text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
vector<long long> a(n);
vector<long long> b(n);
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 0; i < n; i++) cin >> b[i];
sort(b.begin(), b.end());
long long ans = m - 1;
for (long long i = 0; i < n; i++) {
long long z;
if (b[i] > a[0])
z = (b[i] - a[0]) % m;
else
z = (m + b[i] - a[0]) % m;
vector<long long> temp;
temp = a;
for (long long i = 0; i < n; i++) temp[i] = (temp[i] + z) % m;
sort(temp.begin(), temp.end());
if (temp == b) ans = min(ans, z);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
vector<long long> a(n), b(n);
set<long long> s;
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 0; i < n; i++) cin >> b[i], s.insert(b[i]);
sort(b.begin(), b.end());
sort(a.begin(), a.end());
long long mi = a[0], ans = INT_MAX;
for (auto x : s) {
long long dif;
if (x >= mi)
dif = x - mi;
else
dif = m + x - mi;
vector<long long> t(a);
for (long long i = 0; i < n; i++) {
t[i] = (t[i] + dif) % m;
}
sort(t.begin(), t.end());
if (t == b) {
ans = min(ans, dif);
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
bool check(vi a, vi &b, int x, int m) {
for (int i = (0); i < (a.size()); i++) {
a[i] = (a[i] + x) % m;
}
sort((a).begin(), (a).end());
for (int i = (0); i < (a.size()); i++) {
if (a[i] != b[i]) return false;
}
return true;
}
void solve() {
int n, m;
cin >> n >> m;
vi a(n), b(n);
for (int i = (0); i < (n); i++) {
cin >> a[i];
}
for (int i = (0); i < (n); i++) {
cin >> b[i];
}
sort((a).begin(), (a).end());
sort((b).begin(), (b).end());
set<int> s;
for (int j = (0); j < (n); j++) {
int y = b[0] - a[j];
if (y >= 0)
y = y % m;
else
y = m - abs(y);
s.insert(y);
}
int x;
for (auto i : s) {
if (check(a, b, i, m)) {
x = i;
break;
}
}
cout << x;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline bool chkmin(T1 &first, const T2 &second) {
if (first > second) {
first = second;
return 1ll;
} else {
return 0ll;
}
}
template <typename T1, typename T2>
inline bool chkmax(T1 &first, const T2 &second) {
if (first < second) {
first = second;
return 1ll;
} else {
return 0ll;
}
}
istream &operator>>(istream &insert, vector<long long> &a) {
for (long long &now : a) {
insert >> now;
}
return insert;
}
ostream &operator<<(ostream &out, vector<long long> &a) {
for (long long &now : a) {
out << now << ' ';
}
out << "\n";
return out;
}
long long n, mod;
long long solve(long long st, vector<long long> a, vector<long long> b) {
long long res = b[0] - st;
for (long long &now : a) {
now = (now + res + mod) % mod;
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
return a == b;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> mod;
vector<long long> a(n), b(n);
cin >> a >> b;
long long ans = 1e18;
for (long long &now : a) {
if (solve(now, a, b)) {
chkmin(ans, (b[0] - now + mod) % mod);
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
bool FLAG = 1;
using namespace std;
const long long MOD = (long long)1e9 + 7, N = (long long)2e6 + 222;
const long long INF = (long long)1e18;
long long n, k, p[N], a[N], b[N], b1[N];
string s;
void clear() {
for (long long i = 1; i <= n; ++i) {
p[i] = a[i];
}
}
long long m;
void solve() {
cin >> n >> m;
long long mx = 0;
for (long long i = 1; i <= n; ++i) {
cin >> a[i];
mx = max(mx, a[i]);
}
for (long long i = 1; i <= n; ++i) {
cin >> b[i];
}
sort(b + 1, b + 1 + n);
for (long long i = 1; i <= n; ++i) {
b1[i] = b[i] + m;
}
long long mn = INF;
for (long long i = 1; i <= n; ++i) {
clear();
long long d;
if (b[i] - mx < 0)
d = b[i] + m - mx;
else
d = b[i] - mx;
for (long long j = 1; j <= n; ++j) {
p[j] += d;
p[j] %= m;
}
sort(p + 1, p + 1 + n);
bool ok = 0;
for (long long j = 1; j <= n; ++j) {
if (p[j] != b[j]) ok = 1;
}
if (ok == 0) {
mn = min(mn, d);
}
}
cout << mn;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j, x;
cin >> n >> m;
x = m;
vector<int> a(n), b(n);
for (i = 0; i < n; ++i) cin >> a[i];
for (i = 0; i < n; ++i) cin >> b[i];
sort(b.begin(), b.end());
for (i = 0; i < n; ++i) {
int t1 = (b[0] - a[i]) % m;
if (t1 < 0) t1 += m;
vector<int> t0(a);
for (j = 0; j < n; ++j) t0[j] = (t0[j] + t1) % m;
sort(t0.begin(), t0.end());
if (b == t0) x = min(x, t1);
}
cout << x << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;
const long long INF = INT_MAX;
const long long MOD2 = 998244353;
long long gcd(long long a, long long b), lcm(long long a, long long b),
expo(long long e, long long n);
bool cases = false;
void letsGO(long long test) {
long long n, m;
cin >> n >> m;
long long a[n], b[n];
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 0; i < n; i++) cin >> b[i];
sort(b, b + n);
vector<long long> xes;
for (long long i = 0; i < n; i++)
xes.push_back(a[0] <= b[i] ? b[i] - a[0] : b[i] - a[0] + m);
sort(xes.begin(), xes.end());
for (long long i = 0; i < n; i++) {
vector<long long> ok;
long long x = xes[i];
for (long long j = 0; j < n; j++) {
ok.push_back((a[j] + x) % m);
}
sort(ok.begin(), ok.end());
long long flag = 0;
for (long long j = 0; j < n; j++) {
if (b[j] != ok[j]) {
flag = 1;
break;
}
}
if (!flag) {
cout << x << endl;
return;
}
}
}
void speeeeeeeeeed() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long expo(long long e, long long n) {
return n ? n & 1 ? e * expo(e, --n) : expo(e * e, n / 2) : 1;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
signed main() {
speeeeeeeeeed();
cout << fixed << setprecision(10);
long long TT = 1, cnt = 0;
if (cases) cin >> TT;
while (TT--) letsGO(++cnt);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
map<int, int> mp1, mp2;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
mp1[x]++;
}
for (int i = 0; i < n; i++) {
int x;
cin >> x;
mp2[x]++;
}
map<int, int> mp;
for (auto it1 = mp1.begin(); it1 != mp1.end(); it1++) {
for (auto it2 = mp2.begin(); it2 != mp2.end(); it2++) {
if (it1->second == it2->second) {
int x = it1->first;
int y = it2->first;
if (x > y)
mp[m - (x - y)]++;
else
mp[y - x]++;
}
}
}
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it->second >= mp1.size()) {
cout << it->first << endl;
return 0;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
int main() {
long long n, m, tc, num, t = 1;
scanf("%lld %lld", &num, &m);
vector<long long> v1, v2;
for (long long i = 0; i < num; ++i) {
scanf("%lld", &n);
v1.push_back(n);
}
for (long long i = 0; i < num; ++i) {
scanf("%lld", &n);
v2.push_back(n);
}
sort(v2.begin(), v2.end());
long long ans = INT_MAX;
for (long long i = 0; i < num; ++i) {
vector<long long> temp;
long long avgmod = (m + v2[i] - v1[0]) % m;
for (long long j = 0; j < num; ++j) {
temp.push_back((v1[j] + avgmod) % m);
}
sort(temp.begin(), temp.end());
if (v2 == temp) {
ans = min(ans, avgmod);
}
}
printf("%lld\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long n, m;
cin >> n >> m;
long long arr[n];
long long brr[n];
for (long long i = 0; i < n; i++) cin >> arr[i];
multiset<long long> st2;
for (long long i = 0; i < n; i++) cin >> brr[i];
for (long long i = 0; i < n; i++) st2.insert(brr[i]);
long long ans = 1e13;
{
for (long long j = 0; j < n; j++) {
multiset<long long> st1;
long long z = brr[j] - arr[0];
if (z < 0) z = m + z;
for (long long k = 0; k < n; k++) {
st1.insert((arr[k] + z) % m);
}
if (st1 == st2 && z >= 0) {
ans = min(ans, z);
} else if (st1 == st2 && z < 0) {
ans = min(ans, m + z);
}
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[2011], b[2011], temp[2011];
int n, m;
void input() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
sort(b, b + n + 1);
sort(a, a + n + 1);
}
bool check(int x) {
for (int i = 1; i <= n; i++) temp[i] = (a[i] + x) % m;
sort(temp, temp + n + 1);
for (int i = 1; i <= n; i++)
if (b[i] != temp[i]) return false;
return true;
}
int Giang_Bae() {
int t = INT_MAX;
int res = INT_MAX;
for (int i = 1; i <= n; i++) {
t = (m + b[1] - a[i]) % m;
if (check(t) == true) res = min(res, t);
}
return res;
}
int main() {
input();
cout << Giang_Bae();
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double pii = 2 * pi;
const double eps = 1e-6;
const long long MOD = 1e9 + 7;
void solve() {
int n;
long long m;
cin >> n >> m;
vector<long long> a(n, 0ll), b(n, 0ll);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
long long ans = 10ll * int(1e9);
for (int i = 0; i < n; i++) {
bool flag = true;
long long x = (b[i] - a[0] + m) % m;
for (int j = 0; j < n; j++) {
if ((a[j] + x) % m != b[(i + j) % n]) flag = false;
}
if (flag) ans = min(ans, x);
}
cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
ll powmod(ll base, ll exp, const ll MOD) {
ll ans = 1;
while (exp) {
if (exp & 1) ans = (ans * base) % MOD;
base = (base * base) % MOD;
exp >>= 1;
}
return ans;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int n, m;
cin >> n >> m;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) cin >> b[i];
sort(b.begin(), b.end());
int ans = 1e9 + 9;
for (int i = 0; i < n; ++i) {
int x = (b[i] - a[0] + m) % m;
vector<int> tmp = a;
for (int i = 0; i < n; ++i) tmp[i] = (tmp[i] + x) % m;
sort(tmp.begin(), tmp.end());
if (tmp == b) {
ans = min(ans, x);
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m, a[2005], b[2005], c[2005];
int check() {
for (int i = 0; i < n; ++i)
if (b[i] != c[i]) return 0;
return 1;
}
int main() {
scanf("%d", &n);
scanf("%d", &m);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
sort(a, a + n);
sort(b, b + n);
int mn = 1e9;
for (int i = 0; i < n; ++i) {
int t = (b[i] - a[0] + m) % m;
for (int j = 0; j < n; ++j) c[j] = (a[j] + t) % m;
sort(c, c + n);
if (check()) mn = min(mn, t);
}
printf("%d\n", mn);
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[2005], b[2005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
sort(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
int ans = 0x7fffffff;
for (int i = 1; i <= n; i++) {
int t = b[i] - a[1];
if (t < 0) {
t += m;
}
bool flag = true;
for (int j = 1; j <= n; j++) {
int ai = j;
int bi = (i + j - 1 - 1) % n + 1;
if ((a[ai] + t) % m != b[bi]) {
flag = false;
break;
}
}
if (flag) {
ans = min(ans, t);
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
a = abs(a), b = abs(b);
if (a < b) swap(a, b);
return b ? gcd(b, a % b) : a;
}
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
vector<vector<int> > adj;
set<int> st;
int n, m, a[300000 + 5], b[300000 + 5], c[300000 + 5];
map<int, int> m1, m2;
vector<pair<int, int> > v1, v2;
int main(void) {
ios::sync_with_stdio(false), cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
m1[a[i]] += 1;
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
m2[b[i]] += 1;
}
for (auto x : m1) v1.emplace_back(x.second, x.first);
for (auto x : m2) v2.emplace_back(x.second, x.first);
sort(v1.rbegin(), v1.rend());
sort(v2.rbegin(), v2.rend());
sort(b, b + n);
int ans = (int)(1e9 + 5), x;
for (int i = 0; i < (int)(v1).size(); ++i) {
if (v1[0].first == v2[i].first) {
x = v2[i].second - v1[0].second;
if (x < 0) x += m;
for (int j = 0; j < n; ++j) {
c[j] = (a[j] + x) % m;
}
sort(c, c + n);
bool flg = true;
for (int j = 0; j < n; ++j)
if (c[j] != b[j]) {
flg = false;
}
if (flg) ans = min(ans, x);
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long fpow(long long a, long long b) {
long long result = 1;
while (b) {
if (b & 1) {
result = (a * result) % 1000000007;
}
a = (a * a) % 1000000007;
b = b / 2;
}
return result;
}
int main() {
long long n;
long long m;
cin >> n >> m;
long long a[n], b[n], c[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(b, b + n);
long long ans = 1e18;
for (int i = 0; i < n; i++) {
long long f = 0;
long long x = b[0] - a[i];
if (x < 0) {
x += m;
}
for (int i = 0; i < n; i++) {
c[i] = (a[i] + x) % m;
}
sort(c, c + n);
for (int i = 0; i < n; i++) {
if (c[i] != b[i]) {
f = 1;
break;
}
}
if (f == 0) {
ans = min(ans, x);
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[2005], b[2005];
const int inf = 1e9 + 7;
int c[2005];
int check(int pos) {
memcpy(c, a, sizeof(a));
int tv = b[pos] - c[0];
if (tv < 0) tv += m;
for (int i = 0; i < n; i++) c[i] = (c[i] + tv) % m;
for (int i = 0; i < n; i++) {
if (c[i] != b[(i + pos) % n]) return inf;
}
return tv;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < n; i++) scanf("%d", &b[i]);
int ans = inf;
sort(a, a + n);
sort(b, b + n);
for (int i = 0; i < n; i++) ans = min(check(i), ans);
printf("%d\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
long long n, m;
scanf("%lld %lld", &n, &m);
vector<long long> a, b;
map<long long, long long> am, bm;
for (long long i = 0; i < n; i++) {
long long aa;
cin >> aa, a.push_back(aa);
am[aa]++;
}
for (long long i = 0; i < n; i++) {
long long aa;
cin >> aa, b.push_back(aa);
bm[aa]++;
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (a == b) {
cout << 0 << endl;
return 0;
}
long long ans = INT_MAX;
for (long long i = 0; i < n; i++) {
map<long long, long long> t = bm;
long long x = b[i] - a[0];
if (x < 0) x += m;
vector<long long> c(n);
for (long long j = 0; j < n; j++) {
c[j] = ((a[j] + x) % m);
}
sort(c.begin(), c.end());
if (c == b) ans = min(ans, x);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char *argv[]) {
int n, m;
scanf("%d %d", &n, &m);
int a[n], b[n];
map<int, int> mp_a;
map<int, int> mp_b;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < n; i++) {
scanf("%d", &b[i]);
mp_b[b[i]]++;
}
sort(a, a + n);
int k = a[0];
long long ans = 2000000000000000 + 5;
for (int i = 0; i < n; i++) {
int x;
if (b[i] == k)
x = 0;
else if (b[i] > k)
x = b[i] - k;
else
x = m - k + b[i];
for (int j = 0; j < n; j++) {
mp_a[(a[j] + x) % m]++;
}
bool f = true;
for (auto &it : mp_a) {
if (mp_b.find(it.first) != mp_b.end() && mp_b[it.first] == it.second)
continue;
else
f = false;
}
if (f) ans = min(ans, (long long)x);
mp_a.clear();
}
printf("%lld\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
long n, m;
long a[3000], b[3000];
long ha[3000], hb[3000];
long x = 0, min = 1000000003;
bool flag;
for (int i = 0; i < 3000; i++) {
a[i] = 0;
b[i] = 0;
}
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(a, a + n);
sort(b, b + n);
for (int i = 0; i < n - 1; i++) {
ha[i] = a[i + 1] - a[i];
hb[i] = b[i + 1] - b[i];
}
ha[n - 1] = a[0] - a[n - 1];
if (ha[n - 1] < 0) ha[n - 1] += m;
hb[n - 1] = b[0] - b[n - 1];
if (hb[n - 1] < 0) hb[n - 1] += m;
for (int i = 0; i < n; i++) {
flag = true;
for (int j = 0; j < n; j++) {
if (ha[j] != hb[(i + j) % n]) {
flag = false;
break;
}
}
if (flag) {
x = b[i] - a[0];
if (x < 0) x += m;
if (x < min) min = x;
}
}
cout << min << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, m, ans = inf;
long long a[2010], b[2010], c[2010];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
sort(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
for (int w = 1, p = 0; w <= n; w++, p = 0) {
for (int i = w; i <= n; i++) c[++p] = b[i];
for (int i = 1; i < w; i++) c[++p] = b[i];
int x = (c[1] - a[1] + m) % m, flag = 1;
for (int i = 2; i <= n; i++) {
int sub = (c[i] - a[i] + m) % m;
if (sub != x) {
flag = 0;
break;
}
}
if (flag) ans = min(ans, x);
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a[2005];
long long int b[2005];
map<long long int, long long int> m1;
map<long long int, long long int> m2;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int i, j, k, n, t, m;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> a[i];
m1[a[i]]++;
}
for (i = 0; i < n; i++) {
cin >> b[i];
m2[b[i]]++;
}
long long int flag = 0;
set<long long int> ans;
for (i = 0; i < n; i++) {
if (flag) break;
for (j = 0; j < n; j++) {
if (m1[a[i]] == m2[b[j]]) {
flag = 1;
long long int temp;
if (a[i] <= b[j])
temp = b[j] - a[i];
else
temp = m + b[j] - a[i];
long long int flag1 = 0;
for (k = 0; k < n; k++) {
if (m1[a[k]] != m2[(a[k] + temp) % m]) {
flag1 = 1;
break;
}
}
if (!flag1) ans.insert(temp);
}
}
}
if (!flag)
cout << 0 << endl;
else {
set<long long int>::iterator it = ans.begin();
cout << *it << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long n, m, mx = 0;
cin >> n >> m;
vector<long long> a(n), b(n), tmp(n);
for (auto& i : a) cin >> i;
for (auto& i : b) cin >> i, mx = max(mx, i);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
long long ans = 1e18;
for (int j = 0; j < n; ++j) {
long long x = ((b[0] - a[j]) + m) % m;
for (int i = 0; i < n; ++i) tmp[i] = ((a[i] + x) % m);
sort(tmp.begin(), tmp.end());
if (tmp == b) ans = min(ans, x);
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, i, j, l, ans = (long long)10e9;
bool ok;
cin >> n >> m;
long long arr[n], brr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
}
for (i = 0; i < n; i++) {
cin >> brr[i];
}
sort(arr, arr + n);
sort(brr, brr + n);
for (i = 0; i < n; i++) {
l = (m - arr[i] + brr[0]) % m;
ok = true;
for (j = 0; j < n; j++) {
if ((arr[(j + i) % n] + l) % m != brr[j]) {
ok = false;
break;
}
}
if (ok) {
ans = min(ans, l);
} else {
continue;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b);
long long int gcd(long long int a, long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long int modulo(long long int a, long long int b) {
long long int r = a % b;
return r < 0 ? r + b : r;
}
unsigned long long int ncr(unsigned long long int n, unsigned long long int r) {
if (r > n - r) r = n - r;
unsigned long long int ans = 1;
unsigned long long int i;
for (i = 1; i <= r; i++) {
ans *= n - r + i;
ans /= i;
}
return ans;
}
class abc {
public:
long long int val;
long long int ind;
};
bool fun1(abc x, abc y) { return x.val > y.val; }
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long int modInverse(long long int n, long long int p) {
return power(n, p - 2, p);
}
long long int fact[100000 + 2];
long long int ncrfast(long long int n, long long int r, long long int p) {
if (r == 0) return 1;
return (fact[n] * modInverse(fact[r], p) % p * modInverse(fact[n - r], p) %
p) %
p;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n, m;
cin >> n >> m;
long long int a[n];
long long int b[n];
long long int mina = 99999999999999;
long long int minb = 99999999999999;
long long int maxa = 0;
long long int maxb = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
}
for (long long int i = 0; i < n; i++) {
cin >> b[i];
}
vector<long long int> v;
sort(a, a + n);
sort(b, b + n);
for (long long int i = 0; i < n; i++) {
long long int x = b[0] - a[i];
if (x < 0) x = x + m;
long long int aa[n];
for (long long int j = 0; j < n; j++) {
aa[j] = (a[j] + x) % m;
}
sort(aa, aa + n);
long long int flag = 0;
for (long long int k = 0; k < n; k++) {
if (aa[k] != b[k]) {
flag = 1;
break;
}
}
if (flag == 0) v.push_back(x);
}
long long int ans = 9999999999999;
for (long long int i = 0; i < v.size(); i++) {
ans = min(ans, v[i]);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
int a[maxn], b[maxn], c[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
int ans = 1e9;
sort(b, b + n);
for (int i = 0; i < n; i++) {
int x = (b[0] - a[i] + m) % m;
for (int j = 0; j < n; j++) {
c[j] = (a[j] + x) % m;
}
int flag = 0;
sort(c, c + n);
for (int j = 0; j < n; j++) {
if (c[j] != b[j]) {
flag = 1;
break;
}
}
if (flag == 0) {
ans = min(ans, x);
}
}
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e3 + 1000;
long long a[maxn];
long long b[maxn];
long long sa[maxn];
long long sb[maxn];
bool check(int pos1, int pos2, int N) {
for (int i = 1; i <= N - 1; i++) {
if (sb[pos1++] != sa[pos2++]) return false;
}
return true;
}
int main() {
int N;
long long M;
cin >> N >> M;
for (int i = 1; i <= N; i++) cin >> a[i];
sort(a + 1, a + 1 + N);
for (int i = 1; i <= N; i++) cin >> b[i];
sort(b + 1, b + 1 + N);
for (int i = 1; i <= N; i++) b[i + N] = b[i];
for (int i = 1; i < N; i++) sa[i] = a[i + 1] - a[i];
for (int i = 1; i < 2 * N; i++) sb[i] = (b[i + 1] - b[i] + M) % M;
int pos = -1;
long long ans = 1e9 + 1000;
for (int i = 1; i < 2 * N; i++) {
if (check(i, 1, N) == true) {
pos = i;
ans = min(ans, (b[pos] - a[1] + M) % M);
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int p[2005], q[2005];
void solve() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &p[i]);
p[i] %= m;
}
for (int i = 0; i < n; i++) scanf("%d", &q[i]);
map<int, int> mp, mp1;
for (int i = 0; i < n; i++) {
mp[p[i]]++, mp1[q[i]]++;
}
map<int, int> MAP;
for (auto it : mp) {
for (auto jt : mp1) {
if (it.second == jt.second) {
if (jt.first >= it.first) {
MAP[jt.first - it.first]++;
} else {
MAP[(abs(jt.first - 0) + abs(m - it.first))]++;
;
}
}
}
}
for (auto it : MAP) {
if (it.second == (int)(mp).size()) {
printf("%d\n", it.first);
return;
}
}
}
int main() {
int tc = 1;
while (tc--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = (long long)1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
if (a < val) a = val;
}
const long long N = 5 * (long long)1e5 + 10;
long long n, m;
void solve() {
cin >> n >> m;
vector<long long> a(n), b(n);
for (long long i = 0; i < n; ++i) {
cin >> a[i];
}
for (long long i = 0; i < n; ++i) {
cin >> b[i];
}
sort(b.begin(), b.end());
long long ans = inf;
for (long long i = 0; i < n; ++i) {
long long x = (b[0] - a[i] + m) % m;
;
bool good = 1;
map<long long, long long> M;
for (auto it : b) {
M[it]++;
}
map<long long, long long> X;
for (long long j = 0; j < n; ++j) {
long long tt = (a[j] + x) % m;
X[tt]++;
};
if (X == M) {
smin(ans, x);
}
}
cout << ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t = 1;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long ara[2003];
long long ara2[2003];
unordered_map<long long, long long> m1;
unordered_map<long long, long long> m2;
unordered_map<long long, long long>::iterator it;
int main() {
long long n, m;
scanf("%lld", &n);
scanf("%lld", &m);
for (long long i = 0; i < n; i++) scanf("%lld", &ara[i]);
for (long long i = 0; i < n; i++) {
scanf("%lld", &ara2[i]);
long long x = ara2[i];
m1[x]++;
}
long long ans = 9000000000000000;
for (long long i = 0; i < n; i++) {
long long a = (ara2[i] - ara[0] + m) % m;
for (long long j = 0; j < n; j++) m2[(ara[j] + a) % m]++;
long long flag = 0;
for (it = m2.begin(); it != m2.end(); it++) {
if (it->second != m1[it->first]) {
flag = 1;
break;
}
}
if (!flag) ans = min(a, ans);
m2.clear();
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mm = 2e5 + 5;
long long int power(long long int a, long long int b) {
long long int res = 1;
while (b != 0) {
if (b & 1) {
res = (res * a) % 1000000007;
}
b >>= 1;
a = (a * a) % 1000000007;
}
return res % 1000000007;
}
bool iscompo(long long int x) {
for (long long int i = 2; i * i <= x; i++) {
if (x % i == 0) {
return 1;
}
}
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
long long int m;
cin >> m;
vector<long long int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int j = 0; j < n; j++) cin >> b[j];
sort(b.begin(), b.end());
long long int ans = INT_MAX;
for (long long int i = 0; i < n; i++) {
long long int x = (m + b[i] - a[0]) % m;
vector<long long int> temp;
for (long long int j = 0; j < n; j++) {
temp.push_back((a[j] + x) % m);
}
sort(temp.begin(), temp.end());
if (temp == b) {
ans = min(ans, x);
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
char c = getchar();
int x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
const int inf = 2147483647 - 1;
const int maxn = 3e5 + 10;
int a[maxn];
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n = read();
for (int i = 1; i <= n; ++i) a[i] = read();
int l, r;
for (int i = 1; i <= n; ++i) {
if (a[i] >= i - 1)
l = i;
else
break;
}
for (int i = n; i; --i) {
if (a[i] >= n - i)
r = i;
else
break;
}
if (l >= r)
puts("Yes");
else
puts("No");
}
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];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int k = 0, sign = 0;
bool ans1 = true;
int i = 0;
for (i = 0; i < n; i++) {
if (a[i] >= k) {
k++;
} else {
break;
}
}
k = 0;
for (int j = n - 1; j >= i; j--) {
if (a[j] >= k) {
if (j == i && k == a[j - 1]) {
ans1 = false;
break;
}
k++;
} else {
ans1 = false;
break;
}
}
k = 0;
bool ans2 = true;
for (int j = n - 1; j >= 0; j--) {
if (a[j] >= k) {
k++;
} else {
ans2 = false;
break;
}
}
if (ans1 || ans2)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long const inf = 1e9 + 7;
int32_t main() {
long long t;
cin >> t;
for (long long k = 0; k < t; ++k) {
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; ++i) {
cin >> a[i];
}
long long l = 0, r = n - 1;
long long shitl = 0, shitr = 0;
long long sosat = 0;
while (r > l + 1) {
if (a[l] < shitl || a[r] < shitr) {
sosat = 1;
break;
} else {
++l;
--r;
++shitl;
++shitr;
}
}
if (sosat) {
cout << "No" << '\n';
continue;
}
if (l == r) {
if (a[l] >= shitl)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
continue;
} else {
l = n / 2 - 1;
r = l + 1;
shitl = l;
shitr = shitl;
if (a[l] >= shitl + 1 && a[r] >= shitr ||
a[l] >= shitl && a[r] >= shitr + 1)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
continue;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void init(void) { ios::sync_with_stdio(0), cin.tie(0); }
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
cerr << "{";
_print(p.first);
cerr << ",";
_print(p.second);
cerr << "}";
}
template <class T>
void _print(vector<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(set<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
cerr << "[ ";
for (auto i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
class DisjointSet {
public:
vector<int> parent;
DisjointSet(int n) : parent(n) {
for (int i = 0; i < n; i++) parent[i] = i;
}
void join(int a, int b) {
int x = find(a), y = find(b);
if (y < x) {
parent[x] = y;
} else {
parent[y] = x;
}
}
int find(int a) { return a == parent[a] ? a : parent[a] = find(parent[a]); }
bool check(int a, int b) { return find(a) == find(b); }
};
void fun() {
int n;
std::cin >> n;
vector<int> a(n, 0);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
int p1 = n, p2 = -1;
for (int i = 0; i < n; i++) {
if (a[i] < i) {
p1 = i - 1;
break;
}
}
for (int i = n - 1; i >= 0; i--) {
if (a[i] < n - i - 1) {
p2 = i + 1;
break;
}
}
if (p1 >= p2) {
std::cout << "Yes"
<< "\n";
} else {
std::cout << "No"
<< "\n";
}
}
int main() {
init();
cout << fixed << setprecision(20);
int t;
std::cin >> t;
for (int i = 0; i < t; i++) fun();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, a[300005];
scanf("%d", &t);
while (t--) {
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
int pre = -1;
int suf = n;
for (int i = 0; i < n; ++i) {
if (a[i] < i) break;
pre = i;
}
for (int i = n - 1; i >= 0; --i) {
if (a[i] < n - i - 1) break;
suf = i;
}
if (suf <= pre)
printf("YES\n");
else
printf("NO\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long int M = 1e9 + 7;
long long int inf = 9 * 1e18;
long long int begtime = clock();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long int n, m;
long long int binpow(long long int val, long long int deg) {
if (deg < 0) return 0;
if (!deg) return 1 % M;
if (deg & 1) return binpow(val, deg - 1) * val % M;
long long int res = binpow(val, deg >> 1);
return (res * res) % M;
}
long long int modinv(long long int n) { return binpow(n, M - 2); }
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() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int i, j, t, k, x, y, z, N;
cin >> t;
while (t--) {
cin >> n;
long long int a[n];
for (i = 0; i < n; i++) cin >> a[i];
long long int flg = 0;
i = 0;
j = n - 1;
x = -1;
y = -1;
while (i < j) {
if (j - i == 1) {
if (a[j] == y + 1 && a[i] == x + 1) {
flg = 1;
break;
}
if (a[i] < x + 1) {
flg = 1;
break;
}
if (a[j] < y + 1) {
flg = 1;
break;
}
if (a[i] < a[j]) {
a[i] = x + 1;
} else {
a[j] = y + 1;
}
} else {
if (a[i] >= x + 1) {
a[i] = x + 1;
} else {
flg = 1;
break;
}
if (a[j] >= y + 1) {
a[j] = y + 1;
} else {
flg = 1;
break;
}
}
x = a[i];
y = a[j];
i++;
j--;
}
if (i == j) {
if (a[i] < x + 1) {
flg = 1;
}
}
if (flg)
cout << "No\n";
else
cout << "Yes\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int t, n, arr[300010], tmp[300010];
int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
tmp[n - i - 1] = arr[i];
}
int inc = 1, flag = 0;
for (int i = 0; i < n; i++) {
if (inc) {
if (arr[i] < i) {
inc = 0;
i--;
} else {
arr[i] = i;
}
} else {
arr[i] = min(arr[i - 1] - 1, arr[i]);
if (arr[i] < 0) {
flag = 1;
break;
}
}
}
if (!flag) {
cout << "Yes\n";
continue;
}
inc = 1;
flag = 0;
for (int i = 0; i < n; i++) {
arr[i] = tmp[i];
if (inc) {
if (arr[i] < i) {
inc = 0;
i--;
} else {
arr[i] = i;
}
} else {
arr[i] = min(arr[i - 1] - 1, arr[i]);
if (arr[i] < 0) {
flag = 1;
break;
}
}
}
if (!flag) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
vector<int> a;
for (int j = 0; j < n; j++) {
int x;
cin >> x;
a.push_back(x);
}
int lr = -1;
int rl = n;
for (lr = 0; lr < n; lr++) {
if (a[lr] < lr) {
break;
}
}
lr--;
for (rl = n - 1; rl >= 0; rl--) {
if (a[rl] < n - rl - 1) {
break;
}
}
rl++;
if (lr >= rl) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[300005];
int main() {
int T, n, i;
cin >> T;
while (T--) {
int flag = 1;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
}
if (n % 2) {
for (i = 1; i <= n / 2 + 1; i++) {
if (a[i] < i - 1) {
flag = 0;
break;
}
}
if (flag)
for (i = n; i >= n / 2 + 1; i--) {
if (a[i] < n - i) {
flag = 0;
break;
}
}
} else {
for (i = 1; i <= n / 2 - 1; i++) {
if (a[i] < i - 1 || a[n - i + 1] < i - 1) {
flag = 0;
break;
}
}
if (flag) {
if (a[n / 2] >= n / 2 && a[n / 2 + 1] >= n / 2 - 1)
flag = 1;
else if (a[n / 2] >= n / 2 - 1 && a[n / 2 + 1] >= n / 2)
flag = 1;
else
flag = 0;
}
}
if (flag)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[300005];
int main() {
ios::sync_with_stdio(false);
int t, n, up = 0, flag = 1;
cin >> t;
for (int o = 0; o < t; o++) {
up = -1, flag = 1;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
if (n == 1) {
cout << "Yes" << endl;
continue;
}
if (n % 2 == 0) {
for (int i = 0; i < n / 2 - 1; i++) {
if (arr[i] < i || arr[n - 1 - i] < i) {
flag = 0;
break;
}
}
if (arr[n / 2 - 1] < n / 2 - 1 || arr[n / 2] < n / 2 - 1) {
flag = 0;
}
if (arr[n / 2 - 1] == n / 2 - 1 && arr[n / 2] == n / 2 - 1) {
flag = 0;
}
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
} else {
for (int i = 0; i <= n / 2; i++) {
if (arr[i] < i || arr[n - 1 - i] < i) {
flag = 0;
break;
}
}
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
return 0;
}
|
#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, decreasing_index = -1, increasing_index = n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 0; i < n; i++) {
if (v[i] < i) break;
decreasing_index = i;
}
for (int i = n - 1; i >= 0; i--) {
if (v[i] < (n - i - 1)) break;
increasing_index = i;
}
if (increasing_index <= decreasing_index)
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(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 prefix = -1, suffix = n;
for (int i = 0; i < n; i++) {
if (v[i] < i) {
break;
}
prefix = i;
}
for (int i = n - 1; i >= 0; i--) {
if (v[i] < (n - 1) - i) {
break;
}
suffix = i;
}
if (suffix <= prefix)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5, mod = 1e9 + 7, bit = 60;
signed main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n;
long long int i;
cin >> n;
long long int a[n], b[n];
for (i = 0; i < n; i++) {
cin >> a[i];
b[i] = -1;
}
long long int c = 0;
for (i = 0; i < n; i++) {
if (a[i] < c) {
break;
}
b[i] = c++;
}
bool pos = 0;
if (i == n) {
pos = 1;
}
c = 0;
for (i = n - 1; i >= 0; i--) {
if (a[i] < c) {
break;
}
if (i == 0 or (b[i - 1] != -1 and b[i - 1] != c)) {
pos = 1;
}
b[i] = c++;
}
if (pos) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, a[300005], l[300005], r[300005];
void solve() {
cin >> n;
for (__typeof((n)) i = (0); i < (n); i++) cin >> a[i];
for (__typeof((n)) i = (0); i < (n); i++)
l[i] = a[i] >= i, l[i] += (i != 0) * l[i - 1];
r[n] = 0;
for (__typeof((n - 1)) i = (n - 1); i >= (0); i--)
r[i] = a[i] >= n - 1 - i, r[i] += r[i + 1];
for (__typeof((n)) i = (0); i < (n); i++) {
if (l[i] == i + 1 && r[i] == n - i) {
cout << "Yes"
<< "\n";
return;
};
}
{
cout << "No"
<< "\n";
return;
};
}
void prep() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t = 1;
cin >> t;
prep();
cout << fixed << setprecision(12);
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, mod = 1e9 + 7;
int a[N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int l = n, r = 1;
for (int i = 1; i <= n; i++) {
if (a[i] < i - 1) {
l = i - 1;
break;
}
}
int c = 0;
for (int i = n; i >= 1; i--) {
if (a[i] < c++) {
r = i + 1;
break;
}
}
if (l >= r)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int A[300005];
signed main() {
int t;
scanf("%d", &(t));
int n;
while (t--) {
scanf("%d", &(n));
for (int i = 0; i < n; i++) scanf("%d", &(A[i]));
bool flag = 1;
for (int i = 0; i < n; i++) {
if (A[i] < i && A[i] < n - 1 - i) {
puts("No");
flag = 0;
break;
}
}
if (!flag) continue;
bool g = 0;
for (int i = 0; i < n; i++) {
if (g == 0 && A[i] < i && A[i] >= n - 1 - i) {
g = 1;
if (A[i - 1] <= n - 1 - i) {
puts("No");
flag = 0;
break;
}
} else if (g && A[i] < n - 1 - i) {
puts("No");
flag = 0;
break;
}
}
if (flag) {
puts("Yes");
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 9;
long long n, i, t, j, a[maxn], pivot1, pivot2, b;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while (t--) {
b = 0;
cin >> n;
pivot2 = 0;
pivot1 = n + 1;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) {
if (a[i] >= i - 1)
pivot2++;
else
break;
}
for (i = n; i >= 1; i--) {
if (a[i] >= b) {
pivot1--;
b++;
} else
break;
}
if (pivot2 >= pivot1)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
namespace IO {
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin.exceptions(cin.failbit);
if (s.size()) {
setIn(s + ".inp");
setOut(s + ".out");
} else {
}
}
} // namespace IO
using namespace IO;
namespace Function {
template <typename T1, typename T2>
void amax(T1 &a, T2 b) {
if (typeid(a).name() == typeid(int).name() &&
typeid(b).name() == typeid(long long).name()) {
cout << "Error on amax";
exit(0);
}
if (a < b) a = b;
}
template <typename T1, typename T2>
void amin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <typename T>
void compress(vector<T> &a) {
sort(a.begin(), a.end());
a.resize(unique(a.begin(), a.end()) - a.begin());
}
template <typename T>
long long sqr(T x) {
return 1LL * x * x;
}
template <typename T1, typename T2>
long long gcd(T1 a, T2 b) {
return (b == 0 ? a : gcd(b, a % b));
}
template <typename T1, typename T2>
long long lcm(T1 a, T2 b) {
return 1LL * a / gcd(a, b) * b;
}
} // namespace Function
using namespace Function;
namespace Output {
void print(int x) { cout << x << "\n"; }
void print(unsigned int x) { cout << x << "\n"; }
void print(long unsigned int x) { cout << x << "\n"; }
void print(long long x) { cout << x << "\n"; }
void print(unsigned long long x) { cout << x << "\n"; }
void print(float x) { cout << x << "\n"; }
void print(double x) { cout << x << "\n"; }
void print(long double x) { cout << x << "\n"; }
void print(char x) { cout << x << "\n"; }
void print(const char *x) { cout << x << "\n"; }
void print(string x) { cout << x << "\n"; }
void print(bool x) { cout << x << "\n"; }
template <class T, class... Ts>
void print(T t, Ts... ts) {
cout << t << " ";
print(ts...);
}
template <typename T1, typename T2>
void print(pair<T1, T2> a) {
print(a.first, a.second);
}
template <typename T>
void print(T a) {
for (auto it : a) {
print(it);
}
}
template <class T, class... Ts>
void prine(T t, Ts... ts) {
print(t, ts...);
exit(0);
}
} // namespace Output
using namespace Output;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int INF = 1e9;
const long long INFL = 1e18;
const int MOD = 1e9 + 7;
const int N = 3e5 + 10;
bool F[N], G[N];
int a[N];
int main() {
setIO();
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
F[i] = G[i] = 0;
}
G[n] = 1;
a[n] = -1;
for (int i = 0; i < n; i++) {
F[i] = (i == 0 ? 1 : F[i - 1]);
F[i] &= (a[i] >= i);
}
for (int i = n - 1; i >= 0; i--) {
G[i] = G[i + 1];
G[i] &= (a[i] >= n - i - 1);
}
bool ok = 0;
for (int i = 0; i < n; i++) {
if (F[i] && G[i + 1] && a[i] > n - i - 2) {
ok = 1;
break;
}
}
print(ok ? "Yes" : "No");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void fun(long long int n, long long int* arr) {
int i = 0;
int j = n - 1;
int index = 0;
while (i <= j) {
if (arr[i] < index || arr[j] < index) {
cout << "No" << endl;
return;
}
index++;
i++;
j--;
}
if (n % 2 != 0)
cout << "Yes" << endl;
else {
int pos = n / 2 - 1;
if (arr[pos] > pos || arr[pos + 1] > pos) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
for (long long int i = 0; i < t; i++) {
long long int n;
cin >> n;
long long int arr[n];
for (long long int i = 0; i < n; i++) cin >> arr[i];
if (n == 1)
cout << "Yes" << endl;
else
fun(n, arr);
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
void solve() {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
for (long long i = 0; i < n / 2; i++) {
if (a[i] < i) {
cout << "NO" << '\n';
return;
}
}
for (long long i = n / 2; i < n; i++) {
if (a[i] < n - 1 - i) {
cout << "NO" << '\n';
return;
}
}
if (n % 2 == 0) {
if (a[n / 2 - 1] > n / 2 - 1 || a[n / 2] >= n / 2) {
cout << "YES" << '\n';
return;
}
cout << "NO" << '\n';
return;
}
cout << "YES" << '\n';
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long TESTS = 1;
cin >> TESTS;
while (TESTS--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for (int k = 0; k < t; k++) {
int n;
cin >> n;
vector<int> a(n);
vector<bool> lofit(n);
vector<bool> hifit(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
lofit[i] = (a[i] >= i);
if (i > 0) lofit[i] = lofit[i] && lofit[i - 1];
}
for (int i = n - 1; i >= 0; i--) {
hifit[i] = (a[i] >= n - 1 - i);
if (i < n - 1) hifit[i] = hifit[i] && hifit[i + 1];
}
bool success = false;
for (int i = 0; i < n; i++) {
if (lofit[i] && hifit[i]) {
success = true;
break;
}
}
if (success)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int count = 1;
for (int i = 0; i < n; i++) {
if (arr[i] < min(i, n - 1 - i)) {
count = 0;
break;
}
}
if (n % 2 == 0) {
if ((arr[n / 2] == (n / 2) - 1) && (arr[(n / 2) - 1] == arr[n / 2])) {
count = 0;
}
}
if (count == 0) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int a[N];
int main() {
int t;
cin >> t;
while (t--) {
int n, fl = 0, vis = -1, up = 1;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (fl == 0) {
if ((a[i] < i)) {
up = 0;
if (vis == n - 1 - i) fl = 1;
}
if (up == 1) {
if (a[i] < i) fl = 1;
} else {
if (a[i] < n - 1 - i) fl = 1;
}
}
vis = a[i];
}
if (n == 1)
puts("YES");
else {
if (fl == 0)
puts("YES");
else
puts("NO");
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n], i;
for (i = 0; i < n; ++i) cin >> a[i];
for (i = 0; i < n; ++i) {
if (a[i] < i) break;
}
if (a[i] == a[i - 1] && a[i - 1] == i - 1) --a[i];
for (; i < n; ++i) {
if (a[i] < (n - 1 - i)) break;
}
if (i == n)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
bool a1[n];
bool a2[n];
for (int i = 0; i < n; ++i) {
a1[i] = (i != 0 ? a1[i - 1] : true) && a[i] >= i;
}
for (int i = n - 1; i >= 0; --i) {
a2[i] = (i != n - 1 ? a2[i + 1] : true) && a[i] >= (n - i - 1);
}
bool found = false;
for (int i = 0; i < n; ++i) {
if (a1[i] && a2[i]) {
found = true;
break;
}
}
if (found)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
int exp(int x, int y, int p) {
int res = 1;
while (y) {
if (y % 2) res = (res * x % p) % p;
x = (x * x) % p;
y /= 2;
}
return res;
}
int expo(int x, int y) {
int res = 1;
while (y) {
if (y % 2) res = (res * x % ((int)1e9 + 7)) % ((int)1e9 + 7);
x = (x * x) % ((int)1e9 + 7);
y /= 2;
}
return res;
}
long long add(long long a, long long b) {
return (a % ((int)1e9 + 7) + b % ((int)1e9 + 7) + ((int)1e9 + 7)) %
((int)1e9 + 7);
}
int sub(int a, int b) {
return (a % ((int)1e9 + 7) - b % ((int)1e9 + 7) + ((int)1e9 + 7)) %
((int)1e9 + 7);
}
long long mul(long long a, long long b) {
return ((a % ((int)1e9 + 7)) * (b % ((int)1e9 + 7)) + ((int)1e9 + 7)) %
((int)1e9 + 7);
}
int inv(int x) { return expo(x, ((int)1e9 + 7) - 2); }
using namespace std;
long long Ceil(long long a, long long b) { return ((a / b) + (a % b != 0)); }
int main() {
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
bool flag = true;
vector<long long> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
for (int i = 2; i <= n; i++) {
if (v[i] < i - 1 && v[i] < n - i) {
flag = false;
}
if (v[i] == n - i && v[i] == v[i - 1] && v[i] < i - 1) {
flag = false;
}
}
if (flag)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n + 1];
for (long long i = 1; i <= n; i++) {
cin >> a[i];
}
long long startSeKhaTak = -1;
long long endSeKhaTak = n + 1;
long long i;
for (i = 1; i <= n; i++) {
if (a[i] < (i - 1)) {
break;
}
startSeKhaTak = i;
}
for (i = n; i >= 1; i--) {
if (a[i] < (n - i)) {
break;
}
endSeKhaTak = i;
}
if (endSeKhaTak <= startSeKhaTak) {
cout << "Yes\n";
} else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[300300];
int main() {
int n, i, j, x, y, k, ans, curr, temp, m;
int tc;
cin >> tc;
while (tc--) {
cin >> n;
for (i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
}
bool can = 0;
curr = 0;
for (i = 1; i <= n; i++) {
if (arr[i] >= i - 1) curr++;
}
if (curr == n) can = 1;
curr = 0;
for (i = n; i > 0; i--) {
if (arr[i] >= n - i) curr++;
}
if (curr == n) can = 1;
int maxiL = 0;
for (i = 1; i <= n; i++) {
if (arr[i] < i - 1) {
maxiL = i - 1;
break;
}
}
int maxiR = 0;
int now = 0;
for (i = n; i > 0; i--) {
if (arr[i] < now) {
maxiR = i + 1;
break;
}
now++;
}
if (maxiL >= maxiR) can = 1;
if (can)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 300100;
int arr[N];
#pragma warning(disable : 6031)
#pragma warning(disable : 4996)
int t, n;
bool c1[N], c2[N];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
bool f1 = 1, f2 = 1;
bool f3 = 1;
for (int i = 1; i <= n; i++) scanf("%d", arr + i);
memset(c1, 0, sizeof c1);
memset(c2, 0, sizeof c2);
c1[1] = 1;
for (int i = 2; i <= n; i++) {
if (c1[i - 1] && arr[i] >= i - 1) {
c1[i] = 1;
} else {
break;
}
}
c2[n] = 1;
for (int i = n - 1; i >= 1; i--) {
if (c2[i + 1] && arr[i] >= n - i) {
c2[i] = 1;
} else
break;
}
f1 = c1[n];
f2 = c2[1];
f3 = 0;
for (int i = 1; i <= n; i++) {
if (c1[i] && c2[i]) {
f3 = 1;
}
}
if (f1 || f2 || f3)
puts("Yes");
else
puts("No");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
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 i;
bool poss = 1;
for (i = 0; i < n; i++)
if (v[i] < i) break;
i--;
for (int j = i; j < n - 1; j++) {
if (v[j + 1] >= v[j]) v[j + 1] = v[j] - 1;
if (v[j + 1] < 0) {
poss = 0;
break;
}
}
if (poss)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using vl = vector<ll>;
using pll = pair<ll, ll>;
ll mod = 1000000007;
mt19937_64 rng(0xDEADBEEF);
string alpha = []() {
string ans;
for (char c = 'a'; c <= 'z'; c++) ans.push_back(c);
return ans;
}();
template <typename T1>
istream& operator>>(istream& c, vector<T1>& v) {
for (auto& i1 : v) c >> i1;
return c;
}
template <typename T1, typename T2>
istream& operator>>(istream& c, pair<T1, T2>& p) {
c >> p.first >> p.second;
return c;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2> p) {
return c << p.first << ' ' << p.second;
}
template <typename T1>
ostream& operator<<(ostream& c, const vector<T1>& v) {
for (auto& i1 : v) c << i1 << ' ';
return c;
}
template <typename T1>
ostream& operator<<(ostream& c, const set<T1>& v) {
for (auto& i1 : v) c << i1 << ' ';
return c;
}
template <typename T1>
void print(const vector<T1>& v) {
for (auto& i1 : v) cout << i1 << endl;
}
class TIn {};
const TIn vIn;
template <typename T1>
struct TInContainer {
T1 Value;
};
template <typename T1>
TInContainer<T1> operator>>(const T1& value, const TIn vIn) {
return {value};
}
template <typename T1>
bool operator>>(const TInContainer<T1>& e, const set<T1>& v) {
return v.find(e.Value) != v.end();
}
template <typename T1>
bool operator>>(const TInContainer<T1>& e, const vector<T1>& v) {
return find(v.begin(), v.end(), e.Value) != v.end();
}
template <typename T1>
bool operator>>(const TInContainer<T1>& e, const multiset<T1>& v) {
return v.find(e.Value) != v.end();
}
template <typename T1, typename T2>
bool operator>>(const TInContainer<T1>& e, const map<T1, T2>& v) {
return v.find(e.Value) != v.end();
}
template <typename T1, typename T2>
bool operator>>(const TInContainer<T1>& e, const multimap<T1, T2>& v) {
return v.find(e.Value) != v.end();
}
template <typename T1>
bool operator>>(const TInContainer<T1>& e, const pair<T1, T1>& v) {
return !(e.Value < v.first || v.second < e.Value);
}
template <typename T1>
ll operator+(const vector<T1>& v) {
return v.size();
}
template <typename T1>
ll operator+(const set<T1>& v) {
return v.size();
}
template <typename T1>
ll operator+(const multiset<T1>& v) {
return v.size();
}
template <typename T1, typename T2>
ll operator+(const map<T1, T2>& v) {
return v.size();
}
template <typename T1, typename T2>
ll operator+(const multimap<T1, T2>& v) {
return v.size();
}
template <typename T1>
ll operator+(const queue<T1>& v) {
return v.size();
}
template <typename T1>
ll operator+(const priority_queue<T1>& v) {
return v.size();
}
ll operator+(const string& v) { return v.size(); }
template <typename T1, typename T2>
void operator+=(set<T1>& c, const T2& v) {
c.insert(v);
}
template <typename T1, typename T2>
void operator+=(multiset<T1>& c, const T2& v) {
c.insert(v);
}
template <typename T1, typename T2, typename T3>
void operator+=(multimap<T1, T2>& c, const T3& v) {
c.insert(v);
}
template <typename T1, typename T2>
void operator+=(vector<T1>& c, const T2& v) {
c.push_back(v);
}
template <typename T1, typename T2>
void operator+=(queue<T1>& c, const T2& v) {
c.push(v);
}
template <typename T1, typename T2>
void operator+=(priority_queue<T1>& c, const T2& v) {
c.push(v);
}
template <typename T1, typename T2>
void operator-=(set<T1>& c, const T2& v) {
c.erase(v);
}
template <typename T1, typename T2>
void operator-=(multiset<T1>& c, const T2& v) {
c.erase(c.find(v));
}
template <typename T1, typename T2, typename T3>
void operator-=(map<T1, T2>& c, const T3& v) {
c.erase(v);
}
template <typename T1, typename T2, typename T3>
void operator-=(multimap<T1, T2>& c, const T3& v) {
c.erase(c.find(v));
}
template <typename T1>
T1 operator--(set<T1>& c) {
T1 ans = *c.begin();
c.erase(c.begin());
return ans;
}
template <typename T1>
T1 operator--(multiset<T1>& c) {
T1 ans = *c.begin();
c.erase(c.begin());
return ans;
}
template <typename T1>
T1 operator--(vector<T1>& c) {
T1 ans = c.back();
c.pop_back();
return ans;
}
char operator--(string& c) {
char ans = c.back();
c.pop_back();
return ans;
}
template <typename T1>
T1 operator--(queue<T1>& c) {
T1 ans = c.front();
c.pop();
return ans;
}
template <typename T1>
T1 operator--(priority_queue<T1>& c) {
T1 ans = c.top();
c.pop();
return ans;
}
template <typename T1, typename T2>
ll operator/(const T1& v, T2& c) {
return count(c.begin(), c.end(), v);
}
template <typename T1, typename T2>
void operator^=(set<T1>& c, const T2& v) {
if (c.find(v) != c.end())
c.erase(v);
else
c.insert(v);
}
template <typename T1>
void operator<<=(map<T1, ll>& m, const vector<T1>& v) {
for (auto& i1 : v) m[i1]++;
}
void operator<<=(map<char, ll>& m, const string& v) {
for (auto& i1 : v) m[i1]++;
}
template <typename T1, typename T2>
void operator<<=(map<T1, T2>& m, const vector<pair<T1, T2>>& v) {
for (auto& i1 : v) m[i1.first] = i1.second;
}
template <typename T1>
void operator<<=(set<T1>& s, const vector<T1>& v) {
for (auto& i1 : v) s.insert(i1);
}
template <typename T1>
void operator<<=(multiset<T1>& s, const vector<T1>& v) {
for (auto& i1 : v) s.insert(i1);
}
void operator<<=(set<char>& s, const string& v) {
for (auto& i1 : v) s.insert(i1);
}
template <typename T1>
T1 sum(const vector<T1>& v) {
return accumulate(v.begin(), v.end(), T1{});
}
template <typename T1>
T1 max(const vector<T1>& v) {
return *max_element(v.begin(), v.end());
}
template <typename T1>
T1 min(const vector<T1>& v) {
return *min_element(v.begin(), v.end());
}
template <typename T1>
void sort(vector<T1>& v) {
sort(v.begin(), v.end());
}
template <typename T1>
void reverse(vector<T1>& v) {
reverse(v.begin(), v.end());
}
void reverse(string& a) { reverse(a.begin(), a.end()); }
void sort(string& a) { sort(a.begin(), a.end()); }
template <typename T1>
vector<T1> sorted(vector<T1> v) {
sort(v.begin(), v.end());
return move(v);
}
template <typename T1>
vector<T1> reversed(vector<T1> v) {
reverse(v.begin(), v.end());
return move(v);
}
string reversed(string a) {
reverse(a.begin(), a.end());
return move(a);
}
string sorted(string a) {
sort(a.begin(), a.end());
return move(a);
}
template <typename T1>
T1 max(const pair<T1, T1>& v) {
return max(v.first, v.second);
}
template <typename T1>
T1 min(const pair<T1, T1>& v) {
return min(v.first, v.second);
}
template <typename T1>
void sort(pair<T1, T1>& v) {
if (v.second < v.first) swap(v.first, v.second);
}
template <typename T1>
pair<T1, T1> sorted(pair<T1, T1> v) {
if (v.second < v.first) swap(v.first, v.second);
return move(v);
}
template <typename T1, typename T2>
vector<pair<T2, T1>> swapped(const map<T1, T2>& mp) {
vector<pair<T2, T1>> ans;
for (auto& i1 : mp) ans.push_back({i1.second, i1.first});
return move(ans);
}
namespace geom {
pll operator+(pll a, pll b) { return {a.first + b.first, a.second + b.second}; }
pll operator-(pll a, pll b) { return {a.first - b.first, a.second - b.second}; }
pll operator-(pll a) { return {-a.first, -a.second}; }
pll operator*(pll a) { return {-a.second, a.first}; }
pll operator~(pll a) { return {a.second, a.first}; }
pll operator++(pll& a) {
pll ans = a;
a.first++;
a.second++;
return ans;
}
pll operator--(pll& a) {
pll ans = a;
a.first--;
a.second--;
return ans;
}
ll operator*(pll a, pll b) { return a.first * b.first + a.second * b.second; }
ll operator+(pll a) { return a.first * a.first + a.second * a.second; }
ll abs(pll a) { return std::abs(a.first) + std::abs(a.second); }
pll sum(const vector<pll>& v) {
using namespace geom;
pll ans{};
for (auto e : v) ans = ans + e;
return ans;
}
void operator+=(pll& a, pll b) { a = a + b; }
void operator-=(pll& a, pll b) { a = a - b; }
pll operator*(ll a, pll p) { return {p.first * a, p.second * a}; }
void operator*=(pll p, ll a) {
p.first *= a;
p.second *= a;
}
} // namespace geom
using vpll = vector<pll>;
using mll = map<ll, ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using md = double;
template <typename T1>
class asc_queue : public priority_queue<T1, vector<T1>, greater<T1>> {};
template <typename T1>
class desc_queue : public priority_queue<T1> {};
template <typename T1>
string tostring(T1 a) {
stringstream ss;
ss << a;
return ss.str();
}
namespace algo {
template <typename T1>
T1 binpow_mod(T1 a, ll b, ll c = mod) {
if (b == 1) return a;
if (b & 1) return binpow_mod(a, b - 1, c) * a % c;
T1 res = binpow_mod(a, b >> 1, c);
return res * res % c;
}
template <typename T1>
T1 binpow(T1 a, ll b) {
if (b == 1) return a;
if (b & 1) return binpow(a, b - 1) * a;
T1 res = binpow(a, b >> 1);
return res * res;
}
class dsu {
vl v;
ll Sz;
public:
dsu(ll sz) : v(sz), Sz(sz) {
for (ll i = 0, iend = ll(sz); i < iend; i++) v[i] = i;
}
ll get(ll i) {
if (i == v[i]) return v[i];
return v[i] = get(v[i]);
}
ll operator[](ll i) { return get(i); }
void join(ll a, ll b) {
if (get(a) == get(b)) return;
Sz--;
if (rng() % 2) swap(a, b);
v[get(a)] = get(b);
}
ll size() const { return Sz; }
};
ll gcd(ll a, ll b) {
while (a) tie(a, b) = pll{b % a, a};
return b;
}
ll gcdv(vl& v) { return accumulate(v.begin(), v.end(), v.front(), gcd); }
union mask_t {
uint64_t i;
bitset<64> b;
mask_t(ll q) { i = q; }
mask_t(bitset<64> q) { b = q; }
};
vector<bool> eratosphen(ll mx) {
if (mx == 0) return {1};
vector<bool> ans(mx + 1);
ans[0] = 1;
ans[1] = 1;
for (ll i = 2; i <= mx; i++) {
if (ans[i]) continue;
for (ll j = i + i; j <= mx; j += i) ans[j] = 1;
}
return ans;
}
vl primes(ll n) {
auto v = eratosphen(n);
vl ans;
for (ll i = 0, iend = ll(v.size()); i < iend; i++)
if (!v[i]) ans += i;
return ans;
}
template <typename T1>
vector<T1> prefixsum(vector<T1> v) {
vector<T1> ans(1);
for (auto& i1 : v) ans += ans.back() + i1;
return move(ans);
}
template <typename T1>
vector<T1> suffixsum(vector<T1> v) {
return reversed(prefixsum(reversed(v)));
}
template <typename T1>
T1 merge(const T1& a, const T1& b) {
T1 ans(a.size() + b.size());
merge(a.begin(), a.end(), b.begin(), b.end(), ans.begin());
return move(ans);
}
pll exgcd(pll a) {
if (a.first == 0) {
if (a.second == 1)
return {0, 1};
else
return {0, 0};
}
pll val = exgcd({a.second % a.first, a.first});
return {val.second - (a.second / a.first) * val.first, val.first};
}
template <typename T1>
vl kmp(T1& v) {
vl ans(+v);
ll j = 0;
for (ll i = 0, iend = ll(+v); i < iend; i++) {
while (j != 0 && v[i] != v[j]) j = ans[j - 1];
if (v[j] == v[i] && j < i) j++;
ans[i] = j;
}
return ans;
}
} // namespace algo
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout.sync_with_stdio(0);
cout.tie(0);
using namespace geom;
ll q;
cin >> q;
for (ll j = 0, jend = ll(q); j < jend; j++) {
ll n;
cin >> n;
vl v(n);
cin >> v;
vl can_be_left, can_be_right;
for (ll i = 0, iend = ll(n); i < iend; i++) {
can_be_left += v[i] >= i;
can_be_right += v[i] >= n - 1 - i;
}
for (ll i = 0, iend = ll(n - 1); i < iend; i++) {
can_be_left[i + 1] *= can_be_left[i];
can_be_right[n - 1 - i - 1] *= can_be_right[n - 1 - i];
}
ll ok = 0;
for (ll i = 0, iend = ll(n); i < iend; i++) {
if (can_be_left[i] && can_be_right[i]) {
ok = 1;
}
}
cout << (ok ? "Yes" : "No") << endl;
}
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 = 1000000007) {
long long int result = 1;
for (;;) {
if (b & 1) result = (result * a) % M;
b >>= 1;
if (!b) break;
a = (a * a) % M;
}
return result;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int t;
cin >> t;
while (t--) {
int n, i, c = 0, cc = 0;
cin >> n;
long long int a[n];
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) {
if (a[i] >= c)
c++;
else
break;
}
for (i = n - 1; i >= 0; i--) {
if (a[i] >= cc)
cc++;
else
break;
}
if ((c + cc) > n)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
vector<int> a(n);
vector<int> pr(n);
vector<int> sf(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
pr[0] = 0;
sf.back() = 0;
for (int i = 1; i < n; ++i) {
if (a[i] > pr[i - 1]) {
pr[i] = pr[i - 1] + 1;
} else
pr[i] = 1e9;
}
for (int i = n - 2; i > -1; --i) {
if (a[i] > sf[i + 1]) {
sf[i] = sf[i + 1] + 1;
} else
sf[i] = 1e9;
}
bool found = false;
for (int i = 0; i < n; ++i) {
bool flag = true;
if (i - 1 >= 0) {
if (a[i] <= pr[i - 1]) flag = false;
}
if (i + 1 < n) {
if (a[i] <= sf[i + 1]) flag = false;
}
if (flag) found = true;
}
cout << (found ? "Yes\n" : "No\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
template <class T1>
void deb(T1 e1) {
cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
<< endl;
}
template <class T>
T gcd(const T a, const T b) {
return (b ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(const T a, const T b) {
return (a / gcd<T>(a, b) * b);
}
struct node {
long long x, y;
node() {}
node(long long x, long long y) : x(x), y(y) {}
bool operator<(const node& p) const { return x < p.x; }
};
long long a[300006], b[300005], c[300005];
int main() {
long long i, j, k, l, t, n, m, l1, l2, x, y, z;
scanf("%lld", &t);
while (t--) {
scanf("%lld", &n);
l1 = -1;
bool ck = 0;
for (i = 0; i < n; i++) {
scanf("%lld", &a[i]);
if (!ck && a[i] >= i) {
l1++;
} else
ck = 1;
}
ck = 0;
l2 = n;
for (i = n - 1, j = 0; i >= 0; i--, j++) {
if (!ck && a[i] >= j) {
l2--;
} else
ck = 1;
}
if (l1 >= l2) {
deb("Yes");
} else if (abs(l2 - l1) == 1 && (a[l1] > l2 || a[l2] > l1)) {
deb("Yes");
} else if (abs(l2 - l1) == 2 && a[l1 + 1] > l1 && a[l1 + 1] > l2) {
deb("Yes");
} else
deb("No");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[500001];
long long n, t, ans, inc, lft, rt;
int main() {
scanf("%lld", &t);
while (t--) {
scanf("%lld", &n);
inc = 0;
for (int i = 0; i < n; i++) cin >> a[i];
if (n == 2) {
if (!a[0] && !a[1]) {
printf("No\n");
continue;
}
}
for (int i = 0; i < n; i++) {
if (a[i] >= inc) {
inc++;
lft = i;
} else
break;
}
inc = 0;
for (int i = n - 1; i >= 0; i--) {
if (a[i] >= inc) {
inc++;
rt = i;
} else
break;
}
if (lft < rt)
printf("No\n");
else
printf("Yes\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long t, x, n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> t;
while (t--) {
vector<long long> v;
cin >> x;
for (long long i = 0; i < x; i++) {
cin >> n;
v.push_back(n);
}
vector<long long> tmp = v;
v[0] = 0;
long long now = 1;
while ((v[now - 1] + 1) <= v[now] && now < v.size()) {
v[now] = v[now - 1] + 1;
now++;
}
long long now2 = 1;
reverse(tmp.begin(), tmp.end());
tmp[0] = 0;
while ((tmp[now2 - 1] + 1) <= tmp[now2] && now2 < v.size()) {
tmp[now2] = tmp[now2 - 1] + 1;
now2++;
}
if (now > (x - now2)) {
cout << "Yes"
<< "\n";
} else {
cout << "No"
<< "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[400000];
int main() {
int i, j, k, l, id, n, m, t;
cin >> t;
while (t--) {
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++)
if (a[i] < i - 1) break;
for (j = n; j >= 1; j--)
if (a[j] < n - j) break;
i--;
j++;
if (i >= j)
cout << "YES";
else
cout << "NO";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int solve() {
int n;
cin >> n;
vector<int> v(n);
for (auto &i : v) cin >> i;
int x = -1;
int y = n;
for (int i = 0; i < n; i++) {
if (v[i] < i) break;
x = i;
}
for (int i = n - 1; i >= 0; i--) {
if (v[i] < n - i - 1) break;
y = i;
}
if (y <= x) return 1;
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
if (solve())
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;
int indx = -1;
long long miny = 1e9;
int minIndx = -1;
int flag1 = 0;
long long* arr = new long long[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int prefixEnd = -1, suffixEnd = n;
for (int i = 0; i < n; i++) {
if (arr[i] < i) break;
prefixEnd = i;
}
for (int i = n - 1; i >= 0; --i) {
if (arr[i] < (n - 1) - i) break;
suffixEnd = i;
}
if (suffixEnd <= prefixEnd)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[300005], n;
bool ch1() {
for (int i = 0; i < n; i++) {
if (a[i] < i) return 0;
}
return 1;
}
bool ch2() {
for (int i = 0; i < n; i++) {
if (a[i] < n - 1 - i) return 0;
}
return 1;
}
bool ch3() {
int pos = 0;
for (; pos < n; pos++) {
if (a[pos] < pos) break;
}
pos--;
int pos1 = n - 1;
for (; pos1 >= 0; pos1--) {
if (a[pos1] < n - 1 - pos1) break;
}
pos1++;
return pos >= pos1;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (ch1() || ch2() || ch3())
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int i, j, k, x, y, n, ct = 0, flag = 0;
while (t--) {
flag = 0;
cin >> n;
int a[n];
for (i = 0; i < n; i++) cin >> a[i];
if (n % 2 == 0) {
x = n / 2 - 1;
for (i = 0; i < x; i++) {
if (a[i] >= i && a[n - i - 1] >= i)
continue;
else {
flag = 1;
cout << "No"
<< "\n";
break;
}
}
if (flag == 0) {
if ((a[x] >= i && a[x + 1] >= i + 1) ||
(a[x] >= i + 1 && a[x + 1] >= i))
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
}
} else {
x = n / 2 + 1;
for (i = 0; i < x; i++) {
if (a[i] >= i && a[n - i - 1] >= i)
continue;
else {
flag = 1;
cout << "No"
<< "\n";
break;
}
}
if (flag == 0)
cout << "Yes"
<< "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int in() {
int x;
cin >> x;
return x;
}
long long lin() {
long long x;
cin >> x;
return x;
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline void print(pair<T, T> p) {
cout << "(" << p.first << "," << p.second << ") ";
}
template <class T>
inline void print(vector<pair<T, T>> v) {
for (auto e : v) print(e);
cout << endl;
}
template <class T>
inline void print(T v) {
for (auto e : v) cout << e << " ";
cout << endl;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
for (T& x : vec) is >> x;
return is;
}
const long long mod = 1e9 + 7;
int main() {
long long t;
cin >> t;
for (long long i = 0; i < t; i++) {
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
bool flag = true;
if (n % 2 == 1) {
for (long long i = 0; i < n; i++) {
if (i <= n / 2) {
if (a[i] < i) {
flag = false;
break;
}
} else {
if (a[i] < n - 1 - i) {
flag = false;
break;
}
}
}
} else {
bool flag1 = true;
bool flag2 = true;
for (long long i = 0; i < n; i++) {
if (i <= n / 2) {
if (a[i] < i) {
flag1 = false;
}
if (a[n - 1 - i] < i) {
flag2 = false;
}
} else {
if (a[i] < n - 1 - i) {
flag1 = false;
}
if (a[n - 1 - i] < n - 1 - i) {
flag2 = false;
}
}
}
if (flag1 == false && flag2 == false) {
flag = false;
}
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "O3", "unroll-loops", "omit-frame-pointer", \
"inline")
#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4", "popcnt", "abm", \
"mmx", "avx")
#pragma GCC option("tune = native", "arch = native", "no-zero-upper")
#pragma comment(linker, "/stack:200000000")
using namespace std;
void hype() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
signed main() {
hype();
int t, n;
bool b, ans;
vector<int> v;
cin >> t;
for (size_t o = 0; o < (t); ++o) {
cin >> n;
v.resize(n);
b = true;
ans = true;
for (size_t i = 0; i < (n); ++i) cin >> v[i];
for (size_t i = 0; i < (n); ++i) {
if (b && v[i] < i) {
b = false;
if (v[i - 1] < n - i) {
ans = false;
break;
}
}
if (!b && v[i] < n - i - 1) {
ans = false;
break;
}
}
cout << (ans ? "Yes" : "No") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
const int INF = 1 << 29;
using namespace std;
bool solve(vector<int> v, int n) {
int l = -1, r = n;
for (int i = 0; i < n; i++) {
if (v[i] < i) break;
l = i;
}
for (int j = n - 1; ~j; --j) {
if (v[j] < n - j - 1) break;
r = j;
}
return (r <= l);
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> v(n);
for (int &it : v) cin >> it;
cout << (solve(v, n) ? "YES" : "NO") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[300005], n;
bool ch3() {
int pos = 0;
for (; pos < n; pos++) {
if (a[pos] < pos) break;
}
pos--;
for (; pos < n; pos++) {
if (a[pos] < n - 1 - pos) return 0;
}
return 1;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (ch3())
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
int t, n;
cin >> t;
while (t--) {
cin >> n;
int a[n];
int pos = -1, f = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (n % 2 != 0)
pos = n / 2;
else {
int x = a[n / 2];
int y = a[(n - 1) / 2];
if (x >= y)
pos = n / 2;
else
pos = (n - 1) / 2;
}
for (int i = pos - 1; i >= 0; i--) {
a[i] = (a[i] < a[i + 1] - 1) ? a[i] : a[i + 1] - 1;
if (a[i] < 0) {
f = 1;
break;
}
}
for (int i = pos + 1; i < n; i++) {
a[i] = (a[i] < a[i - 1] - 1) ? a[i] : a[i - 1] - 1;
if (a[i] < 0) {
f = 1;
break;
}
}
if (f == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int s[maxn];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
int l = 1, r = n;
while (s[l] >= l - 1) l++;
while (s[r] >= n - r) r--;
if (l - 1 >= r + 1)
printf("YES\n");
else
printf("NO\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e5 + 5;
int a[MAX_N];
int main() {
int t;
cin >> t;
while (t--) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int l = n, r = 1;
for (int i = 1; i <= n; i++) {
if (a[i] < i - 1) {
l = i - 1;
break;
}
}
for (int i = n; i >= 1; i--) {
if (a[i] < n - i) {
r = i + 1;
break;
}
}
if (l >= r)
puts("YES");
else
puts("NO");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
long long int powe(long long int n, long long int m) {
if (m == 0) return 1;
long long int t = powe(n, m / 2);
if (m % 2 == 0) return (t * t);
return (((t * t)) * n);
}
long long int mpowe(long long int n, long long int m) {
if (m == 0) return 1;
long long int t = powe(n, m / 2);
t %= 1000000000000000007;
if (m % 2 == 0) return (t * t) % 1000000000000000007;
return (((t * t) % 1000000000000000007) * n) % 1000000000000000007;
}
long long int logtwo(long long int n) {
if (n == 1) return 0;
return logtwo(n / 2) + 1;
}
long long int binpow(long long int a, long long int b, long long int m) {
a %= m;
long long int res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
long long int A[100005];
void solve() {
long long int n, pos = -1, i, lpos, p = 0;
cin >> n;
lpos = n;
long long int a[n];
for (long long int i = 0; i < n; i++) cin >> a[i];
;
for (i = 0; i < n; i++) {
if (a[i] < i) break;
pos = i;
}
for (i = n - 1; i >= 0; i--) {
if (a[i] < (n - 1 - i)) break;
lpos = i;
}
if (lpos <= pos)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t;
cin >> t;
while (t--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
int t;
int n, a[300010];
bool flag, mark[2][300010];
int main() {
cin >> t;
while (t--) {
memset(mark, 0, sizeof(mark));
flag = 0;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
if (a[i] >= i - 1) {
mark[0][i] = 1;
} else {
break;
}
}
for (int i = n; i >= 1; i--) {
if (a[i] >= n - i) {
mark[1][i] = 1;
} else {
break;
}
}
for (int i = 1; i <= n; i++) {
if (mark[0][i] && mark[1][i]) {
flag = 1;
break;
}
}
if (flag)
puts("Yes");
else
puts("No");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int a[300300];
int se() {
for (int i = 1; i < n; i++) {
if (a[i] < i) {
return i - 1;
}
}
return n - 1;
}
int es() {
for (int i = n - 2; i >= 0; i--) {
if (a[i] < n - i - 1) {
return i + 1;
}
}
return 0;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
if (se() >= es()) {
printf("Yes\n");
} else {
printf("No\n");
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int a[N], b[N], c[N], d[N];
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
int u = n / 2;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (n % 2 != 0) {
if (i <= n / 2) {
b[i] = i;
} else {
u--;
b[i] = u;
}
}
}
int j = 0, jj = 0, l = n - 1;
for (int i = 0; i < n; i++) {
if (n % 2 == 0) {
if (i <= n / 2) {
d[i] = i;
} else {
d[l] = j;
l--;
j++;
}
}
}
u = n / 2;
j = 0, jj = 0;
for (int i = n - 1; i >= 0; i--) {
if (n % 2 == 0) {
if (i >= n / 2 - 1) {
c[i] = j;
j++;
} else {
c[jj] = jj;
jj++;
}
}
}
int fl = 0, f = 0;
if (n % 2 != 0) {
fl = 0;
for (int i = 0; i < n; i++) {
if (a[i] < b[i]) {
fl = 1;
break;
}
}
if (fl == 1)
puts("No");
else {
puts("Yes");
}
} else {
fl = 0, f = 0;
for (int i = 0; i < n; i++) {
if (a[i] < d[i]) {
fl = 1;
break;
}
}
for (int i = 0; i < n; i++) {
if (a[i] < c[i]) {
f = 1;
break;
}
}
if (fl == 1 && f == 1)
puts("No");
else {
puts("Yes");
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int a[N];
int main() {
int t, n;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
bool vis[4] = {0};
int maxn = 0, p = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
int d = a[i] - a[i - 1];
if (i > 1) {
if (d > 0)
vis[1] = 1;
else if (d < 0)
vis[2] = 1;
else
vis[0] = 1;
}
}
if ((vis[1] && !vis[2] || !vis[1] && vis[2]) && !vis[0])
cout << "YES" << endl;
else if ((!vis[1] && !vis[2]) && vis[0]) {
if (n % 2 == 0) {
if (a[1] >= n / 2)
cout << "YES" << endl;
else
cout << "NO" << endl;
} else {
if (a[1] >= (n - 1) / 2)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
} else {
int ff = 0;
if (n % 2 == 0) {
if (a[n / 2] == a[n / 2 + 1]) a[n / 2]--;
}
for (int i = 1; i <= n; i++) {
if (a[i] < min(i - 1, n - i)) ff = 1;
}
if (ff)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
int a[300005];
int main() {
int N, n, i, no;
scanf("%d", &N);
while (N--) {
no = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = 0; i < n; i++) {
if (a[i] < i) break;
}
if (i <= n - 1) {
if (n % 2 == 0 && n / 2 == i && a[i] == a[i - 1])
no = 1;
else {
for (; i < n; i++) {
if (a[i] < n - 1 - i) {
no = 1;
break;
}
}
}
}
if (no)
printf("No\n");
else
printf("Yes\n");
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pi>;
using si = set<int>;
using sl = set<ll>;
using qi = queue<int>;
using ql = queue<ll>;
template <class T>
bool uin(T& a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T& a, T b) {
return a < b ? (a = b, true) : false;
}
template <class T>
bool uin(T& u, T& v, T a, T b) {
return v - u > b - a ? (u = a, v = b, true) : false;
}
template <class T>
bool uax(T& u, T& v, T a, T b) {
return v - u < b - a ? (u = a, v = b, true) : false;
}
namespace input {
template <class T>
void re(complex<T>& x);
template <class T1, class T2>
void re(pair<T1, T2>& p);
template <class T>
void re(vector<T>& a);
template <class T, size_t SZ>
void re(array<T, SZ>& a);
template <class T>
void re(T& x) {
cin >> x;
}
void re(double& x) {
string t;
re(t);
x = stod(t);
}
void re(ld& x) {
string t;
re(t);
x = stold(t);
}
template <class T, class... Ts>
void re(T& t, Ts&... ts) {
re(t);
re(ts...);
}
template <class T>
void re(complex<T>& x) {
T a, b;
re(a, b);
x = cd(a, b);
}
template <class T1, class T2>
void re(pair<T1, T2>& p) {
re(p.f, p.s);
}
template <class T>
void re(vector<T>& a) {
for (int i = 0; i < (((int)(a).size())); ++i) re(a[i]);
}
template <class T, size_t SZ>
void re(array<T, SZ>& a) {
for (int i = 0; i < (SZ); ++i) re(a[i]);
}
} // namespace input
using namespace input;
namespace output {
void pr(int x) { cout << x; }
void pr(long x) { cout << x; }
void pr(ll x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(ld x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char* x) { cout << x; }
void pr(const string& x) { cout << x; }
void pr(bool x) { pr(x ? "true" : "false"); }
template <class T>
void pr(const complex<T>& x) {
cout << x;
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T>
void pr(const T& x);
template <class T, class... Ts>
void pr(const T& t, const Ts&... ts) {
pr(t);
pr(ts...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
pr("{", x.f, ", ", x.s, "}");
}
template <class T>
void pr(const T& x) {
pr("{");
bool fst = 1;
for (const auto& a : x) pr(!fst ? ", " : "", a), fst = 0;
pr("}");
}
void ps() { pr("\n"); }
template <class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
pr(t);
if (sizeof...(ts)) pr(" ");
ps(ts...);
}
void pc() { pr("]\n"); }
template <class T, class... Ts>
void pc(const T& t, const Ts&... ts) {
pr(t);
if (sizeof...(ts)) pr(", ");
pc(ts...);
}
} // namespace output
using namespace output;
inline int bs(bool (*valid)(int), int l, int r, bool order) {
l--, r++;
if (!order) swap(l, r);
while (abs(r - l) > 1) {
int mid = (l + r) >> 1;
if (valid(mid))
r = mid;
else
l = mid;
}
valid(r);
return r;
}
struct dsu {
vector<int> p;
dsu(int n) { p.resize(n + 1); }
inline int get(int x) { return p[x] ? p[x] = get(p[x]) : x; }
inline bool mrg(int x, int y) {
return get(x) == get(y) ? false : p[get(x)] = get(y);
}
};
const int M = 1e9 + 7;
const ll lnf = 1e18 + 3;
const int inf = 1e9 + 3;
const int nax = 2e5 + 5;
typedef decay<decltype(M)>::type T;
struct mi {
T val;
explicit operator T() const { return val; }
mi() { val = 0; }
mi(const ll& v) {
val = (-M <= v && v <= M) ? v : v % M;
if (val < 0) val += M;
}
friend void pr(const mi& a) { pr(a.val); }
friend void re(mi& a) {
ll x;
re(x);
a = mi(x);
}
friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }
friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }
friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }
mi operator-() const { return mi(-val); }
mi& operator+=(const mi& m) {
if ((val += m.val) >= M) val -= M;
return *this;
}
mi& operator-=(const mi& m) {
if ((val -= m.val) < 0) val += M;
return *this;
}
mi& operator*=(const mi& m) {
val = (ll)val * m.val % M;
return *this;
}
friend mi pow(mi a, ll p) {
mi ans = 1;
assert(p >= 0);
for (; p; p /= 2, a *= a)
if (p & 1) ans *= a;
return ans;
}
friend mi inv(const mi& a) {
assert(a != 0);
return pow(a, M - 2);
}
mi& operator/=(const mi& m) { return (*this) *= inv(m); }
friend mi operator+(mi a, const mi& b) { return a += b; }
friend mi operator-(mi a, const mi& b) { return a -= b; }
friend mi operator*(mi a, const mi& b) { return a *= b; }
friend mi operator/(mi a, const mi& b) { return a /= b; }
};
vi invs, fac, ifac;
void genFac(int SZ) {
invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ);
invs[1] = fac[0] = ifac[0] = 1;
for (int i = (2); i <= (SZ - 1); ++i)
invs[i] = M - (ll)M / i * invs[M % i] % M;
for (int i = (1); i <= (SZ - 1); ++i) {
fac[i] = (ll)fac[i - 1] * i % M;
ifac[i] = (ll)ifac[i - 1] * invs[i] % M;
}
}
ll comb(int a, int b) {
if (a < b || b < 0) return 0;
return (ll)fac[a] * ifac[b] % M * ifac[a - b] % M;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int test_case;
cin >> test_case;
while (test_case--) {
int n;
re(n);
vi a(n, 0);
re(a);
int q = 0, p = n - 1;
while (a[q] >= q) q++;
while (a[p] >= n - 1 - p) p--;
ps(q > p + 1 ? "YES" : "NO");
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long t = 1;
template <class myType>
void print_arr(myType &arr, long long L, string sep) {
for (long long(i) = (0); (i) < (L); ++(i)) {
cout << arr[i];
if (i < L - 1) {
cout << sep;
}
}
cout << "\n";
return;
}
void solve() {
long long n;
cin >> n;
vector<long long> a(n);
for (long long(i) = (0); (i) < (n); ++(i)) cin >> a[i];
vector<long long> poss_left(n, 0), poss_right(n, 0);
for (long long(i) = (0); (i) < (n); ++(i)) {
if (a[i] >= i)
poss_left[i] = 1;
else
break;
}
for (long long(i) = (0); (i) < (n); ++(i)) {
if (a[n - i - 1] >= i)
poss_right[n - i - 1] = 1;
else
break;
}
for (long long(i) = (0); (i) < (n); ++(i)) {
if (poss_left[i] && poss_right[i]) {
cout << "Yes"
<< "\n";
return;
}
}
cout << "No"
<< "\n";
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> t;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, k, l, t, arr[300009], x;
int main() {
scanf("%lld", &t);
while (t--) {
scanf("%lld", &n);
k = n;
j = 0;
for (i = 0; i < n; i++) scanf("%lld", &arr[i]);
for (i = 0; i < n; i++) {
if (arr[i] >= i) {
k = i;
m = arr[i];
} else
break;
}
for (i = n - 1; i >= k; i--) {
l = n - i - 1;
if (arr[i] < l) {
j = 1;
break;
}
}
if (j)
printf("No\n");
else
printf("Yes\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[300005], n;
bool ch1() {
for (int i = 0; i < n; i++) {
if (a[i] < i) return 0;
}
return 1;
}
bool ch2() {
for (int i = 0; i < n; i++) {
if (a[i] < n - 1 - i) return 0;
}
return 1;
}
bool ch3() {
int pos = 0;
for (; pos < n; pos++) {
if (a[pos] < pos) break;
}
pos--;
for (; pos < n; pos++) {
if (a[pos] < n - 1 - pos) break;
}
return pos == n;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (ch1() || ch2() || ch3())
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pi>;
using si = set<int>;
using sl = set<ll>;
using qi = queue<int>;
using ql = queue<ll>;
template <class T>
bool uin(T& a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T& a, T b) {
return a < b ? (a = b, true) : false;
}
template <class T>
bool uin(T& u, T& v, T a, T b) {
return v - u > b - a ? (u = a, v = b, true) : false;
}
template <class T>
bool uax(T& u, T& v, T a, T b) {
return v - u < b - a ? (u = a, v = b, true) : false;
}
namespace input {
template <class T>
void re(complex<T>& x);
template <class T1, class T2>
void re(pair<T1, T2>& p);
template <class T>
void re(vector<T>& a);
template <class T, size_t SZ>
void re(array<T, SZ>& a);
template <class T>
void re(T& x) {
cin >> x;
}
void re(double& x) {
string t;
re(t);
x = stod(t);
}
void re(ld& x) {
string t;
re(t);
x = stold(t);
}
template <class T, class... Ts>
void re(T& t, Ts&... ts) {
re(t);
re(ts...);
}
template <class T>
void re(complex<T>& x) {
T a, b;
re(a, b);
x = cd(a, b);
}
template <class T1, class T2>
void re(pair<T1, T2>& p) {
re(p.f, p.s);
}
template <class T>
void re(vector<T>& a) {
for (int i = 0; i < (((int)(a).size())); ++i) re(a[i]);
}
template <class T, size_t SZ>
void re(array<T, SZ>& a) {
for (int i = 0; i < (SZ); ++i) re(a[i]);
}
} // namespace input
using namespace input;
namespace output {
void pr(int x) { cout << x; }
void pr(long x) { cout << x; }
void pr(ll x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(ld x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char* x) { cout << x; }
void pr(const string& x) { cout << x; }
void pr(bool x) { pr(x ? "true" : "false"); }
template <class T>
void pr(const complex<T>& x) {
cout << x;
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T>
void pr(const T& x);
template <class T, class... Ts>
void pr(const T& t, const Ts&... ts) {
pr(t);
pr(ts...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
pr("{", x.f, ", ", x.s, "}");
}
template <class T>
void pr(const T& x) {
pr("{");
bool fst = 1;
for (const auto& a : x) pr(!fst ? ", " : "", a), fst = 0;
pr("}");
}
void ps() { pr("\n"); }
template <class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
pr(t);
if (sizeof...(ts)) pr(" ");
ps(ts...);
}
void pc() { pr("]\n"); }
template <class T, class... Ts>
void pc(const T& t, const Ts&... ts) {
pr(t);
if (sizeof...(ts)) pr(", ");
pc(ts...);
}
} // namespace output
using namespace output;
inline int bs(bool (*valid)(int), int l, int r, bool order) {
l--, r++;
if (!order) swap(l, r);
while (abs(r - l) > 1) {
int mid = (l + r) >> 1;
if (valid(mid))
r = mid;
else
l = mid;
}
valid(r);
return r;
}
struct dsu {
vector<int> p;
dsu(int n) { p.resize(n + 1); }
inline int get(int x) { return p[x] ? p[x] = get(p[x]) : x; }
inline bool mrg(int x, int y) {
return get(x) == get(y) ? false : p[get(x)] = get(y);
}
};
const int M = 1e9 + 7;
const ll lnf = 1e18 + 3;
const int inf = 1e9 + 3;
const int nax = 2e5 + 5;
typedef decay<decltype(M)>::type T;
struct mi {
T val;
explicit operator T() const { return val; }
mi() { val = 0; }
mi(const ll& v) {
val = (-M <= v && v <= M) ? v : v % M;
if (val < 0) val += M;
}
friend void pr(const mi& a) { pr(a.val); }
friend void re(mi& a) {
ll x;
re(x);
a = mi(x);
}
friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }
friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }
friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }
mi operator-() const { return mi(-val); }
mi& operator+=(const mi& m) {
if ((val += m.val) >= M) val -= M;
return *this;
}
mi& operator-=(const mi& m) {
if ((val -= m.val) < 0) val += M;
return *this;
}
mi& operator*=(const mi& m) {
val = (ll)val * m.val % M;
return *this;
}
friend mi pow(mi a, ll p) {
mi ans = 1;
assert(p >= 0);
for (; p; p /= 2, a *= a)
if (p & 1) ans *= a;
return ans;
}
friend mi inv(const mi& a) {
assert(a != 0);
return pow(a, M - 2);
}
mi& operator/=(const mi& m) { return (*this) *= inv(m); }
friend mi operator+(mi a, const mi& b) { return a += b; }
friend mi operator-(mi a, const mi& b) { return a -= b; }
friend mi operator*(mi a, const mi& b) { return a *= b; }
friend mi operator/(mi a, const mi& b) { return a /= b; }
};
vi invs, fac, ifac;
void genFac(int SZ) {
invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ);
invs[1] = fac[0] = ifac[0] = 1;
for (int i = (2); i <= (SZ - 1); ++i)
invs[i] = M - (ll)M / i * invs[M % i] % M;
for (int i = (1); i <= (SZ - 1); ++i) {
fac[i] = (ll)fac[i - 1] * i % M;
ifac[i] = (ll)ifac[i - 1] * invs[i] % M;
}
}
ll comb(int a, int b) {
if (a < b || b < 0) return 0;
return (ll)fac[a] * ifac[b] % M * ifac[a - b] % M;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int test_case;
cin >> test_case;
while (test_case--) {
int n;
re(n);
vi a(n, 0);
re(a);
int q = 0, p = n - 1;
while (a[q] >= q) q++;
q--;
while (a[p] >= n - 1 - p) p--;
p++;
ps(q >= p ? "YES" : "NO");
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int num = 3e5 + 5;
int a[num];
int main() {
int N;
cin >> N;
while (N--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int l, r;
for (l = 0; l < n; l++)
if (a[l] < l) break;
for (r = n - 1; r >= 0; r--)
if (a[r] < n - r - 1) break;
if (r + 1 <= l - 1)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long t, n, ar[300005];
int main() {
cin >> t;
while (t--) {
long long flag = 1;
cin >> n;
for (int i = 0; i < n; i++) cin >> ar[i];
long long inc = 1;
for (int i = 0; i < n; i++) {
if (inc && ar[i] < i) {
inc = 0;
if (ar[i] == ar[i - 1]) ar[i]--;
if (ar[i] < 0) flag = 0;
continue;
}
if (!inc) {
if (ar[i] >= ar[i - 1]) ar[i] = ar[i - 1] - 1;
if (ar[i] < 0) flag = 0;
}
}
if (flag)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
int a[300010];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int flag = 0;
int x = 0;
int m = n;
for (int i = 1; i <= n; i++) {
if (x == 0 && a[i] < i - 1) {
x = 1;
if (a[i] < n - i || n - i >= a[i - 1]) {
flag = 1;
break;
}
} else if (x == 1) {
if (a[i] < n - i) {
flag = 1;
break;
}
}
}
if (flag == 1) {
printf("No\n");
} else {
printf("Yes\n");
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const bool b) { return (b ? "true" : "false"); }
string to_string(const char* s) { return to_string((string)s); }
string to_string(const char c) {
string s = "'";
s += c;
s += "'";
return s;
}
template <class T, class U>
string to_string(const pair<T, U>& p) {
string s = "(";
s += to_string(p.first);
s += ", ";
s += to_string(p.second);
s += ")";
return s;
}
template <class T>
string to_string(const T& a) {
bool first = true;
string s = "{";
for (const auto& x : a) {
if (!first) {
s += ", ";
}
first = false;
s += to_string(x);
}
s += "}";
return s;
}
void debug_out() { cerr << '\n'; }
template <class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
cerr << ' ' << to_string(head);
debug_out(tail...);
}
bool cmp(pair<int, int> a, pair<int, int> b) {
if (a.first == b.first) {
return (a.second < b.second);
}
return a.first < b.first;
}
namespace std {
template <>
struct hash<pair<int, int>> {
std::size_t operator()(pair<int, int> const& s) const noexcept {
return s.first * 1e6 + s.second;
}
};
} // namespace std
int freq[31] = {0};
void bin(int a) {
for (int i = 30; i >= 0; i--) {
freq[i] += a % 2;
a >>= 1;
}
}
void rbin(int a) {
for (int i = 30; i >= 0; i--) {
freq[i] -= a % 2;
a >>= 1;
}
}
int bin_to_int() {
int a = 0;
for (int i = 0; i <= 30; i++) {
a <<= 1;
a += (freq[i] != 0);
}
return a;
}
int f(int a, int b) { return ((a | b) - b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, x = 0, y = 0;
bool c = false, d = false;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] < i && x == 0) {
x = i;
}
if (a[i] >= i) {
c = true;
}
}
for (int i = 0; i < n; i++) {
if (a[n - i - 1] < i && y == 0) {
y = n - i + 1;
}
if (a[n - i - 1] >= i) {
d = true;
}
}
if (x == 0 && c == true) {
x = n;
}
if (y == 0 && d == true) {
y = 1;
}
if (x >= y) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[300001], b[300001];
int main() {
int t;
cin >> t;
for (int h = 0; h < t; h++) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (n == 1 && a[1] >= 0)
cout << "Yes" << endl;
else {
for (int i = 1; i <= n; i++) b[i] = 0;
int kt = 1, r = 1, l = 1;
for (int i = 1; i <= n; i++)
if (a[i] >= i - 1)
b[i] = 1;
else {
l = i - 1;
kt = 0;
break;
}
if (kt == 1) l = n;
kt = 1;
for (int i = n; i >= 1; i--)
if (a[i] >= n - i)
b[i] = 1;
else {
r = i + 1;
kt = 0;
break;
}
if (kt == 1) r = 1;
if (l >= r)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int a[N];
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int l = 0, r = n + 1;
for (int i = 1; i <= n; i++) {
if (a[i] < i - 1) break;
l++;
}
for (int i = n; i >= 1; i--) {
if (a[i] < n - i) break;
r--;
}
if (l < r)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
|
#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--) {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
string ans = "YES";
bool flag = false;
for (int i = 0; i < n - 1; i++) {
if (arr[i] >= arr[i + 1] && flag == false) {
if (arr[i + 1] < i + 1) {
flag = true;
}
}
if (flag) {
if (arr[i] < n - i - 1) {
ans = "NO";
break;
}
}
}
cout << ans << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool fb[300005], fc[300005];
int a[300005], b[300005], c[300005], n;
inline int read() {
int x = 0;
char ch = getchar();
while (ch > '9' || ch < '0') ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return x;
}
inline bool pd() {
for (int i = 1; i <= n; i++)
if (fb[i] && fc[i]) return 1;
return 0;
}
int main() {
int T = read();
while (T--) {
n = read();
b[0] = -1;
c[n + 1] = -1;
for (int i = 1; i <= n; i++) a[i] = read();
for (int i = 1; i <= n; i++) b[i] = min(a[i], b[i - 1] + 1);
for (int i = n; i >= 1; i--) c[i] = min(a[i], c[i + 1] + 1);
for (int i = 1; i <= n; i++) fc[i] = fb[i] = 0;
for (int i = 1; i <= n; i++)
if (b[i] > b[i - 1])
fb[i] = 1;
else
break;
for (int i = n; i >= 1; i--)
if (c[i] > c[i + 1])
fc[i] = 1;
else
break;
if (pd())
printf("Yes\n");
else
printf("No\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int t, n, c[N], a[N];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
c[0] = 1;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
c[i] = 1;
if (c[i - 1] == 0 || a[i] < i - 1) c[i] = 0;
}
int flag = 0;
for (int i = n; i >= 1; i--)
if (a[i] < n - i)
break;
else if (c[i])
flag = 1;
printf(flag ? "Yes\n" : "No\n");
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.