fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. vector<int> a;
  31.  
  32. int consistency1(int n){
  33. if(n==1 && a[0] < 0) return 1;
  34.  
  35.  
  36. vector<int> dp(n+1, 0);
  37. dp[0] = 1;
  38. if(a[0] < 0) dp[1] = 1;
  39.  
  40. for(int i=2; i<=n; i++){
  41.  
  42. int j = i-1;
  43. int negCt = a[i-1]<0 ? 1 : 0;
  44.  
  45. while(j>=0){
  46.  
  47. if(negCt >= 1){
  48. dp[i] += dp[j];
  49. }
  50.  
  51. if(j-1>=0){
  52. if(a[j-1] < 0) negCt++;
  53. }
  54. j--;
  55. }
  56. }
  57.  
  58. return dp[n];
  59.  
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. int consistency2(int n){
  68. if(n==1 && a[0] < 0) return 1;
  69.  
  70. int lastNeg = -1;
  71.  
  72. vector<int> dp(n+1, 0);
  73. vector<int> prefixDp(n+1, 0);
  74.  
  75. dp[0] = 1;
  76. prefixDp[0] = 1;
  77.  
  78. if(a[0] < 0){
  79. dp[1] = 1;
  80. lastNeg = 0;
  81. }
  82. prefixDp[1] = dp[0] + dp[1];
  83.  
  84.  
  85. for(int i=2; i<=n; i++){
  86.  
  87. if(a[i-1]<0) lastNeg = i-1;
  88.  
  89. if(lastNeg != -1) dp[i] = prefixDp[lastNeg];
  90.  
  91. prefixDp[i] = prefixDp[i-1] + dp[i];
  92.  
  93. }
  94.  
  95. return dp[n];
  96.  
  97. }
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. int consistency3(int n){
  106. if(n==1 && a[0] < 0) return 1;
  107.  
  108. int ans = 0;
  109. int sum = 0;
  110.  
  111. int lastNeg = -1;
  112.  
  113. for(int i=0; i<n; i++){
  114.  
  115. if(a[i] < 0){
  116. if(lastNeg == -1){
  117. ans = 1;
  118. sum = 1;
  119. lastNeg = i;
  120. }
  121. else{
  122. ans = sum;
  123. }
  124. }
  125. sum += ans;
  126. }
  127.  
  128. return ans;
  129. }
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147. int practice(int n){
  148.  
  149.  
  150. return 0;
  151. }
  152.  
  153.  
  154.  
  155.  
  156.  
  157. void solve() {
  158.  
  159. int n;
  160. cin>> n;
  161.  
  162. a.resize(n);
  163. for(int i=0; i<n; i++) cin >> a[i];
  164.  
  165. cout << consistency1(n) << " " << consistency2(n) << " " << consistency3(n) << endl;
  166.  
  167.  
  168. }
  169.  
  170.  
  171.  
  172.  
  173.  
  174. int32_t main() {
  175. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  176.  
  177. int t = 1;
  178. // cin >> t;
  179. while (t--) {
  180. solve();
  181. }
  182.  
  183. return 0;
  184. }
Success #stdin #stdout 0s 5320KB
stdin
8
2 -3 4 5 -10 6 -8 10
stdout
12 12 12