Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 1699 . Problem I 害蟲決戰時刻 */
- #include <bits/stdc++.h>
- #define jazz ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
- using namespace std;
- struct Query
- {
- int l, r, k, Qid, block;
- bool operator < (const Query &b) const
- {
- return (block < b.block) || (block == b.block && r < b.r);
- }
- }qry[100005];
- int N, Q, lim, L, R, K, maxcur = -1;
- int arr[50005], app[50005], cnt[50005];
- bool ans[100005] = {};
- void add(int x)
- {
- cnt[app[x]]--;
- app[x]++;
- cnt[app[x]]++;
- maxcur = max(maxcur, app[x]);
- }
- void sub(int x)
- {
- cnt[app[x]]--;
- app[x]--;
- cnt[app[x]]++;
- if(!cnt[maxcur]) maxcur--;
- }
- void solve()
- {
- sort(qry + 1, qry + 1 + Q);
- int cL = 1, cR = 1;
- cnt[0] = N;
- add(arr[cL]);
- for(int i = 1; i <= Q; ++i)
- {
- while(qry[i].r > cR)
- add(arr[++cR]);
- while(qry[i].l < cL)
- add(arr[--cL]);
- while(qry[i].r < cR)
- sub(arr[cR--]);
- while(qry[i].l > cL)
- sub(arr[cL++]);
- if(maxcur * 1.0 >= 1.0 * (qry[i].r - qry[i].l + 1) / qry[i].k)
- ans[qry[i].Qid] = true;
- }
- for(int i = 1; i <= Q; ++i) cout << (ans[i] ? "Yes" : "No") << '\n';
- }
- int main()
- {
- jazz;
- vector<int> v;
- cin >> N >> Q;
- lim = sqrt(N);
- for(int i = 1; i <= N && cin >> arr[i]; ++i) v.emplace_back(arr[i]);
- sort(v.begin(), v.end());
- v.resize(unique(v.begin(), v.end()) - v.begin());
- for(int i = 1; i <= N; ++i) arr[i] = lower_bound(v.begin(),v.end(),arr[i]) - v.begin();
- for(int i = 1; i <= Q && cin >> L >> R >> K; ++i)
- {
- if(L > R) swap(L, R);
- qry[i].Qid = i;
- qry[i].l = L;
- qry[i].r = R;
- qry[i].k = K;
- qry[i].block = L / lim;
- }
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement