Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/tree_policy.hpp>
- #include <ext/pb_ds/assoc_container.hpp>
- #define int int64_t
- #pragma GCC optimize("O3")
- using namespace std;
- using namespace __gnu_pbds;
- using namespace __gnu_cxx;
- template<typename T>
- using orset = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
- int32_t main()
- {
- ios::sync_with_stdio(false);
- cin.tie(nullptr); cout.tie(nullptr);
- int n, q;
- cin >> n >> q;
- unordered_map<int, orset<int>> cnt;
- vector<int> a(n);
- for(int i = 0; i < n; i++){
- cin >> a[i];
- cnt[a[i]].insert(i);
- }
- while(q--){
- int tp;
- cin >> tp;
- if(tp == 1){
- int i, x;
- cin >> i >> x;
- i--;
- if(a[i] == x)
- continue;
- cnt[a[i]].erase(i);
- if(cnt[a[i]].empty())
- cnt.erase(a[i]);
- a[i] = x;
- cnt[x].insert(i);
- }
- else{
- int l, r, cur = 0;
- cin >> l >> r;
- l--, r--;
- for(auto & i : cnt){
- if(i.second.empty())
- continue;
- int len = i.second.order_of_key(r + 1) - i.second.order_of_key(l);
- if(len & 1)
- cur++;
- }
- cout << cur << '\n';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment