社区讨论
分块0分求助
P2357守墓人参与者 2已保存回复 6
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 6 条
- 当前快照
- 1 份
- 快照标识符
- @lo108ysl
- 此快照首次捕获于
- 2023/10/22 13:05 2 年前
- 此快照最后确认于
- 2023/11/02 12:35 2 年前
CPP
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,f;
long long a[N],k;
int opt,L,R;
int fk[N],len;
long long tag[N],v[N];
long long ans;
int main()
{
scanf("%d%d",&n,&f);
len=sqrt(n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
fk[i]=ceil(1.0*i/len);
v[fk[i]]+=a[i];
}
while(f--)
{
scanf("%d",&opt);
if(opt<=3)
{
if(opt==1)
scanf("%d%d%lld",&L,&R,&k);
else if(opt==2)
scanf("%lld",&k),L=1,R=1;
else
scanf("%lld",&k),L=1,R=1,k=-k;
if(fk[L]==fk[R])
{
for(int i=L;i<=R;i++)
a[i]+=k,v[fk[L]]+=k;
}
else
{
for(int i=L;fk[i]==fk[L];i++)
a[i]+=k,v[fk[L]]+=k;
for(int i=fk[L]+1;i<fk[R];i++)
tag[i]+=k,v[i]+=len*k;
for(int i=R;fk[i]==fk[R];i--)
a[i]+=k,v[fk[R]]+=k;
}
}
else
{
if(opt==4)
{
ans=0;
scanf("%d%d",&L,&R);
if(fk[L]==fk[R])
for(int i=L;i<=R;i++)
ans+=a[i]+tag[L];
else
{
for(int i=L;fk[i]==fk[L];i++)
ans+=a[i]+tag[L];
for(int i=fk[L]+1;i<fk[R];i++)
ans+=v[i];
for(int i=R;fk[i]==fk[R];i--)
ans+=a[i]+tag[R];
}
}
else
ans=a[1]+tag[1];
printf("%lld\n",ans);
}
}
return 0;
}
跑了亿组随机数据,发现了hack数据,但是不知道为什么错。
数据如下:
in:
CPP22 20
25729 16878 29158 22388 7127 12089 21602 1070 8035 29861 19497 7153 21772 28177 23796 3497 16867 22232 13566 28078 2984 21832
4 7 11
4 6 13
4 4 21
2 372
2 11506
5
4 16 16
3 24629
4 11 15
1 2 18 16630
3 9387
5
3 20384
4 1 7
2 32642
1 4 19 10659
5
1 4 16 30709
5
1 21 21 6669
right_out:
CPP80065
121079
289791
37607
3497
100395
3591
192229
15849
15849
wrong_out:
CPP80065
121079
289791
37607
3497
100395
3591
142339
15849
15849
回复
共 6 条回复,欢迎继续交流。
正在加载回复...