#include <iostream> #include <string.h> #include <vector> #include <set> using namespace std; struct E{ long long int num,no; bool commit; }; struct E2{ int l,r,x,y,z; }; const int maxS=16;//600000; int R=7;//262143 int no2=0; vector<E2> copyData; vector<long long int> areaSum; E segA[maxS]; long long int fSegASet(int no,int p1,int l2,int r2,long long int num){ if(r2<p1 || p1<l2)return segA[no].num; if(l2==r2){ segA[no].num=num; return segA[no].num; } int m=(l2+r2)/2; long long int res=fSegASet(no*2+1,p1,l2,m,num); res+=fSegASet(no*2+2,p1,m+1,r2,num); segA[no].num=res; return res; } long long int calc(int no,int no2,int no3,int l,int r,int l2,int r2,bool commit){ cout<<"<"<<commit<<" "<<no<<",no2="<<no2<<",no3="<<no3<<",l="<<l<<",r="<<r<<","<<l2<<","<<r2<<",>"; if(commit==true){ cout<<endl; return segA[no].num; } E2 e2=copyData[no3]; int l3=e2.y+(l2-e2.x); int r3=l3+(r2-l2)+1; return areaSum[r3]-areaSum[l3]; } long long int fSegACalcAns(int no,int l,int r,int l2,int r2,int no2,bool commit){ commit=commit && segA[no].commit; no2=(no2<segA[no].no)?segA[no].no:no2; long long int res=calc(no,no2,no2,l,r,l2,r2,commit); if(r2<l || r<l2)return 0; if(l2==r2){ segA[no].no=no2; return res; } if(l<=l2 && r2<=r){ segA[no].no=no2; return res; }else{ int m=(l2+r2)/2; res=fSegACalcAns(no*2+1,l,r,l2,m,no2,commit); res+=fSegACalcAns(no*2+2,l,r,m+1,r2,no2,commit); return res; } } long long int fSegAUpData(int no,int l,int r,int l2,int r2,int no2,int no3,bool commit){ commit=commit && segA[no].commit; no3=(no3<segA[no].no)?segA[no].no:no3; long long int res=calc(no,no2,no3,l,r,l2,r2,commit); if(r2<l || r<l2)return res; res=calc(no,no2,no2,l,r,l2,r2,false); segA[no].commit=true; if(l2==r2){ segA[no].no=no2; segA[no].num=res; segA[no].commit=true; return res; } if(l<=l2 && r2<=r){ segA[no].no=no2; segA[no].num=res; segA[no].commit=true; segA[no*2+1].commit=false; segA[no*2+2].commit=false; return res; }else{ int m=(l2+r2)/2; res=fSegAUpData(no*2+1,l,r,l2,m,no2,no3,commit); res+=fSegAUpData(no*2+2,l,r,m+1,r2,no2,no3,commit); segA[no].num=res; segA[no].commit=true; return res; } } int main() { for(int i=0;i<maxS;i++){ segA[i].num=0; segA[i].no=-1; segA[i].commit=true; } int n,m; cin>>n>>m; for(int i=0;i<n;i++){ long long int num; cin>>num; fSegASet(0,i,0,R,num); } areaSum.push_back(0); long long int sum=0; for(int i=0;i<n;i++){ long long int num; cin>>num; sum+=num; areaSum.push_back(sum); } for(int i=0;i<maxS;i++){ areaSum.push_back(Sum); } for(int i=0;i<m;i++){ int c1,l,r,x,y,z; cin>>c1; if(c1==0){ cin>>x>>y>>z; E2 e2; e2.l=y-1; e2.r=y-2+z; e2.x=x-1; e2.y=y-1; e2.z=z; l=x-1; r=x-2+z; copyData.push_back(e2); fSegAUpData(0,l,r,0,R,no2,-1,true); no2++; }else{ cin>>l>>r; l--; r--; cout<<fSegACalcAns(0,l,r,0,R,-1,true)<<endl; } for(int i=0;i<maxS;i++){ cout<<"("<<i<<","<<segA[i].num<<")"; } cout<<endl; } return 0; }
5 5 1 3 5 7 9 2 4 6 8 10 1 1 3 1 4 5 0 4 1 2 1 1 3 1 4 5
<1 0,no2=-1,no3=-1,l=0,r=2,0,7,> <1 1,no2=-1,no3=-1,l=0,r=2,0,3,> <1 3,no2=-1,no3=-1,l=0,r=2,0,1,> <1 4,no2=-1,no3=-1,l=0,r=2,2,3,> <1 9,no2=-1,no3=-1,l=0,r=2,2,2,> <1 10,no2=-1,no3=-1,l=0,r=2,3,3,> <1 2,no2=-1,no3=-1,l=0,r=2,4,7,> 9 (0,25)(1,16)(2,9)(3,4)(4,12)(5,9)(6,0)(7,1)(8,3)(9,5)(10,7)(11,9)(12,0)(13,0)(14,0)(15,0) <1 0,no2=-1,no3=-1,l=3,r=4,0,7,> <1 1,no2=-1,no3=-1,l=3,r=4,0,3,> <1 3,no2=-1,no3=-1,l=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,l=3,r=4,4,4,>l3=1,r3=2 E=9 6 2 <1 12,no2=0,no3=-1,l=3,r=4,5,5,>l3=2,r3=3 E=0 12 6 <1 6,no2=0,no3=-1,l=3,r=4,6,7,>l3=3,r3=5 E=0 30 12 (0,39)(1,11)(2,28)(3,4)(4,7)(5,10)(6,0)(7,1)(8,3)(9,5)(10,2)(11,4)(12,0)(13,0)(14,0)(15,0) <1 0,no2=-1,no3=-1,l=0,r=2,0,7,> <1 1,no2=-1,no3=-1,l=0,r=2,0,3,> <1 3,no2=-1,no3=-1,l=0,r=2,0,1,> <1 4,no2=-1,no3=-1,l=0,r=2,2,3,> <1 9,no2=-1,no3=-1,l=0,r=2,2,2,> <1 10,no2=0,no3=0,l=0,r=2,3,3,> <1 2,no2=-1,no3=-1,l=0,r=2,4,7,> 9 (0,39)(1,11)(2,28)(3,4)(4,7)(5,10)(6,0)(7,1)(8,3)(9,5)(10,2)(11,4)(12,0)(13,0)(14,0)(15,0) <1 0,no2=-1,no3=-1,l=3,r=4,0,7,> <1 1,no2=-1,no3=-1,l=3,r=4,0,3,> <1 3,no2=-1,no3=-1,l=3,r=4,0,1,> <1 4,no2=-1,no3=-1,l=3,r=4,2,3,> <1 9,no2=-1,no3=-1,l=3,r=4,2,2,> <1 10,no2=0,no3=0,l=3,r=4,3,3,> <1 2,no2=-1,no3=-1,l=3,r=4,4,7,> <1 5,no2=-1,no3=-1,l=3,r=4,4,5,> <1 11,no2=0,no3=0,l=3,r=4,4,4,> <1 12,no2=-1,no3=-1,l=3,r=4,5,5,> <1 6,no2=-1,no3=-1,l=3,r=4,6,7,> 6 (0,39)(1,11)(2,28)(3,4)(4,7)(5,10)(6,0)(7,1)(8,3)(9,5)(10,2)(11,4)(12,0)(13,0)(14,0)(15,0)