#include #include #include using namespace atcoder; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 10000000 int main(){ int N,Q; cin>>N>>Q; map mp; rep(i,N)mp[i] = i+1; fenwick_tree F(N); rep(i,N){ int A; scanf("%d",&A); F.add(i,A); } rep(i,Q){ int t,x; scanf("%d %d",&t,&x); x--; auto it = mp.upper_bound(x); it--; //cout<<(it->first)<<','<<(it->second)<second-1==x){ int temp = it->first; it = mp.erase(it); int x = temp; int y = it->second; mp.erase(it); mp[x] = y; } } if(t==2){ if(it->second-1!=x){ int a = it->first; int b = x+1; int c = x+1; int d = it->second; mp.erase(it); mp[a] = b; mp[c] = d; } } if(t==3){ F.add(x,1); } if(t==4){ int l = it->first; int r = it->second; printf("%lld\n",F.sum(l,r)); } } return 0; }