Advertisement
mickypinata

TAChi-T005: Frequency Count

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