#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000000LL int B = 1<<10; void setting(vector &a,vector> &vs,vector> &sums,int ind){ for(int i=B*ind;i>n>>q; vector a(n); rep(i,n){ cin>>a[i]; } vector> vs((n+B-1)/B,vector()); vector> sums((n+B-1)/B,vector()); rep(i,n){ vs[i/B].push_back(0); sums[i/B].push_back(0); } rep(i,sums.size()){ sums[i].push_back(0); } for(int i=0;i>t>>x>>y; if(t==1){ x ^= last & ((1<<16)-1); y ^= last & ((1LL<<40)-1); x--; a[x] = y; setting(a,vs,sums,x/B); } else{ x ^= last & ((1<<16)-1); y ^= last & ((1<<16)-1); long long temp = last; if(x>y){ swap(x,y); } x--; long long ok = -1,ng = 1LL<<41; while(ng-ok>1LL){ long long mid = (ok+ng)/2; long long l = x,r = y; int cnt = 0; while(l=r){ if(a[l]<=mid)cnt++; l++; } else{ int ind = l/B; cnt += distance(vs[ind].begin(),upper_bound(vs[ind].begin(),vs[ind].end(),mid)); l += B; } } if(cnt <= (y-x)/2)ok = mid; else ng = mid; } ok++; last = 0; long long l = x,r = y; while(l=r){ if(a[l]<=ok){ last += ok-a[l]; } else last += a[l]-ok; l++; } else{ int ind = l/B; int num = distance(vs[ind].begin(),upper_bound(vs[ind].begin(),vs[ind].end(),ok)); last -= sums[ind][num]; last += sums[ind].back() - sums[ind][num]; last += ok * num; last -= ok * (vs[ind].size()-num); l += B; } } cout<