P3368是不是数据有误
  • 板块灌水区
  • 楼主gmllsswzw
  • 当前回复9
  • 已保存回复9
  • 发布时间2022/11/19 15:38
  • 上次更新2023/10/27 02:22:36
查看原帖
P3368是不是数据有误
534025
gmllsswzw楼主2022/11/19 15:38

交上去全WA,但下载的数据本地测试没有问题QAQ 附代码

//ljy.sys
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,m,x,y,k,opt,a[N],tot;
long long c[N],ans[N];
int lowbit(int x){
	return x&(-x);
}
void updata(int x,int k){
	while(x<=n){
		c[x]+=k;
		x+=lowbit(x);
	}
}
int getsum(int x){
	long long sum;
	while(x){
		sum+=c[x];
		x-=lowbit(x);
	}
	return sum;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		updata(i,a[i]-a[i-1]);
	}
	for(int i=1;i<=m;i++){
		scanf("%d",&opt);
		if(opt==1){
			scanf("%d%d%d",&x,&y,&k);
			updata(x,k);
			updata(y+1,-k);
		}
		else{
			scanf("%d",&x);
			ans[++tot]=getsum(x);
		}
	}
	for(int i=1;i<=tot;i++)	
		printf("%lld\n",ans[i]);
	return 0;
}

附#1

输入 
8 10
130 466 304 450 743 684 369 152 
2 5
1 1 8 256
1 2 8 214
1 2 8 941
1 3 8 287
1 3 8 66
2 7
2 7
2 3
1 2 8 617
输出
743
2133
2133
2068
2022/11/19 15:38
加载中...