QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#168395#6856. Easy problem IC1924huangjiaxuWA 1600ms64192kbC++142.1kb2023-09-08 13:52:202023-09-08 13:52:21

Judging History

你现在查看的是最新测评结果

  • [2023-09-08 13:52:21]
  • 评测
  • 测评结果:WA
  • 用时:1600ms
  • 内存:64192kb
  • [2023-09-08 13:52:20]
  • 提交

answer

#include<stdio.h>
#include<algorithm>
using namespace std;
const int N=5e5+5;
typedef long long ll;
int n,q,a[N],T;
#define L k<<1
#define R k<<1|1
struct seg{
	ll sum[N<<2],tg[N<<2],ln[N<<2],mn[N<<2];
	bool rv[N<<2];
	void pushup(int k){
		ln[k]=ln[L]+ln[R],sum[k]=sum[L]+sum[R],mn[k]=min(mn[L],mn[R]);
	}
	void pushrv(int k){
		rv[k]^=1,tg[k]=-tg[k],sum[k]=-sum[k];
	}
	void pushtg(int k,ll v){
		sum[k]+=v*ln[k],tg[k]+=v,mn[k]+=v;
	}
	void pushdown(int k){
		if(rv[k]){
			pushrv(L);
			pushrv(R);
			rv[k]=false;
		}
		if(tg[k]){
			pushtg(L,tg[k]);
			pushtg(R,tg[k]);
			tg[k]=0;
		}
	}
	void build(int k,int l,int r){
		if(l==r){
			ln[k]=1,sum[k]=mn[k]=a[l];
			return;
		}
		int mid=l+r>>1;
		build(L,l,mid),build(R,mid+1,r);
		pushup(k);
	}
	void modify(int k,int l,int r,int x,int y,int v,bool ty){
		if(x<=l&&r<=y){
			if(ty)pushrv(k),pushtg(k,v);
			else pushtg(k,-v);
			return;
		}
		int mid=l+r>>1;
		pushdown(k);
		if(x<=mid)modify(L,l,mid,x,y,v,ty);
		if(y>mid)modify(R,mid+1,r,x,y,v,ty);
		pushup(k);
	}
	ll query(int k,int l,int r,int x,int y){
		if(x<=l&&r<=y)return sum[k];
		int mid=l+r>>1;
		pushdown(k);
		ll res=0;
		if(x<=mid)res+=query(L,l,mid,x,y);
		if(y>mid)res+=query(R,mid+1,r,x,y);
		return res;
	}
	void clear(){
		for(int i=1;i<n<<2;++i)sum[i]=ln[i]=mn[i]=tg[i]=rv[i]=0;
	}
}T1,T2;
void clear(int k,int l,int r,int v){
	if(T1.mn[k]>=2*v)return;
	if(l==r){
		T2.sum[k]=abs(T1.sum[k]-v),T2.ln[k]=1;
		T1.sum[k]=T1.ln[k]=0,T1.mn[k]=1e18;
		return;
	}
	T1.pushdown(k),T2.pushdown(k);
	int mid=l+r>>1;
	clear(L,l,mid,v),clear(R,mid+1,r,v);
	T1.pushup(k),T2.pushup(k);
}
void solve(){
	scanf("%d%d",&n,&q);
	T1.clear(),T2.clear();
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	T1.build(1,1,n);
	for(int i=1,op,l,r,x;i<=q;++i){
		scanf("%d%d%d",&op,&l,&r);
		if(op==1){
			scanf("%d",&x);
			T2.modify(1,1,n,l,r,x,true);
			clear(1,1,n,x);
			T1.modify(1,1,n,l,r,x,false);
		}else printf("%lld\n",T2.query(1,1,n,l,r));
	}
}
int main(){
	scanf("%d",&T);
	while(T--)solve();
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1600ms
memory: 64192kb

input:

5
200000 200000
3709648 4995492 5495456 501056 4601940 1825635 6147030 7689408 143360 9147335 2417120 2793752 9916480 8197760 7882880 7267650 2321280 1451104 8753832 7068854 6171460 1619388 5223842 4450688 2700644 5887820 4425750 6152896 6689900 5465982 9139756 5472040 6425220 9986528 4223363 938070...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
14624
5937
594
16046
11644
4359
10927
932
594
3512
55212
11492
83906
58091
72639
5952
5362
22398
56681
428768
491352
292918
582306
59911
31068
224629
240122
130389
811818
986882
151432
488888
131955
744972
174439
1075175
1604261
930089
239088
232926
206775
2...

result:

wrong answer 1st lines differ - expected: '367859591959', found: '0'