Knobody

Untitled

Jul 23rd, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define dbg(i,j) cout<<"I am "<<i<<" = "<<endl<<j<<endl;
  3. #define dbr(name,a) cout<<name<<endl;for(auto x:a)cout<<x<<" ";cout<<endl;
  4. #define DBR(name,a) cout<<name<<endl;for(auto x:a){ for(auto y:x)cout<<y<<" ";cout<<endl;}
  5. #define dbmp(name,a) cout<<name<<endl;for(auto x:a){ cout<<x.first<<"\t"<<x.second<<endl;}
  6. #define dbp(name,a) cout<<name<<endl;cout<<a.first<<"\t"<<a.second<<endl;
  7. #define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  8. using namespace std;
  9.  
  10. typedef long long int big;
  11.  
  12. typedef  long double fig;
  13.  
  14.  
  15. big power(big x, big y, big p)
  16. {
  17.     big res = 1;      // Initialize result
  18.  
  19.     x = x % p;  // Update x if it is more than or  
  20.                 // equal to p
  21.  
  22.     while (y > 0)
  23.     {
  24.         // If y is odd, multiply x with result
  25.         if (y & 1)
  26.             res = (res*x) % p;
  27.  
  28.         // y must be even now
  29.         y = y>>1; // y = y/2
  30.         x = (x*x) % p;  
  31.     }
  32.     return res;
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39. int main(){
  40.     big t=1;
  41.     //scanf("%lld",&t);
  42.     while(t--){
  43.         big n;
  44.         cin>>n;
  45.         vector<big> arr(n);
  46.         for(big i=0;i<n;i++){
  47.             cin>>arr[i];
  48.             if(arr[i]>0){
  49.                 arr[i]++;
  50.             }
  51.         }
  52.         vector<big> leftc(n);
  53.         vector<big> rightc(n);
  54.         big c=0;
  55.         for(big i=0;i<n;i++){
  56.             c=c-1;
  57.             c=max(c,arr[i]);
  58.             rightc[i]=c;
  59.         }
  60.         c=0;
  61.         for(big i=n-1;i>=0;i--){
  62.             c=c-1;
  63.             c=max(c,arr[i]);
  64.             leftc[i]=c;
  65.         }
  66.         big count=0;
  67.         for(big i=0;i<n-1;i++){
  68.             if(leftc[i]==0 && rightc[i]==0){
  69.                 count++;
  70.             }
  71.         }
  72.         cout<<count<<"\n";
  73.     }
  74.     return 0;
  75. }
  76.  
  77. //
Add Comment
Please, Sign In to add comment