Advertisement
mickypinata

CUBE-T225: Humanity has Declined

Jul 12th, 2021
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 2e5;
  5.  
  6. int arr[N + 2], cls[N + 1], cnt[N + 1];
  7. int nDwarf, numType;
  8.  
  9. void addSnack(int x){
  10.     if(x < 1 || x > nDwarf){
  11.         return;
  12.     }
  13.     if(cnt[x] == 0){
  14.         ++numType;
  15.     }
  16.     ++cnt[x];
  17. }
  18.  
  19. void removeSnack(int x){
  20.     if(x < 1 || x > nDwarf){
  21.         return;
  22.     }
  23.     --cnt[x];
  24.     if(cnt[x] == 0){
  25.         --numType;
  26.     }
  27. }
  28.  
  29. int main(){
  30.  
  31.     int nSnack, Q;
  32.     scanf("%d%d%d", &nSnack, &nDwarf, &Q);
  33.     for(int i = 1; i <= nSnack; ++i){
  34.         scanf("%d", &arr[i]);
  35.     }
  36.  
  37.     numType = 0;
  38.     int mnIdx = 0;
  39.     for(int i = 1; i <= nSnack; ++i){
  40.         while(numType < nDwarf && mnIdx <= nSnack){
  41.             addSnack(arr[mnIdx + 1]);
  42.             ++mnIdx;
  43.         }
  44.         cls[i] = mnIdx;
  45.         removeSnack(arr[i]);
  46.     }
  47.  
  48.     while(Q--){
  49.         int l, r;
  50.         scanf("%d%d", &l, &r);
  51.         if(r >= cls[l]){
  52.             cout << "YES\n";
  53.         } else {
  54.             cout << "NO\n";
  55.         }
  56.     }
  57.  
  58.     return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement