text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int main() { int n, t, i, ctr; cin >> t; while (t--) { cin >> n; int a[i]; for (i = 0; i < n; i++) cin >> a[i]; ctr = 0; for (i = 0; i < n; i++) { if (a[i] >= i || a[i] >= (n - 1 - i)) ctr++; } if (n % 2 == 0 && a[n / 2] == a[n / 2 - 1] && a[n / 2] < n / 2) ctr--; if (ctr != n) cout << "No" << endl; else cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int rewt = 0; rewt < t; rewt++) { int n; cin >> n; vector<long long> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int left = 0; int right = n - 1; bool mozno = true; while (right >= left) { if (v[left] < left || v[right] < n - 1 - right) { mozno = false; break; } left++; right--; } if (n % 2 == 1) { if (mozno) { cout << "Yes" << endl; } else { cout << "No" << endl; } } else { if (!mozno) { cout << "No" << endl; } else { int x = n / 2; if (v[x - 1] >= x || v[x] >= x) { cout << "Yes" << endl; } else cout << "No" << endl; } } } return 0; }
#include <bits/stdc++.h> using namespace std; long long a[350000]; int main() { int t; cin >> t; while (t--) { int n, f = 0, t; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int mid = (n / 2) + (n % 2), k; t = mid; if (t + 1 <= n && a[t + 1] > a[t]) { t++; mid = t; } k = a[t]; mid--; while (mid > 0) { if (a[mid] < k) k = a[mid]; else k--; if (k < 0 && mid > 0) f = 1; mid--; } k = a[t]; mid = t + 1; while (mid <= n) { if (a[mid] < k) k = a[mid]; else k--; if (k < 0 && mid <= n) f = 1; mid++; } if (f == 1) printf("No\n"); else printf("Yes\n"); } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n, flag = 0, f = 0; cin >> n; vector<long long> v; for (int j = 0; j < n; j++) { long long a; cin >> a; v.push_back(a); } for (int j = 0; j <= n / 2; j++) { if (v[j] < j) { flag = 1; } } int c = 0; for (int j = v.size() - 1; j > n / 2; j--) { if (v[j] < c) { flag = 1; } c++; } for (int j = 0; j < n / 2 - 1; j++) { if (v[j] < j) { f = 1; } } c = 0; for (int j = v.size() - 1; j >= n / 2 - 1; j--) { if (v[j] < c) { f = 1; } c++; } if (flag == 1 && f == 1) { cout << "No" << endl; } if (flag == 0 || f == 0) { cout << "Yes" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int mi = INT_MAX; int ma = 0; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] < i - 1) mi = min(i, mi); if (a[i] < n - i) ma = max(i, ma); } if (ma + 1 <= mi - 1) cout << "Yes" << endl; else cout << "No" << endl; } int main() { int t; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; int T, n; int a[300004], v[300004]; int main() { scanf("%d", &T); while (T--) { scanf("%d", &n); bool flag = true; for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); v[i] = min(i - 1, n - i); } if (n % 2 == 0) { if (a[n / 2] > a[n / 2 + 1]) v[n / 2]++; else v[n / 2 + 1]++; } for (int i = 1; i <= n; ++i) if (a[i] < v[i]) flag = false; if (!flag) printf("No\n"); else printf("Yes\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int middle(int a, int b, int c) { if ((a <= b && b <= c) || (c <= b && b <= a)) return b; else if ((b <= a && a <= c) || (c <= a && a <= b)) return a; else return c; } template <typename KeyType, typename ValueType> std::pair<KeyType, ValueType> get_max(const std::map<KeyType, ValueType> &x) { using pairtype = std::pair<KeyType, ValueType>; return *std::max_element(x.begin(), x.end(), [](const pairtype &p1, const pairtype &p2) { return p1.second < p2.second; }); } static inline bool isvowel(char ch) { static const std::string vowels("aeiouEAIOU"); return vowels.end() != std::find(vowels.begin(), vowels.end(), ch); } template <typename Map> bool map_compare(Map const &lhs, Map const &rhs) { return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin()); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n), c(n); for (int i = 0; i < n; ++i) { cin >> v[i]; c[i] = min(i, n - 1 - i); } if (n % 2 == 0) { if (v[n / 2] > v[n / 2 - 1]) c[n / 2]++; else c[n / 2 - 1]++; } bool flag = true; for (int i = 0; i < n; ++i) { if (c[i] > v[i]) flag = false; } cout << (flag ? "YES" : "NO") << endl; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int N = 3e5 + 5, inf = 1e9 + 5; int n, m; int a[N]; int main() { int t; scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); int ok = 1, p = -1; for (int i = 0; i < n; ++i) { if (a[i] < i) { if (a[i] >= a[i - 1]) --a[i]; if (n - 1 - i > a[i]) ok = 0; } } puts(ok ? "Yes" : "No"); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int n; cin >> n; int a[n]; bool ok = true; bool f = true; for (int i = 0; i < n; i++) { cin >> a[i]; if (!ok) continue; if (f && a[i] < i) { f = false; } if (!f && a[i] < n - i - 1) ok = false; } if (n % 2 == 0 && a[n / 2] == (n / 2 - 1) && a[n / 2 - 1] == (n / 2 - 1)) ok = false; if (ok) cout << "Yes\n"; else cout << "No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int p1, p2; long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } if (n == 1) { cout << "Yes" << endl; } else { int count = 0, dount = 0; for (int i = 0; i < n; i++) { if (a[i] >= i) { } else { p1 = i; count = 1; break; } } long long int m = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] >= m) { } else { p2 = i; dount = 1; break; } m++; ; } if (count == 0 || dount == 0) cout << "Yes" << endl; else { int count = 0, dount = 0; if (p1 >= 1) p1--; long long int m = 0; for (int i = n - 1; i >= p1; i--) { if (a[i] >= m) { } else { dount = 1; break; } m++; ; } if (p2 >= 1) p2--; for (int i = p2; i < n; i++) { if (a[i] >= i) { } else { count = 1; break; } } if (count == 0 || dount == 0) cout << "Yes" << endl; else cout << "No" << endl; } } } return 0; }
#include <bits/stdc++.h> using namespace std; long long int a[300005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t, n, m, i, j, k, l; cin >> t; while (t--) { cin >> n; long long int max = -1; long long int maxpos; int flag = 0; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i <= n; i++) { if (a[i] < i - 1) break; } if (i <= n) { long long int mini = a[i]; if (a[i] == a[i - 1]) mini--; if (mini < 0) flag = 1; for (j = i + 1; j <= n; j++) { mini = min(mini - 1, a[j]); if (mini < 0) { flag = 1; break; } } } if (flag == 0) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (a > 0 && b > 0) { if (a > b) a %= b; else b %= a; } return a + b; } long long a[1000000 + 5]; int32_t main() { ios_base::sync_with_stdio(false); long long t; cin >> t; while (t--) { long long n; cin >> n; for (long long i = 0; i < n; i++) { cin >> a[i]; } if (n == 1) { cout << "Yes" << '\n'; continue; } if (n == 2) { if (a[0] == 0 && a[1] == 0) cout << "No" << '\n'; else cout << "Yes" << '\n'; continue; } if (n % 2 == 1) { long long k = 0; bool can = true; for (long long i = 0; i <= n / 2; i++) { if (a[i] < k) can = false; if (i != n / 2) k++; } for (long long i = n / 2 + 1; i < n; i++) { k--; if (a[i] < k) can = false; } if (can) { cout << "Yes" << '\n'; } else { cout << "No" << '\n'; } } else { long long k = 0; bool can = true; for (long long i = 0; i < n / 2 - 1; i++) { if (a[i] < k) can = false; if (i != n / 2 - 2) k++; } long long k0 = k; for (long long i = n / 2 + 1; i < n; i++) { if (a[i] < k) can = false; k--; } if (can == true && ((a[n / 2 - 1] >= k0 + 2 && a[n / 2] >= k0 + 1) || (a[n / 2 - 1] >= k0 + 1 && a[n / 2] >= k0 + 2))) { can = true; } else { can = false; } if (can) { cout << "Yes" << '\n'; } else { cout << "No" << '\n'; } } } }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0), ios_base ::sync_with_stdio(0); long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; bool pos1 = 1; bool sharp = 0; int i = 0; while (i < n && i < n - 1 && a[i] < a[i + 1]) { i++; } long long pos = -1; long long mx = 0; for (int i = 0; i < n; ++i) { if (a[i] >= i) { mx = a[i]; pos = i; } else break; } while (pos < n - 1) { if (a[pos] > a[pos + 1]) pos++; else { a[pos + 1] = a[pos] - 1; pos++; } } for (int i = 0; i < n; ++i) if (a[i] < 0) pos1 = 0; if (pos1) cout << "Yes" << endl; else cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int cases; cin >> cases; for (int tt = 0; tt < cases; tt++) { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } int ind1 = 0, ind2 = n - 1; for (int i = 0; i < n; i++) { if (i <= v[i]) { ind1 = i; } else { break; } } for (int i = n - 1; i >= 0; i--) { int val = n - 1 - i; if (v[i] >= val) { ind2 = i; } else { break; } } if (ind1 >= ind2) { cout << "Yes" << endl; } else cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000000 + 7; const long long int N = 1000000 + 6; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; } long long int cnt = 0, i = 0; for (; i < n; i++) { if (a[i] < i) { cnt++; break; } } if (cnt == 0) { cout << "Yes\n"; continue; } long long int j = n - 1; for (; j >= i; j--) { if (a[j] < n - j - 1) { cnt++; break; } } if (cnt == 1 && (a[i - 1] == n - i - 1)) { cout << "No\n"; continue; }; if (cnt == 1) { cout << "Yes\n"; continue; } cout << "No\n"; } }
#include <bits/stdc++.h> using namespace std; long long arr[1000000]; int main() { long long t, i, j, k, n, p1, p2; cin >> t; for (i = 0; i < t; i++) { cin >> n; for (j = 0; j < n; j++) { cin >> arr[j]; } p1 = -1; p2 = -1; for (j = 0; j < n; j++) { if (arr[j] < j) { p1 = j - 1; break; } } for (j = n - 1; j >= 0; j--) { if (arr[j] < n - 1 - j) { p2 = j + 1; break; } } if (p1 == -1 || p2 == -1) { cout << "Yes" << endl; } else { if (p1 < p2) { cout << "No" << endl; } else { cout << "Yes" << endl; } } } }
#include <bits/stdc++.h> using namespace std; signed main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i]; int i = 0; for (; i < n; i++) { if (a[i] < i) break; b[i] = i; } if (i == n) { cout << "Yes\n"; continue; } else { long long push = 0, flag = 0; for (int j = n - 1; j >= i; j--) { if (a[j] < push) { cout << "No\n"; flag = 1; break; } push++; } push--; if (flag == 0) { if (push == b[i - 1]) { if (a[i] > push || a[i - 1] > push) { cout << "Yes\n"; } else { cout << "No\n"; } } else { cout << "Yes\n"; } } else { continue; } } } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, i, prefix, suffix; cin >> n; int a[n]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { if (i > a[i]) break; prefix = i; } for (i = n - 1; i >= 0; i--) { if ((n - i - 1) > a[i]) break; suffix = i; } if (suffix <= prefix) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; vector<long long int> vec(n + 2, 0); for (long long int i = 1; i <= n; i++) cin >> vec[i]; vector<long long int> inc(n + 2, 0), dec(n + 2, 0); for (long long int i = 1; i <= n; i++) { if (vec[i] >= i - 1) { inc[i] = 1; } inc[i] += inc[i - 1]; } long long int c = 0; for (long long int i = n; i >= 1; i--) { if (vec[i] >= c) { dec[i] = 1; } c++; dec[i] += dec[i + 1]; } bool bb = 0; for (long long int i = 1; i <= n; i++) { if (inc[i] == i && dec[i] == (n - i + 1)) { bb = 1; break; } } if (bb == 1) { cout << "Yes" << endl; } else { cout << "No" << endl; } } }
#include <bits/stdc++.h> using namespace std; int middle(int a, int b, int c) { if ((a <= b && b <= c) || (c <= b && b <= a)) return b; else if ((b <= a && a <= c) || (c <= a && a <= b)) return a; else return c; } template <typename KeyType, typename ValueType> std::pair<KeyType, ValueType> get_max(const std::map<KeyType, ValueType> &x) { using pairtype = std::pair<KeyType, ValueType>; return *std::max_element(x.begin(), x.end(), [](const pairtype &p1, const pairtype &p2) { return p1.second < p2.second; }); } static inline bool isvowel(char ch) { static const std::string vowels("aeiouEAIOU"); return vowels.end() != std::find(vowels.begin(), vowels.end(), ch); } template <typename Map> bool map_compare(Map const &lhs, Map const &rhs) { return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin()); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) { cin >> v[i]; } int inc = 0, dec = 0; for (inc = 0; inc <= v[inc] and inc < n; ++inc) ; for (dec = n - 1; n - 1 - dec <= v[dec] and dec >= 0; --dec) ; cout << (inc + n - 1 - dec > n ? "YES" : "NO") << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 500500; const int inf = 0x3f3f3f3f; int n, m; int a[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tn; cin >> tn; while (tn--) { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int i; int p1 = 0, p2 = 0; for (i = 1; i <= n; i++) { if (a[i] + 1 >= i) { p1 = i; continue; } else { break; } } for (i = n; i >= 0; i--) { if (a[i] >= n - i) { p2 = i; continue; } else break; } if (p1 < p2) cout << "No" << "\n"; else cout << "Yes" << "\n"; } }
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)2e9; const long long mod = 1000000007; long long dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; long long powmod(long long a, long long p) { long long ans = 1; while (p) { if (p & 1) ans *= a; p /= 2; a *= a; ans %= mod; a %= mod; } return ans; } long long mdinv(long long a) { return powmod(a, mod - 2); } const long long N = 3e5 + 10; long long v[N]; bool a[N], b[N]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long tt; cin >> tt; while (tt--) { long long n; cin >> n; for (long long i = 0; i < (long long)n; i++) cin >> v[i]; for (long long i = 0; i < (long long)n; i++) a[i] = b[i] = 0; for (long long i = 0; i < (long long)n; i++) { a[i] = (v[i] >= i); b[i] = (v[i] >= (n - 1 - i)); } for (long long i = 1; i < n; i++) a[i] &= a[i - 1]; for (long long i = n - 2; i >= 0; i--) b[i] &= b[i + 1]; bool ans = 0; for (long long i = 0; i < (long long)n; i++) if (a[i] && b[i]) ans = 1; cout << (ans ? "Yes" : "No") << "\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); int query; cin >> query; while (query--) { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int l = n, r = n; for (int i = 0; i < n; i++) { if (v[i] < i) { l = i; break; } } reverse(v.begin(), v.end()); for (int i = 0; i < n; i++) { if (v[i] < i) { r = i; break; } } reverse(v.begin(), v.end()); if (l + r >= n + 1) cout << "Yes\n"; else cout << "No\n"; } }
#include <bits/stdc++.h> using namespace std; const int maxn = 1001010; int a[maxn]; void solve() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } int cnt = 0; for (int i = 0; i < n and a[i] >= i; ++i, ++cnt) { } for (int i = n - 1; i >= 0 and a[i] >= n - 1 - i; --i, ++cnt) { } cout << (cnt > n ? "Yes" : "No") << endl; } int main() { int t; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void ans() { long long num; cin >> num; long long A[num]; for (long long i = 0; i < num; i++) cin >> A[i]; long long i, j; for (i = 0; i < num; i++) { if (A[i] < i) break; } for (j = num - 1; j >= 0; j--) { if (A[j] < num - j - 1) break; } if (i >= j + 2) cout << "YES" << "\n"; else cout << "NO" << "\n"; } int32_t main() { c_p_c(); long long x; cin >> x; while (x--) ans(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; while (t--) { cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int p = -1, s = n; for (int i = 0; i < n; i++) { if (a[i] < i) break; p = i; } for (int i = n - 1; i >= 0; i--) { if (a[i] < n - 1 - i) break; s = i; } if (s <= p) cout << "Yes\n"; else cout << "No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 314; const int INF = 1e9; const double PI = acos(-1); const int MOD = 1e9 + 7; const double eps = 1e-9; long long a[N]; int dpl[N], dpr[N]; void solve() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } if (n == 1) { cout << "Yes\n"; return; } int up = 1; int idx = 0; int ds = n + 1; for (int i = 2; i <= n; ++i) { if (a[i] < i - 1) { ds = i; break; } } for (int i = ds; i <= n; ++i) { a[i] = min(a[i], a[i - 1] - 1); if (a[i] < 0) { cout << "No\n"; return; } if (a[i] == 0 && i != n) { cout << "No\n"; return; } } cout << "Yes\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 7; int arr[maxn], L[maxn], R[maxn], n; void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; } L[0] = 1, R[n + 1] = 1; for (int i = 1; i <= n; i++) { if (arr[i] >= i - 1) { L[i] = L[i - 1]; } else { L[i] = 0; } } for (int i = n; i >= 1; i--) { if (arr[i] >= n - i) { R[i] = R[i + 1]; } else { R[i] = 0; } } for (int i = 1; i <= n; i++) { if (L[i] && R[i]) { cout << "Yes" << endl; return; } } cout << "No" << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int test = 1; cin >> test; while (test--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 5; long long t, n, a[N]; bool possible() { for (long long i = 0, j = n - 1; i <= j; i++, j--) if (a[i] < i || a[j] < i) return 0; return n % 2 || a[n / 2 - 1] > n / 2 - 1 || a[n / 2] > n / 2 - 1; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; cout << (possible() ? "Yes\n" : "No\n"); } }
#include <bits/stdc++.h> using namespace std; int main() { long long int t, i, j, k; cin >> t; while (t--) { long long int n, n1, n2; cin >> n; long long int a[n], b[n], c[n]; for (i = 0; i < n; i++) { cin >> a[i]; c[i] = a[i]; b[i] = a[i]; } long long int pre = 0, post = 0, i1 = 0, j1 = (n - 1), i2, j2, count1 = 0, count2 = 0; while (i1 < n && j1 >= 0) { count1 = 0; count2 = 0; if (a[i1] >= pre && i1 <= (n - 1) && (i1 == 0 || (i1 - i2) == 1)) { c[i1] = pre; i2 = i1; count1++; } if (a[j1] >= post && j1 >= 0 && (j1 == (n - 1) || (j2 - j1) == 1)) { b[j1] = post; j2 = j1; count2++; } pre++; post++; if (i1 < (n - 2)) i1++; if (j1 > 0) j1--; if (count1 == 0 && count2 == 0) break; } if ((j2 - i2) <= 0) cout << "Yes" << "\n"; else if ((j2 - i2) == 1) { if ((a[j2] == a[i2]) && (b[j2] == c[i2])) cout << "No" << "\n"; else cout << "Yes" << "\n"; } else cout << "No" << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int n; vector<int> v; bool solve() { int i, j; for (i = 1; i < n; i++) { if (v[i] < i) { i--; break; } } if (i == n) return true; for (j = n - 2; j >= 0; j--) { if (v[j] < n - 1 - j) { j++; break; } } return (i >= j); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; ; while (t--) { cin >> n; v.resize(n); for (int i = 0; i < n; i++) cin >> v[i]; (solve()) ? cout << "YES" : cout << "NO"; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; int pref = -1, suff = n; for (int i = 0; i < n; i++) { if (a[i] < i) break; pref = i; } for (int i = n - 1; i >= 0; i--) { if (a[i] < (n - 1 - i)) break; suff = i; } if (suff <= pref) cout << "Yes\n"; else cout << "No\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, num[350004], count = 0; cin >> n; for (int i = 0; i < n; i++) cin >> num[i]; if (n == 1) cout << "YES\n"; else { for (int i = 0; i < n; i++) { if (i < n / 2) { if (num[i] < i) count = 1; } else { if ((num[i] < n - i - 1) || ((num[n / 2 - 1] == num[n / 2]) && (num[n / 2] == n / 2 - 1))) count = 1; } } if (count == 0) cout << "YES\n"; else cout << "NO\n"; } count = 0; } return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int start = 0; for (int i = 0; i < n; i++) { if (a[i] < i) break; start = i; } int end = n - 1; for (int i = 0; i < n; i++) { if (a[n - i - 1] < i) break; end = n - i - 1; } if (end <= start) cout << "Yes" << "\n"; else cout << "No" << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); int t = 1; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> long long a[300005]; int main() { int t; scanf("%d", &t); while (t--) { int n, i, flag = 1; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%lld", &a[i]); if (n == 1) { printf("YES\n"); continue; } if (n == 2 && a[0] == 0 && a[n - 1] == 0) { printf("NO\n"); continue; } for (i = 1; i < n - 1; i++) { if (a[i] < i && a[i] < (n - 1 - i)) { flag = 0; break; } if (a[i] == a[i + 1]) { if (a[i] == i && a[i + 1] == (n - i - 2)) { flag = 0; break; } } } if (flag) printf("YES\n"); else printf("NO\n"); } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int a[1000000], flag = 0; long long int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } int start, end; for (start = 0; start < n; start++) { if (a[start] < start) break; } start; for (end = n - 1; end >= 0; end--) { if (a[end] < n - end - 1) break; } if (start > end + 1) flag = 1; if (flag == 1) cout << "Yes" << endl; else cout << "No" << endl; } }
#include <bits/stdc++.h> using ll = long long; using ull = unsigned long long; using namespace std; int del(int n, int a) { for (int i = 2; i * i <= n; i++) if (n % i == 0 && i != a) return i; return -1; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int p = -1, s = n; for (int i = 0; i < n; ++i) { if (a[i] < i) break; p = i; } for (int i = n - 1; i >= 0; --i) { if (a[i] < (n - 1) - i) break; s = i; } if (s <= p) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void B() { int t, n; cin >> t; while (t--) { int l = INT_MAX, r = INT_MAX; cin >> n; int arr[n]; for (int i = 0; i < (n); i++) cin >> arr[i]; for (int i = 0; i < (n); i++) { if (arr[i] < i) { l = i - 1; break; } } if (l == INT_MAX) cout << "Yes\n"; else { for (int i = n - 1; i >= l; i--) { if (arr[i] < (n - i - 1)) { r = i; break; } } if (r == INT_MAX) cout << "Yes\n"; else cout << "No\n"; } } } int main() { { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); }; B(); return 0; }
#include <bits/stdc++.h> using namespace std; bool check(vector<int> v, vector<int> v1) { for (int i = 0; i < v.size(); i++) { if (v[i] < v1[i]) return false; } return true; } int main() { int t, n, x, mid; vector<int> v, v1, v2; cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } if (n % 2 == 1) { mid = n / 2; for (int i = 0; i < n; i++) { if (i <= mid) v1.push_back(i); else v1.push_back(n - 1 - i); } if (check(v, v1)) cout << "YES" << endl; else cout << "NO" << endl; } else { mid = n / 2; for (int i = 0; i < n; i++) { if (i <= mid) v1.push_back(i); else v1.push_back(n - 1 - i); if (i <= mid - 2) v2.push_back(i); else v2.push_back(n - 1 - i); } if (check(v, v1) || check(v, v2)) cout << "YES" << endl; else cout << "NO" << endl; } v.clear(); v1.clear(); v2.clear(); } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int left = 0; int right = n - 1; for (int i = 0; i < n; i++) { if (a[i] >= i) left = i; else break; } for (int i = n - 1; i >= 0; i--) { if (a[i] >= n - i - 1) right = i; else break; } if (left >= right) cout << "YES" << endl; else cout << "NO" << endl; } int main() { int t; cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 10; const long long INF = 1e18; const long long inf = -1e18; const long long MOD = 1e9 + 7; long long n, t, k, s, q, a[N]; int main() { cin >> q; for (int i = 1; i <= q; i++) { cin >> n; k = 0; t = 0; for (int j = 1; j <= n; j++) { cin >> a[j]; } for (int j = 1; j <= n; j++) { if (a[j] >= j - 1) { k++; } else { break; } } for (int j = n; j >= 1; j--) { if (a[j] >= n - j) { t++; } else { break; } } if (k > n - t) { cout << "YES" << endl; } else { cout << "NO" << endl; } } }
#include <bits/stdc++.h> using namespace std; long long int dp[45]; long long int a[1000006]; int main() { long long int mod, t, k = 0, n, i, m, x, j = 0, l, c = 0, r = 0, w, s = 0, d = 0, f = 0, sum = 0, mul, mx1, mx, s1 = 10000000, s2 = 0; cin >> t; while (t--) { d = 0; f = 0; cin >> n; for (i = 0; i < n; i++) { cin >> m; if (f == 0 && d <= m) { d++; } else if (f != 3) { if (f == 0) { d = min(k - 1, n - d - 1); f = 2; } if (d >= 0 && d <= m) { d--; } else { f = 3; } } k = m; } if (f == 3) { cout << "No" << endl; } else { cout << "Yes" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int max_size = 3e5 + 100; const int mod = 1e9 + 7; const long long dis = 2e16; long long a[max_size]; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; if (n == 1) { cout << "Yes" << endl; continue; } bool vis[n + 5][2]; memset(vis, 0, sizeof(vis)); vis[0][0] = 1; vis[n - 1][1] = 1; for (int i = 1; i < n; i++) { vis[i][0] = (a[i] >= i) & vis[i - 1][0]; vis[n - 1 - i][1] = (a[n - 1 - i] >= i) & vis[n - i][1]; } bool check = 0; check = (a[0] >= n - 1) && vis[1][1]; check |= (a[n - 1] >= n - 1) && vis[n - 2][0]; for (int i = 1; i < n - 1; i++) { check |= (a[i] >= max(i, n - i - 1)) & vis[i - 1][0] & vis[i + 1][1]; } if (check) cout << "Yes"; else cout << "No"; cout << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int, int>; using graph = vector<vi>; void go() { int n; cin >> n; vi A(n); for (int& i : A) cin >> i; vi left(n, 0), right(n, 0); for (int i = 0; i < n && A[i] >= i; i++) left[i] = i; for (int i = n - 1; i >= 0 && A[i] >= (n - 1 - i); i--) right[i] = n - 1 - i; bool poss = false; for (int i = 0; i < n - 1; i++) { if ((left[i] == i && right[i + 1] == n - 1 - (i + 1))) { if (left[i] == right[i + 1]) { if (A[i] > left[i] || A[i + 1] > right[i + 1]) poss = true; } else { poss = true; } } } if (poss || n == 1) cout << "Yes\n"; else cout << "No\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) go(); return 0; }
#include <bits/stdc++.h> using namespace std; int mang[4000009]; int main() { int t; cin >> t; while (t > 0) { int n; cin >> n; int tang = 0, giam = 0; int ii = 0; for (int i = 0; i < n; i++) { cin >> mang[i]; if (mang[i] >= i && ii == i) { ii++; tang = i; } } int k = 0; for (int j = n - 1; j >= tang; j--) { if (mang[j] >= k) { k++; giam = j; } else { break; } } if (tang >= giam) { cout << "YES" << endl; } else { cout << "NO" << endl; } t--; } return 0; }
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b, long long int m) { if (b == 0) return 1; if (b == 1) return a % m; long long int t = power(a, b / 2, m); t = (t * t) % m; if (b & 1) t = (t * a) % m; return t; } long long int gcd(long long int a, long long int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n]; long long int flag = 0; for (long long int i = 0; i < n; i++) { cin >> a[i]; } long long int k = -1; for (long long int i = 0; i < n; i++) { if (a[i] < i) { k = i - 1; break; } } if (k != -1) { for (long long int i = k; i < n; i++) { if (a[i] < n - 1 - i) { flag = 1; break; } } if (flag) { cout << "No" << endl; } else { cout << "Yes" << endl; } } else { if (flag) { cout << "No" << endl; } else { cout << "Yes" << endl; } } } }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:2000000000") using namespace std; vector<long long> used, parent, a, cnt_child; struct edge { long long idx, st; }; bool cmp(long long x, long long y) { return a[x] > a[y]; } bool fl = true; void dfs(long long start, long long p, vector<vector<long long> >& g, long long h) { used[start] = 1; parent[start] = p; for (auto i : g[start]) { if (!used[i]) { dfs(i, start, g, h + 1); cnt_child[start] += cnt_child[i] + 1; } } if (cnt_child[start] + h > g[start].size()) { fl = false; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; ++i) { cin >> a[i]; } long long l = n + 1, r = -1; for (long long i = 0; i < n; ++i) { if (a[i] < i) { l = i - 1; break; } } for (long long i = n - 1; i >= 0; --i) { if (a[i] < (n - i - 1)) { r = i + 1; break; } } if (l >= r) { cout << "Yes\n"; } else { cout << "No\n"; } } }
#include <bits/stdc++.h> using namespace std; int main() { int tc; cin >> tc; while (tc--) { int n; cin >> n; vector<int> a(n); for (int& i : a) cin >> i; int p, q; for (p = 0; p < n; p++) { if (a[p] < p) { p--; break; } } for (q = n - 1; q >= 0; q--) if (a[q] < n - q - 1) { q++; break; } cout << (p >= q ? "YES\n" : "NO\n"); } }
#include <bits/stdc++.h> const int maxx = 3e5 + 7; const int maxn = 1e9 + 1; using namespace std; int t, n; int a[maxx]; int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } if (n == 1) cout << "Yes" << endl; else if (n == 2) { if (a[0] == 0 && a[1] == 0) cout << "No" << endl; else cout << "Yes" << endl; } else { int flag = 0; if (n % 2 == 0) { for (int i = 0; i < n / 2; i++) { if (a[i] < i) { flag = 1; break; } } for (int i = n / 2; i < n; i++) { if (a[i] < n - i - 1) { flag = 1; break; } } if (a[n / 2 - 1] == a[n / 2] && a[n / 2 - 1] == n / 2 - 1) { flag = 1; } if (flag) cout << "No" << endl; else cout << "Yes" << endl; } else { for (int i = 0; i < n / 2; i++) { if (a[i] < i) { flag = 1; break; } } for (int i = n / 2; i < n; i++) { if (a[i] < n - i - 1) { flag = 1; break; } } if (flag) cout << "No" << endl; else cout << "Yes" << endl; } } } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 3 * 1e5 + 10; int n, a[MAX]; int main() { ios::sync_with_stdio(0); cin.tie(0); bool ans, asc, des; int t; cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; ans = asc = true; for (int i = 0, j = 0; i < n && ans; i++) { if (asc) if (a[i] < i) { asc = false; if (i) if (a[i] == n - i - 1 && a[i] == a[i - 1]) ans = false; } if (!asc) if (a[i] < n - i - 1) ans = false; } des = true; for (int i = 1; i < n; i++) { des = des && (a[i] < a[i - 1]); } if (ans || des) cout << "Yes" << '\n'; else cout << "No" << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 5e6 + 10; const int mod = 1e9 + 7; int a[maxn]; int main() { int n; cin >> n; while (n--) { int len; cin >> len; for (int i = 1; i <= len; i++) scanf("%d", &a[i]); bool ok = 1; bool yes = 0; int cnt = 0; int aa = -1, b = -1; for (int i = 1; i <= len; i++) { if (a[i] >= cnt) ++cnt; else { aa = i - 1; ok = 0; break; } } yes |= ok; ok = 1; cnt = 0; for (int i = len; i >= 1; i--) { if (a[i] >= cnt) ++cnt; else { b = i + 1; ok = 0; break; } } yes |= ok; ok = 1; cnt = 0; yes |= (aa >= b); if (yes) cout << "Yes" << endl; else cout << "no" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long Min(long long a, long long b) { return (a < b) ? a : b; } long long Max(long long a, long long b) { return (a < b) ? b : a; } long long gcd(long long m, long long n) { if (n == 0) return m; return gcd(n, m % n); } long long lcm(long long m, long long n) { return m * n / gcd(m, n); } long long a[500005]; long long pos_l[500005], pos_r[500005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long tc; cin >> tc; while (tc--) { long long n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; pos_l[i] = pos_r[i] = 0; } for (int i = 0; i < n; i++) { if (a[i] >= i) pos_l[i] = 1; else break; } for (int i = 0; i < n; i++) { if (a[n - i - 1] >= i) pos_r[n - i - 1] = 1; else break; } long long suc = 0; for (int i = 0; i < n; i++) { if (pos_l[i] && pos_r[i]) { cout << "Yes\n"; suc = 1; break; } } if (suc == 0) { cout << "No\n"; } } exit(0); }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int q; cin >> q; while (q--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } bool ok = 1; vector<int> b = a; int i = 0; for (; i < n - 1; i++) { if (a[i] >= i) { a[i] = i; } else break; } if (i > 0 && a[i] == a[i - 1]) { i--; } a[i] = b[i]; for (; i < n - 1; i++) { if (a[i + 1] >= a[i]) { a[i + 1] = a[i] - 1; } } for (int i = 0; i < n; i++) { if (a[i] < 0) ok = 0; } if (ok) { cout << "Yes" << endl; } else { cout << "No" << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (auto &i : a) { cin >> i; } vector<bool> pref(n); vector<bool> suf(n); pref[0] = true; for (int i = 1; i < n; ++i) { if (a[i] >= i && pref[i - 1]) { pref[i] = true; } } suf[n - 1] = true; for (int i = n - 2; i >= 0; --i) { if (a[i] >= (n - i - 1) && suf[i + 1]) { suf[i] = true; } } bool flag = true; for (int i = 0; i < n; ++i) { if (pref[i] && suf[i]) { cout << "Yes" << '\n'; flag = false; break; } } if (flag) { cout << "No\n"; } } return 0; }
#include <bits/stdc++.h> using ll = long long; using namespace std; const int N = 1e6 + 6, mod = 1e9 + 7; int t, a[N], l[N], r[N]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } bool yes = 1; for (int i = 1; i <= n; i++) { if (a[i] < i - 1) { yes = 0; } l[i] = yes; } yes = 1; for (int i = n; i >= 1; i--) { if (a[i] < n - i) { yes = 0; } r[i] = yes; } l[0] = 1; r[n + 1] = 1; a[0] = -INT_MAX; a[n + 1] = INT_MAX; yes = 0; for (int k = 0; k <= n; k++) { if (l[k] && r[k + 1] && (k - 1 < a[k + 1] || k - 1 > a[k + 1])) { yes = 1; } } if (yes) { cout << "Yes\n"; } else { cout << "No\n"; } } }
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void write(t x) { if (x < 0) { putchar('-'), write(-x); } else { if (x > 9) write(x / 10); putchar('0' + x % 10); } } const int N = 3e5 + 5; int a[N]; void doit() { int n, l = 0, r; r = read(n) + 1; for (int i = 1; i <= n; i++) read(a[i]); while (a[l + 1] >= l && l + 1 <= n) l++; while (a[r - 1] >= n - r + 1 && r - 1 >= 1) r--; if (l >= r) puts("Yes"); else puts("No"); } signed main() { int t; read(t); while (t--) doit(); }
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int mod = 998244353; const long long INF = 0x3f3f3f3f3f3f3f3f; int n, a[maxn], b[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) b[i] = a[i]; int ff = 0; for (int i = 1; i < n; i++) { b[i + 1] = min(b[i + 1], b[i] - 1); if (b[i + 1] < 0) { ff = 1; break; } } if (!ff) { cout << "Yes" << '\n'; continue; } a[0] = -1; int pos = -1; for (int i = 1; i < n; i++) { int temp = a[i]; a[i] = min(a[i], a[i - 1] + 1); if (a[i] >= a[i + 1]) { a[i] = temp; pos = i; break; } } if (pos == -1) { cout << "Yes" << '\n'; continue; } int flag = 0; for (int i = pos; i < n; i++) { a[i + 1] = min(a[i + 1], a[i] - 1); if (a[i + 1] < 0) { flag = 1; break; } } if (flag) cout << "No" << '\n'; else cout << "Yes" << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; cin >> t; while (t--) { long long int i, n; cin >> n; long long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; int prefix = -1, suffix = n; for (i = 0; i < n; i++) { if (a[i] < i) break; prefix = i; } for (i = n - 1; i >= 0; i--) { if (a[i] < n - 1 - i) break; suffix = i; } if (suffix <= prefix) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long a[n]; bool flag = true; for (int i = 0; i < n; i++) { cin >> a[i]; } int l = 0, r = (n - 1), num = 0; while (l <= r) { if ((l + 1) == r) { if ((a[l] >= num && a[r] >= (num + 1)) || (a[l] >= (num + 1) && a[r] >= num)) { break; } else { flag = false; } } if (a[l] >= num) { a[l] = num; } else { flag = false; } if (a[r] >= num) { a[r] = num; } else { flag = false; } l++; r--; num++; } cout << (flag ? "YES" : "NO") << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) cin >> arr[i]; long long p = 0; while (p < n) { if (arr[p] < p) break; p++; } --p; long long s = n - 1; while (s >= 0) { if (arr[s] < n - s - 1) break; s--; } ++s; if (s <= p || (s == p + 1 && arr[s] != arr[p])) cout << "Yes"; else cout << "No"; cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007, N = 3e5 + 5, M = 1e5 + 5, INF = 0x3f3f3f3f; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } int a[N]; int main(void) { ios::sync_with_stdio(false); int T; cin >> T; while (T--) { int n; cin >> n; bool flag = 1; for (int i = 0; i < n; i++) { cin >> a[i]; } int l = 0, r = n - 1; while (a[l] >= l) ++l; while (a[r] >= n - 1 - r) --r; if (l > r + 1) puts("YES"); else puts("NO"); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n), temp1(n), temp2(n); for (int i = 0; i < n; i++) cin >> v[i]; int indf = -1, indb = -1; for (int i = 0; i < n; i++) { if (v[i] < i) { break; } indf = i; } for (int i = n - 1; i >= 0; i--) { if (v[i] < (n - 1) - i) { break; } indb = i; } if (indb <= indf) { cout << "Yes\n"; } else cout << "No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 100; int a[N]; int main(void) { int t; scanf("%d", &t); while (t--) { int n; cin >> n; for (int i = 0; i < n; i++) scanf("%d", &a[i]); int toR = 0; int toL = n - 1; for (int i = 0; i < n; i++) { if (a[i] >= i) toR = i; else break; } for (int i = n - 1; i >= 0; i--) { if (a[i] >= (n - 1 - i)) toL = i; else break; } if (toL - toR == 1 && a[toL] == a[toR]) puts("NO"); else if (toL - toR > 1) puts("NO"); else puts("YES"); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long oo = (long long)1e16; const int A = 26; long long n, m, ID, l, nb, a, b; long long t[300005]; long long t1[300005]; long long t2[300005]; long long dp[300005]; vector<int> v; string s; int main() { ios_base::sync_with_stdio(0); cin >> nb; while (nb--) { cin >> n; for (int i = 0; i < n; i++) cin >> t[i]; a = n; for (int i = 0; i < n; i++) { if (t[i] < i) { a = i; break; } } bool test = true; for (int i = a - 1; i < n; i++) { if (t[i] < (n - 1 - i)) test = false; } if (test) cout << "Yes\n"; else cout << "No\n"; } }
#include <bits/stdc++.h> using namespace std; int u[300005]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &u[i]); int i, j; for (i = 1; i <= n; i++) { if (u[i] < i - 1) break; } for (j = n; j >= 1; j--) { if (u[j] < n - j) break; } if (n >= 3) { if (i - 2 >= j) printf("Yes\n"); else printf("No\n"); } else { if (n == 1) printf("Yes\n"); else { if (u[1] == 0 && u[2] == 0) printf("No\n"); else printf("Yes\n"); } } } }
#include <bits/stdc++.h> using namespace std; const int N = 3 * 1e5 + 100; int t, n, a[N]; int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); bool bl = 1; vector<int> p; int l, r; l = 0; r = (int)1e9; for (int i = 1; i <= n; i++) { if (a[i] < i - 1 && a[i] >= n - i) r = min(r, i); if (a[i] >= i - 1 && a[i] < n - i) l = max(l, i); if (a[i] >= i - 1 && a[i] >= n - i) p.push_back(i); if (a[i] < i - 1 && a[i] < n - i) { bl = 0; break; } } if (!bl) { printf("No\n"); continue; } for (int i = 0; i < (int)p.size(); i++) { if (r > p[i] && l < p[i]) { bl = 0; break; } } if (bl) printf("No\n"); else printf("Yes\n"); } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int prefix_end = -1, suffix_end = n; for (int i = 0; i < n; i++) { if (a[i] < i) { break; } prefix_end = i; } for (int i = n - 1; i >= 0; i--) { if (a[i] < (n - 1) - i) { break; } suffix_end = i; } if (suffix_end <= prefix_end) { cout << "Yes"; } else { cout << "No"; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; namespace IO { static char buf[1 << 20], *fs, *ft; inline char gc() { if (fs == ft) { ft = (fs = buf) + fread(buf, 1, 1 << 20, stdin); if (fs == ft) return EOF; } return *fs++; } inline int read() { int x = 0, f = 1; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -f; s = getchar(); } while (s >= '0' && s <= '9') { x = x * 10 + s - '0'; s = getchar(); } return x * f; } } // namespace IO using IO::read; const int N = 300100; int T; int n; int a[N]; int sum[N], sum1[N]; int vis[N], vis1[N]; inline void solve() { int opt = 0; n = read(); memset(sum, 0, sizeof(sum)); memset(sum1, 0, sizeof(sum1)); for (register int i = 1; i <= n; ++i) { vis[i] = 0; a[i] = read(); if (a[i] >= i - 1) vis[i] = 1; sum[i] = sum[i - 1] + vis[i]; } for (int i = n; i >= 1; --i) { vis1[i] = 0; if (a[i] >= n - i) vis1[i] = 1; sum1[i] = sum1[i + 1] + vis1[i]; } if (sum[n] == n) { puts("Yes"); return; } if (sum1[1] == n) { puts("Yes"); return; } for (register int i = 1; i <= n; ++i) if (sum[i] + sum1[i + 1] == n && !(a[i] == a[i + 1] && a[i] == i - 1)) { puts("Yes"); opt = 1; break; } if (opt == 0) puts("No"); } int main() { T = read(); while (T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 10; typedef int ar[MAXN]; namespace HABIT { template <typename T> inline T Max(T a) { return a; } template <typename T, typename... Args> inline T Max(T a, Args... args) { T b = Max(args...); return (a > b) ? a : b; } template <typename T> inline T Min(T a) { return a; } template <typename T, typename... Args> inline T Min(T a, Args... args) { T b = Min(args...); return (a < b) ? a : b; } inline char gc() { return getchar(); } inline int read() { register int ans = 0; register char c = gc(); register bool neg = 0; while (c < 48 || c > 57) neg ^= !(c ^ '-'), c = gc(); while (c >= 48 && c <= 57) ans = (ans << 3) + (ans << 1) + (c ^ 48), c = gc(); return neg ? -ans : ans; } char Output_Ans[1 << 20 | 1], *Output_Cur = Output_Ans; inline void output() { Output_Cur -= fwrite(Output_Ans, 1, Output_Cur - Output_Ans, stdout); } inline void print(char c) { if (Output_Cur - Output_Ans + 1 >> 20) output(); *(Output_Cur++) = c; } inline void print(char *s) { while (*s) print(*(s++)); } inline void print(unsigned long long int x) { if (!x) { print('0'); return; } char buf[30] = {0}, *p = buf + 28; while (x) *(p--) = x % 10 + 48, x /= 10; print(p + 1); } inline void print(unsigned int x) { print((unsigned long long int)x); } inline void print(long long int x) { if (x < 0) print('-'), x = -x; print((unsigned long long int)x); } inline void print(int x) { if (x < 0) print('-'), x = -x; print((unsigned long long int)x); } } // namespace HABIT using namespace HABIT; ar ar_d_Num1, ar_d_Num2; inline bool alw() { int d_N = read(); for (register int i = 1, I = d_N; i <= I; i++) { int d_Tmp = read(); ar_d_Num1[i] = d_Tmp - i + 1; ar_d_Num2[i] = d_Tmp - d_N + i; } int d_Pos1 = 1, d_Pos2 = d_N; while (ar_d_Num1[d_Pos1] >= 0 && d_Pos1 <= d_N) d_Pos1++; while (ar_d_Num2[d_Pos2] >= 0 && d_Pos2 >= 1) d_Pos2--; if (d_Pos1 > d_N || d_Pos2 < 1) return -1; return d_Pos1 - d_Pos2 >= 2; } int main() { for (register int i = 1, I = read(); i <= I; i++) if (alw()) print("Yes\n"); else print("No\n"); output(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long int a[n]; int ind1 = -1; int ind2 = -1; int ans = 1; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (a[i] < i) { ind1 = i; break; } } for (int i = n - 1; i >= 0; i--) { if (a[i] < n - i - 1) { ind2 = i; break; } } if ((ind1 == -1 || ind2 == -1) || ind2 + 1 < ind1) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int md = 1e9 + 7; const int MX = 2e5 + 5; const long long INF = 1e18; const long double PI = 4 * atan((long double)1); long long power(long long a, long long n) { long long res = 1; while (n) { if (n % 2) res *= a; a *= a; n /= 2; } return res; } long long abst(long long a) { return ((a < 0) ? (-1 * a) : (a)); } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int f = 0, p = 1; int prev = -1; for (int i = 0; i < n; i++) { if (f == 0) { if (arr[i] >= (prev + 1)) prev++; else { if (prev > (n - i - 1)) { prev = n - i - 1; f = 1; if (arr[i] < prev) { p = 0; break; } } else { p = 0; break; } } } else { prev = prev - 1; if (arr[i] < prev) { p = 0; break; } } } if (p) cout << "Yes\n"; else { prev = -1; p = 1; f = 0; for (int i = n - 1; i >= 0; i--) { if (f == 0) { if (arr[i] >= (prev + 1)) prev++; else { if (prev > (i)) { prev = i; f = 1; if (arr[i] < prev) { p = 0; break; } } else { p = 0; break; } } } else { prev = prev - 1; if (arr[i] < prev) { p = 0; break; } } } if (p) cout << "Yes\n"; else cout << "No\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; int a[300010]; int main() { int i, j, k, n, m, x, y, z, t; scanf("%d", &t); while (t--) { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n; i++) { if (a[i] < i) { break; } } i--; for (j = n - 1; j >= 0; j--) { if (a[j] < n - j - 1) { break; } } j++; if (i >= j) { printf("Yes\n"); } else { printf("No\n"); } } }
#include <bits/stdc++.h> using namespace std; int main() { int T, N; cin >> T; while (T--) { cin >> N; int pr = -1, a = -1, k; bool b = true; int i = 0; for (i = 0; i < N; i++) { pr = a; cin >> a; if (a < i) break; } if (i < N && (pr <= (N - 1 - i) || a < (N - 1 - i))) { b = false; } i++; for (; i < N; i++) { cin >> a; if (b && a < N - 1 - i) { b = false; } } if (b) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; char s[3005]; int a[300005]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int l = n, r = 0; for (int i = 1; i <= n; i++) { if (a[i] >= i - 1) r++; else break; } for (int i = n; i >= 1; i--) { if (a[i] >= n - i) l--; else break; } if (l < r) cout << "Yes\n"; else cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } int val = 0; int i = 0; while (i < n && v[i] >= i) { i++; } if (i == n) { cout << "Yes" << endl; continue; } if (v[i] == v[i - 1]) { val = v[i] - 1; } else { val = v[i]; } if (val == -1) { cout << "No" << endl; continue; } i++; while (i < n) { if (v[i] >= val) { val = val - 1; } else { val = v[i]; } if (val == -1) { break; } i++; } if (val >= 0 && i == n) { cout << "Yes" << endl; } else { cout << "No" << endl; } } }
#include <bits/stdc++.h> using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long ar[n]; for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); i += 1 - 2 * ((0) > (n))) cin >> ar[i]; long long pre[n], suf[n]; long long flag = 0; pre[0] = 1; suf[n - 1] = 1; for (__typeof(n) i = (1) - ((1) > (n)); i != (n) - ((1) > (n)); i += 1 - 2 * ((1) > (n))) { pre[i] = (pre[i - 1] && (ar[i] >= i)); } for (long long i = n - 2; i >= 0; i--) suf[i] = (suf[i + 1] && (ar[i] >= (n - 1 - i))); for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); i += 1 - 2 * ((0) > (n))) { if (pre[i] == 1 && suf[i] == 1) { cout << "Yes" << '\n'; flag = 1; break; } } if (flag == 0) { cout << "No" << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; inline long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } inline long long lowbit(long long x) { return (x & -x); } inline long long kissme(long long x, long long y) { long long res = 1; if (x == 0) return 1; if (x == 1) return y; res = kissme(x / 2, y); res = res * res % mod; if (x % 2 == 1) res = res * y % mod; return res; } void read(int &x) { int f = 1; x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = x * 10 + s - '0'; s = getchar(); } x *= f; } void print(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) print(x / 10); putchar(x % 10 + '0'); } int T, n, x[N]; bool f[N][2]; void solve() { for (int i = 0; i < n + 2; i++) f[i][0] = f[i][1] = false; f[0][0] = true; f[n + 1][1] = true; for (int i = 1; i <= n; i++) { if (x[i] >= i - 1 && f[i - 1][0]) { f[i][0] = true; } } for (int i = n; i >= 1; i--) { if (x[i] >= n - i && f[i + 1][1]) { f[i][1] = true; } } for (int i = 1; i <= n; i++) { if (f[i][0] && f[i][1]) { cout << "Yes\n"; return; } } cout << "No\n"; return; } signed main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; cin >> T; while (T--) { cin >> n; for (int i = 1; i <= n; ++i) { cin >> x[i]; } solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int a[300010]; int b[300010]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int maxx = 0; int maxxp = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); b[n - i + 1] = a[i]; } int len1 = 0, len2 = 0; while (len1 < n && a[len1 + 1] >= len1) ++len1; while (len2 < n && b[len2 + 1] >= len2) ++len2; if (len1 + len2 >= n + 1) puts("Yes"); else puts("No"); } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) cin >> arr[i]; long long pr = -1, sf = n; long long count = n - 1; for (long long i = 0; i < n; i++) { if (arr[i] < i) break; pr = i; } for (long long i = n - 1; i > -1; i--) { if (arr[i] < n - 1 - i) break; sf = i; } if (sf <= pr) cout << "Yes" << "\n"; else cout << "No" << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 300010, M = 10000005; long long t, n, a[N], f[N], b[N], fs[N], bs[N], B, F; int solve() { scanf("%lld", &t); while (t--) { scanf("%lld", &n); bool pos = 0; B = 0, F = 0; for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); f[i] = 0, b[i] = 0; if (a[i] < i) f[i] = 1; if (a[i] < n - 1 - i) b[i] = 1; B += b[i]; } for (int i = 0; i < n; i++) { F += f[i]; bs[i] = B; fs[i] = F; B -= b[i]; } for (int i = 0; i < n; i++) { long long x = 0, y = 0; if (i - 1 >= 0) x = fs[i - 1]; if (i + 1 < n) y = bs[i + 1]; if (x == 0 && y == 0 && a[i] >= i && a[i] >= n - i - 1) { pos = 1; break; } } if (pos) printf("Yes\n"); else printf("No\n"); } return 0; } int main() { int ret = solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int maxl = 1, maxr = 1; for (int i = 1; i < n; i++) if (a[i] >= i) maxl++; else break; for (int i = n - 2; i >= 0; i--) if (a[i] >= n - 1 - i) maxr++; else break; if (maxl + maxr > n) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; long long int j = 0, k = 0, z = -1, x = n; for (int i = 0; i < n; ++i) { if (a[i] >= j) { j++; z = i; } else break; } for (int i = n - 1; i >= 0; --i) { if (a[i] >= k) { k++; x = i; } else break; } if (z >= x) { cout << "Yes\n"; } else cout << "No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t, n; cin >> t; while (t--) { cin >> n; long long a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int l = 0, r = n - 1; for (int i = 0; i < n; i++) { if (a[i] >= i) l = i; else break; } for (int j = n - 1; j >= 0; j--) { if (a[j] >= n - 1 - j) r = j; else break; } if (l >= r) cout << "YES"; else cout << "NO"; cout << endl; } }
#include <bits/stdc++.h> using namespace std; bool p[100001] = {false}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n], s = n, p = 0; for (long long int i = 0; i < n; i++) cin >> a[i]; for (long long int i = 0; i < n; i++) { if (a[i] < i) { s = i - 1; break; } } for (long long int i = n - 1, j = -1; i >= 0; i--) { if (a[i] < ++j) { p = i + 1; break; } } if (s < p) { cout << "No" << endl; continue; } cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; long long T, n; long long a[300005], b[300005]; void C() { memset(a, 0, sizeof(long long) * (n + 1)); memset(b, 0, sizeof(long long) * (n + 1)); } int main() { cin >> T; while (T--) { C(); cin >> n; if (n % 2 == 1) { for (int i = 1; i <= n; ++i) cin >> a[i]; long long h = 1, t = n, cnt = -1; while (1) { if (h == t) { b[h] = ++cnt; break; } b[h] = b[t] = ++cnt; h++, t--; } bool ok = 0; for (int i = 1; i <= n; ++i) { if (a[i] < b[i]) { puts("No"); ok = 1; break; } } if (ok == 0) puts("Yes"); } else { int sb; for (int i = 1; i <= n; ++i) cin >> a[i]; long long h = 1, t = n, cnt = -1; while (1) { if (h + 1 == t) { b[h] = b[t] = ++cnt; sb = h; b[h]++; break; } b[h] = b[t] = ++cnt; h++, t--; } bool ok = 0; for (int i = 1; i <= n; ++i) { if (a[i] < b[i]) { ok = 1; break; } } if (ok == 0) { puts("Yes"); continue; } b[sb]--; b[sb + 1]++; ok = 0; for (int i = 1; i <= n; ++i) { if (a[i] < b[i]) { puts("No"); ok = 1; break; } } if (ok == 0) puts("Yes"); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; for (int it = 0; it < t; ++it) { int n; cin >> n; vector<int> v(n, 0); for (auto& x : v) cin >> x; vector<int> kek(n, 0); if (n % 2 == 1) { for (int i = 0; i <= n / 2; i++) { kek[i] = i; } kek[n / 2 + 1] = n / 2 + 1; for (int i = 0; i <= n / 2; i++) { kek[n - 1 - i] = i; } bool yes = true; for (int i = 0; i < n; i++) { if (v[i] < kek[i]) yes = false; } if (yes) cout << "Yes\n"; else cout << "No\n"; } else { for (int i = 0; i < n / 2; i++) { kek[i] = i; } kek[n / 2] = n / 2; for (int i = n / 2 + 1; i < n; i++) { kek[i] = n - 1 - i; } bool yes = true; for (int i = 0; i < n; i++) { if (v[i] < kek[i]) yes = false; } if (yes) { cout << "Yes\n"; continue; } reverse(kek.begin(), kek.end()); yes = true; for (int i = 0; i < n; i++) { if (v[i] < kek[i]) yes = false; } if (yes) { cout << "Yes\n"; continue; } cout << "No\n"; } } }
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long long int flag = 0ll; bool ok = true; long long int start = 0; for (int i = 0; i < n; i++) { if (a[i] < i) { break; } start = i; } flag = a[start]; for (int i = start + 1; i < n; i++) { flag = min(a[i], flag - 1); if (flag < 0) { ok = false; break; } } if (!ok) { cout << "NO\n"; } else { cout << "YES\n"; } } }
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 1; const int MOD = 1e9 + 7; const int base = 257; const int M = 1e6 + 1; const int INFI = 1e8; long long Hash[M], po[M]; long long gethash(long long l, long long r) { return ((Hash[r] - Hash[l - 1] * po[r - l + 1] + MOD * MOD) % MOD); } void precomputehashing() { po[0] = 1; for (int i = 1; i <= M; i++) po[i] = (po[i - 1] * base) % MOD; string s; s = " " + s; for (int i = 1; i <= s.size() - 1; i++) Hash[i] = (Hash[i - 1] * base + s[i] - '*' + 1) % MOD; } long long fac[N], ifac[N]; long long PowerMod(long long a, long long n) { long long ret = 1; while (n) { if (n & 1) { ret *= a; ret %= MOD; } a *= a; a %= MOD; n /= 2; } return ret; } void precomputecombinatoris() { int i; fac[0] = 1; for (i = 1; i < N; i++) { fac[i] = (i * fac[i - 1]) % MOD; } ifac[N - 1] = PowerMod(fac[N - 1], MOD - 2); for (i = N - 2; i >= 0; i--) { ifac[i] = ((i + 1) * ifac[i + 1]) % MOD; } } long long C(int r, int n) { long long ret = fac[n]; ret *= ifac[r]; ret %= MOD; ret *= ifac[n - r]; ret %= MOD; return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a[N]; bool check = 0; for (int i = 0; i <= n - 1; i++) { cin >> a[i]; } bool res = 1; for (int i = 0; i <= n - 1; i++) { if (a[i] < i) { if (a[i] == a[i - 1]) a[i]--; int cnt = 0; for (int j = n - 1; j >= i; j--) { if (a[j] < cnt || cnt > a[i]) { res = 0; break; } else { cnt++; } } break; } } if (res) { cout << "YES" << "\n"; } else { cout << "NO" << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int tc; cin >> tc; while (tc--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < (int)(n); i++) cin >> a[i]; int preItr = -1, suffixItr = n; for (int i = 0; i < n; i++) { if (a[i] < i) break; preItr = i; } for (int i = n - 1; i >= 0; i--) { if (a[i] < (n - 1) - i) break; suffixItr = i; } if (suffixItr <= preItr) cout << "Yes" << '\n'; else cout << "No" << '\n'; } }
#include <bits/stdc++.h> using namespace std; vector<map<int, int>> adj; vector<vector<int>> ver; vector<bool> storage; void Solve() { int n; cin >> n; vector<int> vec(n); int pr = n; for (int i = 0; i < n; ++i) { cin >> vec[i]; if (pr == n && vec[i] < i) pr = i; } --pr; int sf = -1; for (int i = n - 1; i >= 0; --i) { if (vec[i] < n - i - 1) { sf = i; break; } } ++sf; if (sf <= pr) cout << "Yes\n"; else cout << "No\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) Solve(); }
#include <bits/stdc++.h> using namespace std; int main() { int T0; cin >> T0; for (int _ = 0; _ < T0; _++) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } bool f = 1; for (int i = 0; f && i < (n + 1) / 2; i++) { if (a[i] < i) f = 0; } for (int i = (n + 1) / 2; f && i < n; i++) { if (a[i] < n - 1 - i) f = 0; } if (!(n % 2) && a[n / 2 - 1] == a[(n) / 2] && a[n / 2] == n / 2 - 1) f = 0; if (f) cout << "Yes\n"; else cout << "No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; long long arr[300000]; long long temp[300000]; int main() { int q; cin >> q; while (q--) { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; temp[i] = arr[i]; } int st = 0; int endIdx1 = -1; for (int i = 0; i < n; i++) { if (arr[i] >= st) { st++; endIdx1 = i; } else { break; } } if (endIdx1 == n - 1) { cout << "Yes" << endl; continue; } st = 0; int endIdx = n; for (int i = n - 1; i >= 0; i--) { if (arr[i] >= st) { st++; endIdx = i; } else { break; } } if (endIdx == 0) { cout << "Yes" << endl; continue; } if (endIdx1 >= endIdx) { cout << "Yes" << endl; } else { cout << "No" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; inline int re() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return x * f; } int z[333333], y[333333]; int a[333333]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; z[0] = 1; for (int i = 1; i <= n; i++) { a[i] = re(); if (a[i] >= i - 1 && z[i - 1]) z[i] = 1; else z[i] = 0; } y[n + 1] = 1; int f = 0; for (int i = n; i >= 1; i--) { if (a[i] >= n - i && y[i + 1]) { y[i] = 1; } else y[i] = 0; if (y[i] && z[i]) { f = 1; break; } } if (f == 1) puts("Yes"); else puts("No"); } }
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; const int inf = 1e9 + 5; const int nax = 1e5 + 10; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { if (a[i] < i) { for (int j = i; j < n; j++) { if (a[j] >= a[j - 1] && a[j - 1] != 0) a[j] = a[j - 1] - 1; else if (a[j] >= a[j - 1] && a[j - 1] == 0) { cout << "No"; return; } } break; } } cout << "Yes"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long T; cin >> T; while (T--) { solve(); cout << "\n"; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; } inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; } inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; } inline bool setmax(long long &x, long long y) { return (y > x) ? x = y, 1 : 0; } using namespace std; int n; int a[300000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(20); int T; cin >> T; while (T--) { cin >> n; for (int i = (0); i < (n); ++i) cin >> a[i]; int f = 1; int i = 1; while (i < n && a[i] >= i) i++; if (i) i--; int h = n - i - 1; while (i < n && a[i] >= h) i++, h--; if (i == n) cout << "Yes\n"; else cout << "No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long int MaxN = 300005; const long long int mod = 1e9 + 7; const float pi = 3.1415926535897932384626433832795028; long long int mcd(long long int a, long long int b) { if (a == 0) return b; return mcd(b % a, a); } int arr[MaxN]; void solve() { int N, i, j, p, q; cin >> N; for (i = 1; i <= N; i++) { cin >> arr[i]; } p = 0, q = N + 1; for (i = 1; i <= N; i++) { if (arr[i] >= i - 1) { p = i; } else break; } for (i = N; i > 0; i--) { if (arr[i] >= N - i) { q = i; } else break; } if (p >= q) cout << "Yes\n"; else cout << "No\n"; } int main() { long long int t, i; cin >> t; for (i = 1; i <= t; i++) { solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long ar[n]; for (long long i = 0; i < n; i++) cin >> ar[i]; long long ans = 0; long long begin = 0, k = 0; while (begin < n && ar[begin] >= begin) begin++; if (begin == n) ans = 1; begin = n - 1; while (begin > 0 && ar[begin] >= k) { begin--; k++; } if (k == n) ans = 1; long long left = 0, right = n - 1; k = 0; while (ar[left] >= left) left++; left--; while (ar[right] >= k) { right--; k++; } right++; if (left >= right) ans = 1; if (ans == 1) cout << "Yes" << endl; else cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 5; int n, a[(int)1e6 + 5]; int main(void) { ios_base::sync_with_stdio(false), cin.tie(nullptr); int tc; cin >> tc; while (tc--) { cin >> n; int i; for (i = 0; i < n; ++i) { cin >> a[i]; } int l = n, r = n; for (i = 0; i < n; ++i) { if (a[i] < i) { l = i; break; } } reverse(a, a + n); for (i = 0; i < n; ++i) { if (a[i] < i) { r = i; break; } } if (l + r > n) cout << "Yes\n"; else cout << "No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int solve() { long long n, r = 0; cin >> n; long long l = n; vector<long long int> a(n); for (long long int i = 0; i < n; i++) cin >> a[i]; for (long long int i = 0; i < n; i++) if (a[i] >= i) continue; else { l = i - 1; break; } for (long long int i = n - 1; i > -1; i--) if (a[i] >= n - 1 - i) continue; else { r = i + 1; break; } cout << (l >= r ? "YES\n" : "NO\n"); return 0; } int main() { auto start = chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long test_cases = 1; cin >> test_cases; while (test_cases--) solve(); auto stop = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); }
#include <bits/stdc++.h> const long long MOD = 1000 * 1000 * 1000 + 7; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; cin >> T; while (T--) { long long N; cin >> N; long long A[N]; long long flag = 0; for (long long i = 0; i < N; i++) { cin >> A[i]; } if (N % 2 != 0) { for (long long i = 0; i < N; i++) { if (A[i] < min(i, N - i - 1)) { flag = 1; break; } } } else { for (long long i = 0; i < N; i++) { if (A[i] < min(i, N - i - 1)) { flag = 1; break; } if (A[(N / 2) - 1] == A[N / 2] && A[N / 2] == (N / 2) - 1) { flag = 1; break; } } } if (flag == 1) cout << "No" << '\n'; else cout << "Yes" << '\n'; } return 0; }