YEZAELP

SMMR-Chi-005: Frequency Count

Dec 5th, 2021 (edited)
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. unordered_map <int, int> val, freq;
  6.  
  7. int main(){
  8.  
  9.     int Q;
  10.     scanf("%d", &Q);
  11.  
  12.     for(int q=1;q<=Q;q++){
  13.         int opr, x;
  14.         scanf("%d %d", &opr, &x);
  15.         if(opr == 3){
  16.             if(freq[x] > 0) printf("1\n");
  17.             else printf("0\n");
  18.         }
  19.         else if(opr == 1){
  20.             if(freq[ val[x] ] > 0) freq[ val[x] ] --;
  21.             val[x] ++;
  22.             freq[ val[x] ] ++;
  23.         }
  24.         else{
  25.             if(val[x] == 0) continue;
  26.             if(freq[ val[x] ] > 0) freq[ val[x] ] --;
  27.             val[x] --;
  28.             freq[ val[x] ] ++;
  29.         }
  30.     }
  31.  
  32.     return 0;
  33. }
Add Comment
Please, Sign In to add comment