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
| #include <bits/stdc++.h> using namespace std; #define int long long const int N = 200010; int tr[N << 4],a[N],lst[N]; void build(int u,int l,int r){ if(l == r){ tr[u] = lst[l]; return; } int mid = l + r >> 1; build(u * 2, l, mid); build(u * 2 + 1, mid + 1, r); tr[u] = max(tr[u << 1], tr[u << 1 | 1]); } int ask(int u, int l,int r,int L,int R){ if(l >= L && r <= R){ return tr[u]; } int mid = l + r >> 1; int res = 0; if(L <= mid){ res = max(res, ask(u << 1,l, mid, L,R)); } if(R >= mid + 1){ res = max(res, ask(u << 1 | 1,mid + 1,r, L,R)); } return res; }
void solve(){ int n, q; cin >> n >> q; for(int i = 1; i <= n; i++)cin >> a[i]; map<int,int>mp; for(int i = 1 ;i <= n; i++){ if(mp.count(a[i])){ lst[i] = mp[a[i]]; } else lst[i] = lst[mp[a[i]]]; mp[a[i - 1]] = i - 1; }
build(1,1, n); while(q--){ int l, r; cin >> l >> r; if(ask(1,1,n,l,r) >= l){ cout << "YES" << endl; } else cout << "NO" <<endl; } }
signed main(){ int _(1); while(_ --){ solve(); } return 0; }
|