1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| #include<bits/stdc++.h>
#define ll long long #define INF 2147483647 #define mod 998244353 #define lc(a) (a << 1) #define rc(a) (a << 1 | 1) #define add(a, b) ((a) + (b) >= mod ? (a) + (b) - mod : (a) + (b)) #define minus(a, b) ((a) < (b) ? (a) - (b) + mod : (a) - (b)) #define mul(a, b) ((a) * (ll)(b) % mod)
int inp(){ char c = getchar(); while(c < '0' || c > '9') c = getchar(); int sum = 0; while(c >= '0' && c <= '9'){ sum = sum * 10 + c - '0'; c = getchar(); } return sum; } int a[300010]; int s[300010]; int powmod[300010]; struct SEG{ int l; int r; int sum; int rev;
SEG operator + (const SEG &b) const { if(l == -1) return b; if(b.l == -1) return (SEG){l, r, sum, rev}; return (SEG){l, b.r, add(mul(sum, powmod[b.r - b.l + 1]), b.sum), add(mul(b.rev, powmod[r - l + 1]), rev)}; } }; struct SEG_Tree{ SEG t[2400000];
void push_up(int cur){ t[cur] = t[lc(cur)] + t[rc(cur)]; }
void build(int cur, int l, int r){ t[cur].l = l; t[cur].r = r; t[cur].sum = t[cur].rev = 0; if(l == r){ t[cur].sum = t[cur].rev = 0; return ; } int mid = (l + r) >> 1; build(lc(cur), l, mid); build(rc(cur), mid + 1, r); push_up(cur); }
void modify(int cur, int pos, int c){ if(t[cur].l == t[cur].r){ t[cur].sum = t[cur].rev = c; return ; } if(pos <= t[lc(cur)].r) modify(lc(cur), pos, c); else modify(rc(cur), pos, c); push_up(cur); }
SEG query(int cur, int l, int r){ if(t[cur].l > r || t[cur].r < l) return (SEG){-1, -1, -1, -1}; if(t[cur].l >= l && t[cur].r <= r) return t[cur]; return query(lc(cur), l, r) + query(rc(cur), l, r); } }t;
int main(){ int n = inp(); for(int i = 1; i <= n; i++) a[i] = inp(); powmod[0] = 1; for(int i = 1; i <= n; i++) powmod[i] = (powmod[i - 1] << 1) % mod; t.build(1, 1, n); bool flg = false; for(int i = 1; i <= n; i++){ t.modify(1, a[i], 1); if((a[i] << 1) - 1 <= n){ if(a[i] > 1 && t.query(1, 1, a[i] - 1).sum != t.query(1, a[i] + 1, (a[i] << 1) - 1).rev){ flg = true; break; } } else { if(a[i] < n && t.query(1, a[i] + 1, n).rev != t.query(1, (a[i] << 1) - n, a[i] - 1).sum){ flg = true; break; } } } if(flg){ printf("YES\n"); } else { printf("NO\n"); } }
|