Advertisement
Emiliatan

1699

Jul 2nd, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. /* 1699 . Problem I 害蟲決戰時刻 */
  2. #include <bits/stdc++.h>
  3. #define jazz ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
  4.  
  5. using namespace std;
  6.  
  7. struct Query
  8. {
  9.     int l, r, k, Qid, block;
  10.     bool operator < (const Query &b) const
  11.     {
  12.         return (block < b.block) || (block == b.block && r < b.r);
  13.     }
  14. }qry[100005];
  15.  
  16. int N, Q, lim, L, R, K, maxcur = -1;
  17. int arr[50005], app[50005], cnt[50005];
  18. bool ans[100005] = {};
  19.  
  20. void add(int x)
  21. {
  22.     cnt[app[x]]--;
  23.     app[x]++;
  24.     cnt[app[x]]++;
  25.     maxcur = max(maxcur, app[x]);
  26. }
  27. void sub(int x)
  28. {
  29.     cnt[app[x]]--;
  30.     app[x]--;
  31.     cnt[app[x]]++;
  32.     if(!cnt[maxcur]) maxcur--;
  33. }
  34. void solve()
  35. {
  36.     sort(qry + 1, qry + 1 + Q);
  37.     int cL = 1, cR = 1;
  38.     cnt[0] = N;
  39.     add(arr[cL]);
  40.     for(int i = 1; i <= Q; ++i)
  41.     {
  42.         while(qry[i].r > cR)
  43.             add(arr[++cR]);
  44.         while(qry[i].l < cL)
  45.             add(arr[--cL]);
  46.         while(qry[i].r < cR)
  47.             sub(arr[cR--]);
  48.         while(qry[i].l > cL)
  49.             sub(arr[cL++]);
  50.         if(maxcur * 1.0 >= 1.0 * (qry[i].r - qry[i].l + 1) / qry[i].k)
  51.             ans[qry[i].Qid] = true;
  52.     }
  53.     for(int i = 1; i <= Q; ++i) cout << (ans[i] ? "Yes" : "No") << '\n';
  54. }
  55.  
  56. int main()
  57. {
  58.     jazz;
  59.     vector<int> v;
  60.     cin >> N >> Q;
  61.     lim = sqrt(N);
  62.  
  63.     for(int i = 1; i <= N && cin >> arr[i]; ++i) v.emplace_back(arr[i]);
  64.  
  65.     sort(v.begin(), v.end());
  66.     v.resize(unique(v.begin(), v.end()) - v.begin());
  67.     for(int i = 1; i <= N; ++i) arr[i] = lower_bound(v.begin(),v.end(),arr[i]) - v.begin();
  68.  
  69.     for(int i = 1; i <= Q && cin >> L >> R >> K; ++i)
  70.     {
  71.         if(L > R) swap(L, R);
  72.         qry[i].Qid = i;
  73.         qry[i].l = L;
  74.         qry[i].r = R;
  75.         qry[i].k = K;
  76.         qry[i].block = L / lim;
  77.     }
  78.     solve();
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement