RT,卡常卡不动了,快读加了,define int long long去掉了,还是卡不进100pts
#include <bits/stdc++.h>
#define Arr std::vector
const int N = 1e5 + 5;
std::unordered_map<int, int> mp;
int l, r, t, ans[N];
int n, m, cur, q, a[N], plc[N], ret[N];
std::array<int, 5> Q[N];
int T;
inline int read()
{
int w = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
w = (w << 3) + (w << 1) + (ch - 48);
ch = getchar();
}
return w * f;
}
inline void add(int x)
{
mp[x]++;
}
inline void del(int x)
{
mp[x]--;
}
inline void Modify(int tt)
{
if (l <= plc[tt] && plc[tt] <= r)
{
del(a[plc[tt]]); add(ret[tt]);
}
std::swap(a[plc[tt]], ret[tt]);
}
signed main()
{
n = read(), m = read();
T = std::pow(n, 0.6666);;
for (int i = 1; i <= n; i++) a[i] = read();
for (int i = 1; i <= m; i++)
{
char op[5]; scanf("%s", op + 1);
if (op[1] == 'C')
{
int x = read(), d = read();
plc[++cur] = x, ret[cur] = d;
}
else
{
q++;
int L = read(), R = read(), D = read();
Q[q] = {L, R, D, q, cur};
}
}
std::sort(Q + 1, Q + q + 1, [](std::array<int, 5> x, std::array<int, 5> y)
{
int posx = x[0] / T, posy = y[0] / T;
if (posx != posy) return posx < posy;
int Posx = x[1] / T, Posy = y[1] / T;
if (Posx != Posy) return Posx < Posy;
return x[4] < y[4];
});
l = 1, r = 0, t = 0;
for (int i = 1; i <= q; i++)
{
while (l > Q[i][0]) l--, add(a[l]);
while (r < Q[i][1]) r++, add(a[r]);
while (l < Q[i][0]) del(a[l]), l++;
while (r > Q[i][1]) del(a[r]), r--;
while (t < Q[i][4]) t++, Modify(t);
while (t > Q[i][4]) Modify(t), t--;
ans[Q[i][3]] = mp[Q[i][2]];
}
for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
return 0;
}