Advertisement
Galebickosikasa

Untitled

Dec 15th, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
  2. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
  3. // #pragma comment(linker, "/stack:200000000"]
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <unordered_set>
  10. #include <unordered_map>
  11. #include <set>
  12. #include <map>
  13. #include <queue>
  14. #include <deque>
  15. #include <bitset>
  16. #include <stack>
  17. #include <random>
  18. #include <fstream>
  19. #include <sstream>
  20. #include <chrono>
  21.  
  22. #define fi first
  23. #define se second
  24. #define pb push_back
  25. #define ll long long
  26. #define ld long double
  27. #define hm unordered_map
  28. #define pii pair<int, int>
  29. #define sz(a) (int)a.size()
  30. #define all(a) a.begin(), a.end()
  31. #define cinv(v) for (auto& x: v) cin >> x
  32. #define fr(i, n) for (int i = 0; i < n; ++i)
  33. #define fl(i, l, n) for (int i = l; i < n; ++i)
  34.  
  35. #define int ll
  36.  
  37. template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
  38. template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}
  39.  
  40. using namespace std;
  41.  
  42. #ifdef LOCAL
  43. #define dbg(x) cerr << #x << " : " << x << '\n'
  44. const int maxn = 20;
  45. #else
  46. #define dbg(x)
  47. const int maxn = 2e5 + 20;
  48. #endif
  49.  
  50. //tg: @galebickosikasa
  51.  
  52. ostream& operator << (ostream& out, const pii& v) {
  53. out << v.fi << ", " << v.se;
  54. return out;
  55. }
  56.  
  57. template<typename T> ostream& operator << (ostream& out, const vector<T>& v) {
  58. for (auto& x: v) out << x << " ";
  59. return out;
  60. }
  61.  
  62. istream& operator >> (istream& in, pii& a) {
  63. in >> a.fi >> a.se;
  64. return in;
  65. }
  66.  
  67. const ll inf = (ll) 2e9;
  68. const ld pi = asin (1) * 2;
  69. const ld eps = 1e-8;
  70. const ll mod = (ll)1e9 + 7;
  71. const ll ns = 97;
  72.  
  73. mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  74.  
  75. void solve () {
  76. int n;
  77. cin >> n;
  78. vector<int> goo (n);
  79. cinv (goo);
  80. fr (i, n) goo.pb (goo[i]);
  81. int mn = n, mx = n;
  82. int l = n, r = n;
  83. int f = 0;
  84. while (l >= 0 && r < 2 * n) {
  85. int t = 0;
  86. while (l >= mn) {
  87. chkmin (mn, l - goo[l]);
  88. chkmax (mx, l + goo[l]);
  89. if (mn < 0 || mx >= 2 * n) {
  90. f = 1;
  91. break;
  92. }
  93. if (l > mn) --l, t = 1;
  94. else break;
  95. }
  96. if (f) break;
  97. while (r <= mx) {
  98. chkmin (mn, r - goo[r]);
  99. chkmax (mx, r + goo[r]);
  100. if (mn < 0 || mx >= 2 * n) {
  101. f = 1;
  102. break;
  103. }
  104. if (r < mx) ++r, t = 1;
  105. else break;
  106. }
  107. if (!t) break;
  108. }
  109. if (f) cout << "YES\n";
  110. else cout << "NO\n";
  111. }
  112.  
  113. signed main () {
  114. ios_base::sync_with_stdio(false);
  115. cin.tie(nullptr);
  116. cout.tie(nullptr);
  117. int q;
  118. cin >> q;
  119. while (q--) solve ();
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement