带修莫队,复杂度应该是不对的,但还是厚颜无耻的来请人帮忙卡常。
感谢火车司机的快读板子。
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
namespace IO {
char buf[1 << 22], Out[1 << 22], *p1 = buf, *p2 = buf;
int p3 = -1, f = 0;
inline char getchar(){return (p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1 ++;}
inline void flush(){fwrite(Out, 1, p3 + 1, stdout);p3 = -1;}
inline void check(){if(p3 > (1 << 21)) flush();}
inline void putchar(char a){Out[++ p3] = a;check();}
}
template <typename T>
inline void read(T &x){
x = 0;int fu = 1;
char c = IO :: getchar();
while(c > 57 || c < 48){
if(c == 45) fu = -1;
c = IO :: getchar();
}
while(c <= 57 && c >= 48){
x = (x << 3) + (x << 1) + c - 48;
c = IO :: getchar();
}
x *= fu;
}
template <typename T>
inline void fprint(T x){
if(x < 0) IO :: putchar(45), x = -x;
if(x > 9) fprint(x / 10);
IO :: putchar(x % 10 + 48);
}
template <typename T>
inline void fprint(T x, char ch){
fprint(x);IO :: putchar(ch);
}
inline char next_char(){
char ch = IO :: getchar();
while(ch == 9 || ch == 10 || ch == 32) ch = IO :: getchar();
return ch;
}
int n, m;
const int block = 5000;
int a[300005], bel[300005];
struct QUEST{
int l, r;
int t, cc;
int id;
inline bool operator <(const QUEST &tmp) const{
return (bel[l] ^ bel[tmp.l]) ?(l < tmp.l) : ((bel[r] ^ bel[tmp.r])? ((bel[l] & 1)? (r < tmp.r) : (r > tmp.r)) : (t < tmp.t));
}
}q[300005];
int c[300005];
int ans, cnt[300005];
int ret[300005];
int main(){
read(n);read(m);
for (register int i = 1;i <= n;i ++) read(a[i]), bel[i] = ((i - 1) / block) + 1;
int tot = 0, tt = 0;
for (register int i = 1;i <= m;++ i){
int opt;read(opt);
if(opt == 1){
read(q[++ tot].l);read(q[tot].r);read(q[tot].cc);
q[tot].t = tt;
q[tot].id = tot;
}
else{read(c[++ tt]);}
}
sort(q + 1, q + tot + 1);
int l = q[1].l, r = l - 1, t = 0;
for (register int i = 1;i <= tot;++ i){
while(l > q[i].l) ++ cnt[a[-- l]];
while(r < q[i].r) ++ cnt[a[++ r]];
while(l < q[i].l) -- cnt[a[l ++]];
while(r > q[i].r) -- cnt[a[r --]];
while(t < q[i].t){
t ++;
bool ck1 = (c[t] <= q[i].r && c[t] >= q[i].l), ck2 = (c[t] + 1 <= q[i].r && c[t] + 1 >= q[i].l);
if(ck1 ^ ck2) {
if(ck1) -- cnt[a[c[t]]], ++ cnt[a[c[t] + 1]];
else ++ cnt[a[c[t]]], -- cnt[a[c[t] + 1]];
}
swap(a[c[t]], a[c[t] + 1]);
}
while(t > q[i].t){
bool ck1 = (c[t] <= q[i].r && c[t] >= q[i].l), ck2 = (c[t] + 1 <= q[i].r && c[t] + 1 >= q[i].l);
if(ck1 ^ ck2) {
if(ck1) -- cnt[a[c[t]]], ++ cnt[a[c[t] + 1]];
else ++ cnt[a[c[t]]], -- cnt[a[c[t] + 1]];
}
swap(a[c[t]], a[c[t] + 1]);
t --;
}
ret[q[i].id] = cnt[q[i].cc];
}
for (register int i = 1;i <= tot;++ i) fprint(ret[i], 10), IO :: check();
IO :: flush();
return 0;
}