fireLUFFY

F

May 27th, 2021 (edited)
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.13 KB | None | 0 0
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
  3. #pragma GCC optimize("unroll-loops")
  4. #pragma comment(linker, "/stack:200000000")
  5.  
  6. #include<bits/stdc++.h>
  7.  
  8. #define int long long
  9. #define ull unsigned long long
  10. #define vi vector<int>
  11. #define vvi vector<vector<int>>
  12. #define loop(i,n) for(int i=0;i<n;i++)
  13. #define loopn(i,a,b) for(int i=a;i<=b;i++)
  14. #define rloop(i,n) for(int i=n-1;i>=0;i--)
  15. #define sortv(a) sort(a.begin(),a.end())
  16. #define sortvr(a) sort(a.rbegin(),a.rend())
  17. #define verase(a) a.erase(unique(a.begin(),a.end()),a.end())
  18. #define all(a) a.begin(),a.end()
  19. #define getv(v,n) for(int i=0;i<n;i++){int x; cin>>x; v.push_back(x);};
  20. #define dbg(x) cerr<<#x<<" = "<<x<<"\n";
  21. #define mp make_pair
  22. #define pb push_back
  23. #define pf push_front
  24. #define fi first
  25. #define se second
  26. #define endl "\n"
  27. #define inf 2e18
  28. using namespace std;
  29.  
  30. int MOD=1000000007;
  31. int mod=998244353;
  32. const int N=200050;
  33. const int nn=1000050;
  34. int fact[N]; // array to store values of factorial
  35. bool prime[nn]; //array to store precalculated primes till 10^6
  36. bool pow2(int x){if(x&&(!(x&(x-1)))) return true; else return false;}
  37. template<class T> T gcd(T a,T b){if(!a||!b)return a|b; unsigned shift=__builtin_ctz(a|b); a>>=__builtin_ctz(a); do{b>>=__builtin_ctz(b); if(a>b)swap(a,b);b-=a;}while(b); return a<<shift;}
  38. template<class T> T lcm(T a,T b){ unsigned val=max(a,b)/gcd(a,b);val*=min(a,b);return val;}
  39. int multiply(int x, int y){return (x * 1ll * y) % MOD;}
  40. int power(int x, int y){int z = 1;while(y){if(y & 1) z = multiply(z, x);x = multiply(x, x);y >>= 1;}return z;}
  41. int modInverse(int x){return power(x, MOD - 2);}
  42. int divide(int x, int y){return multiply(x, modInverse(y));}
  43. void cal_factorial(){fact[0] = 1;for(int i = 1; i < N; i++)fact[i] = multiply(fact[i - 1], i);}// function to calculate factorial upto N
  44. void cal_primes(){memset(prime,true,sizeof(prime)); loopn(i,2,sqrt(nn)){ if(prime[i]==true){ for(int j=i*i;j<=nn;j+=i){prime[j]=false;}}}}
  45. int nCr(int n, int k){return divide(fact[n], multiply(fact[k], fact[n - k]));}
  46. void FASTIO(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
  47.  
  48. void solve(int t)
  49. {
  50.     int testcases=t;
  51.     while(t--)
  52.     {
  53.         //cout<<"Case #"<<(testcases-t)<<": "<<endl;
  54.         int n;cin>>n;
  55.         vi v;
  56.         getv(v,n);
  57.         if(n==1)
  58.             cout<<"Yes"<<endl;
  59.         else
  60.         {
  61.             int mx=(-1),pos=0;
  62.             bool flag=true;
  63.             loop(i,n)
  64.             {
  65.                 if(v[i]>mx)
  66.                 {
  67.                     pos=i;
  68.                     mx=v[i];
  69.                 }
  70.             }
  71.             for(int i=pos-1;i>=0;i--)
  72.             {
  73.                 if(v[i]>=v[i+1])
  74.                     v[i]=(v[i+1]-1);
  75.             }
  76.             for(int i=pos;i<n-1;i++)
  77.             {
  78.                 if(v[i+1]>=v[i])
  79.                     v[i+1]=(v[i]-1);
  80.             }
  81.             loop(i,n)
  82.             if(v[i]<0)
  83.             {
  84.                 flag=false;
  85.                 break;
  86.             }
  87.              
  88.             if(flag)
  89.                 cout<<"Yes"<<endl;
  90.             else
  91.                 cout<<"No"<<endl;
  92.         }
  93.     }
  94. }
  95.  
  96. main()
  97. {
  98.     auto start=chrono::system_clock::now();
  99.     {
  100.         #ifndef ONLINE_JUDGE
  101.             freopen("input.txt","r",stdin);
  102.             freopen("output.txt","w",stdout);
  103.         #endif
  104.         FASTIO();  
  105.         int t=1;
  106.         cin>>t;
  107.         solve(t);
  108.     }
  109.     auto end=chrono::system_clock::now();
  110.     chrono::duration<double> elapsed=end-start;
  111. //  cout<<" Time taken: "<<elapsed.count()<<" sec";
  112.     return 0;
  113. }
Add Comment
Please, Sign In to add comment