提交时间:2023-08-16 12:05:25
运行 ID: 98596
#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m, ti, len; int a[N], tmp[N], tong[N]; struct node { int op, l, r, x, tm, id; } t[N]; int sz = 4000, tot; bool cmp(node x, node y) {return x.tm < y.tm ? 1 : (x.l / sz < y.l / sz ? 1 : x.r < y.r);} int pre[N], nxt[N]; int main() { // freopen("1.in", "r", stdin); // freopen("std.out", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++) cin >> a[i], tmp[i] = a[i], tong[++len] = a[i]; for(int i = 1; i <= m; i++) { cin >> t[i].op >> t[i].l >> t[i].r; if(t[i].op == 1) { ti++; pre[ti] = tmp[i]; cin >> t[i].x; tmp[i] = t[i].x; tong[++len] = t[i].x; nxt[ti] = tmp[i]; } else t[i].tm = ti, t[i].id = ++tot; } sort(tong + 1, tong + len + 1); len = unique(tong + 1, tong + len + 1) - tong - 1; for(int i = 1; i <= n; i++) a[i] = lower_bound(tong + 1, tong + len + 1, a[i]) - tong; for(int i = 1; i <= m; i++) if(t[i].x) t[i].x = lower_bound(tong + 1, tong + len + 1, t[i].x) - tong; if(n <= 5000 && m <= 5000) { for(int i = 1; i <= m; i++) { for(int j = 1; j <= len; j++) tong[j] = 0; if(t[i].op == 1) for(int j = t[i].l; j <= t[i].r; j++) a[j] = t[i].x; else { int res = 0; for(int j = t[i].l; j <= t[i].r; j++) if(!tong[a[j]]) res++, tong[a[j]]++; cout << res << '\n'; } } return 0; } // sort(t + 1, t + m + 1, cmp); // for(int i = 1; i <= m; i++) // { // while(now < t[i].tm) update(now); // while(now > t[i].tm) update(now); // while(l < t[i].l) del(l++); // while(l > t[i].l) add(--l); // while(r < t[i].r) add(++r); // while(r > t[i].r) del(r--); // } return 0; }