Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3. #define sync \
  4. ios_base::sync_with_stdio(0); \
  5. cin.tie(0); \
  6. cout.tie(0)
  7. typedef long long ll;
  8. typedef unsigned long long ull;
  9. typedef pair<int,int> pii;
  10. typedef vector<int> vi;
  11. typedef long double ld;
  12. typedef pair<long long, long long> pll;
  13. #define ALL(V) V.begin(), V.end()
  14. #define SZ(V) (int)V.size()
  15. #define pb push_back
  16. #define mp make_pair
  17. #define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
  18. #define FOR(i, a, b) for(int i = (a); i < (b); ++i)
  19. #define FORR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
  20. #define REP(i, N) FOR(i, 0, N)
  21. #define REPR(i, N) RFOR(i, N, 0)
  22. #define FILL(A,value) memset(A,value,sizeof(A))
  23. #define f first
  24. #define s second
  25. #define ff first
  26. #define ss second
  27.  
  28.  
  29. const int MOD = 1e9+7;
  30. const int INF = 1e9+7;
  31. const int base = 1e9;
  32. const int MAX = 1e5;
  33. const double EPS = 1e-9;
  34. const double PI = acos(-1.);
  35. #define int ll
  36. int a[100005];
  37.  
  38. main()
  39. {
  40. sync;
  41. int t;
  42. cin>>t;
  43. for (int h=0;h<t;h++){
  44.  
  45. map<int,int> cnt;
  46. int n,q, difCnt=0;
  47. cin>>n>>q;
  48. for (int i=0;i<n;i++){
  49. cin>>a[i];
  50. cnt[a[i]];
  51. cnt[a[i]]++;
  52. if (cnt[a[i]]==1)
  53. difCnt++;
  54. }
  55. for (int i=0;i<q;i++){
  56. int type;
  57. cin>>type;
  58. if (type==2) cout<<difCnt-(cnt[0]>0)<<endl;
  59. else{
  60. int p,v;
  61. cin>>p>>v;
  62. if (v!=a[p-1]){
  63. cnt[v];
  64. cnt[a[p-1]];
  65. if (cnt[a[p-1]]==1)
  66. difCnt--;
  67. if (cnt[v]==0)
  68. difCnt++;
  69. cnt[a[p-1]]--;
  70. cnt[v]++;
  71. a[p-1]=v;
  72. }
  73. }
  74. }
  75.  
  76. }
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement