ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#932 | #211. 「CSP-S2019」划分 | ryp | 100 | 1312ms | 927912kb | C++14 | 2.2kb | 2025-07-04 17:08:52 | 2025-07-04 17:08:53 |
answer
#include <cstdio>
#include <cstring>
#include <ctime>
const int MAXN=40000010;
const unsigned PMOD=(1<<30)-1;
const unsigned MOD=1e9;
long long _sum[MAXN],*sum=_sum+5,g[MAXN];
int q[MAXN],f[MAXN];
int p[100010],l[100010],r[100010];
char _B[1<<21],*_S=_B,*_T=_B;
#define getchar() (_S==_T&&(_T=(_S=_B)+fread(_B,1,1<<21,stdin),_S==_T)?EOF:*_S++)
inline int read(){
register int res=0;
register char ch=getchar();
while(ch<'0'||ch>'9')
ch=getchar();
while(ch>='0'&&ch<='9'){
res=(res<<3)+(res<<1)+(ch&15);
ch=getchar();
}
return res;
}
int main(){
int n=read(),type=read();
if(type==0){
for(int i=1;i<=n;i++){
int x=read();
sum[i]=sum[i-1]+x;
}
}
else{
register unsigned x,y,z,m;
register unsigned s1,s2,s3,pos=1;
x=read();y=read();z=read();s1=read();s2=read();m=read();
for(register int i=1;i<=m;i++){
register unsigned p=read(),l=read(),r=read(),len=r-l+1;
for(;pos<=p;pos++){
if(pos==1)
s3=s1;
else if(pos==2)
s3=s2;
else{
s3=(x*s2+y*s1+z)&PMOD;
s1=s2;s2=s3;
}
sum[pos]=sum[pos-1]+s3%len+l;
}
}
}
register int *hd=q+1,*tl=q+1;
for(register int i=1;i<=n;i++){
while(hd<tl&&sum[*hd]+g[*hd]<=sum[i])
hd++;
g[i]=sum[i]-sum[*(hd-1)];
// f[i]=f[q[hd-1]]+g[i]*g[i];
f[i]=*(hd-1);
while(hd<tl&&sum[*(tl-1)]+g[*(tl-1)]>=sum[i]+g[i])
tl--;
*tl++=i;
}
register unsigned pos=n;
register unsigned long long ans[3]={0,0,0};
while(pos){
register unsigned long long tmp1=g[pos]&PMOD,tmp2=g[pos]>>30;
ans[2]+=tmp2*tmp2;
ans[1]+=tmp1*tmp2<<1;
ans[0]+=tmp1*tmp1;
ans[1]+=ans[0]>>30;ans[0]&=PMOD;
ans[2]+=ans[1]>>30;ans[1]&=PMOD;
pos=f[pos];
}
register unsigned long long tmp[4]={ans[2],0,0,0};
for(int i=1;~i;i--){
for(int j=0;j<=3;j++)
tmp[j]<<=30;
tmp[0]+=ans[i];
for(int j=0;j<=2;j++){
tmp[j+1]+=tmp[j]/1000000000;
tmp[j]%=1000000000;
}
}
if(tmp[3])
printf("%llu%09llu%09llu%09llu\n",tmp[3],tmp[2],tmp[1],tmp[0]);
else if(tmp[2])
printf("%llu%09llu%09llu\n",tmp[2],tmp[1],tmp[0]);
else if(tmp[1])
printf("%llu%09llu\n",tmp[1],tmp[0]);
else
printf("%llu\n",tmp[0]);
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 4
Accepted
time: 0ms
memory: 9716kb
input:
1 0 1
output:
1
result:
ok "1"
Test #2:
score: 4
Accepted
time: 0ms
memory: 9532kb
input:
10 0 5 1 2 1 1 1 1 1 2 3
output:
108
result:
ok "108"
Test #3:
score: 4
Accepted
time: 0ms
memory: 9704kb
input:
10 0 5 1 1 4 3 2 1 6 5 6
output:
254
result:
ok "254"
Test #4:
score: 4
Accepted
time: 0ms
memory: 9580kb
input:
50 0 488 19 20 6 7 8 9 10 11 171 172 173 174 64 64 64 64 64 64 64 64 64 64 64 64 218 219 220 221 222...
output:
4485725
result:
ok "4485725"
Test #5:
score: 4
Accepted
time: 0ms
memory: 9532kb
input:
50 0 657 83 80 81 86 60 84 85 63 64 61 335 13 14 6 7 6 7 6 7 6 7 6 17 17 17 17 17 135 136 130 131 10...
output:
3963358
result:
ok "3963358"
Test #6:
score: 4
Accepted
time: 0ms
memory: 9672kb
input:
50 0 538 3 4 3 4 3 4 3 128 89 90 131 72 79 76 71 84 81 82 73 76 83 74 83 82 71 72 71 74 81 8 3 2 13 ...
output:
3376710
result:
ok "3376710"
Test #7:
score: 4
Accepted
time: 0ms
memory: 9716kb
input:
400 0 3009 356 438 551 606 387 2073 2777 2778 824 404 394 554 248 545 261 262 548 253 561 403 415 27...
output:
3170248737
result:
ok "3170248737"
Test #8:
score: 4
Accepted
time: 0ms
memory: 9636kb
input:
400 0 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633...
output:
6979363199
result:
ok "6979363199"
Test #9:
score: 4
Accepted
time: 0ms
memory: 9720kb
input:
400 0 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444...
output:
3318244868
result:
ok "3318244868"
Test #10:
score: 4
Accepted
time: 0ms
memory: 9704kb
input:
5000 0 26416 26417 26418 26419 26420 26421 26422 26423 26424 26425 26426 26427 26428 26429 26430 264...
output:
33887118980393
result:
ok "33887118980393"
Test #11:
score: 4
Accepted
time: 0ms
memory: 9736kb
input:
5000 0 23207 23208 23209 23210 23211 23212 23213 23214 23215 23216 23217 23218 23219 23220 23221 232...
output:
33248894141865
result:
ok "33248894141865"
Test #12:
score: 4
Accepted
time: 0ms
memory: 9620kb
input:
5000 0 66757 66758 66759 66760 66761 66762 66763 66764 66765 66766 66767 66768 66769 66770 66771 667...
output:
37723392435267
result:
ok "37723392435267"
Test #13:
score: 4
Accepted
time: 0ms
memory: 9744kb
input:
5000 0 27900 27901 27902 27903 27904 27905 27906 27907 27908 27909 27910 27911 27912 27913 27914 279...
output:
32475835026360
result:
ok "32475835026360"
Test #14:
score: 4
Accepted
time: 0ms
memory: 9712kb
input:
5000 0 88538 88539 88540 88541 88542 88543 88544 88545 88546 88547 88548 88549 88550 88551 88552 885...
output:
46614887221321
result:
ok "46614887221321"
Test #15:
score: 4
Accepted
time: 1ms
memory: 9632kb
input:
5000 0 57597 57598 57599 57600 57601 57602 57603 57604 57605 57606 57607 57608 57609 57610 57611 576...
output:
42148252068110
result:
ok "42148252068110"
Test #16:
score: 4
Accepted
time: 0ms
memory: 9656kb
input:
5000 0 32091 32092 32093 32094 32095 32096 32097 32098 32099 32100 32101 32102 32103 32104 32105 321...
output:
36356787333837
result:
ok "36356787333837"
Test #17:
score: 4
Accepted
time: 9ms
memory: 24028kb
input:
500000 0 232520 232521 232522 232523 232524 232525 232526 232527 232528 232529 232530 232531 232532 ...
output:
3404048031740228391
result:
ok "3404048031740228391"
Test #18:
score: 4
Accepted
time: 6ms
memory: 23872kb
input:
500000 0 171097 171098 171099 171100 171101 171102 171103 171104 171105 171106 171107 171108 171109 ...
output:
3274086928325086647
result:
ok "3274086928325086647"
Test #19:
score: 4
Accepted
time: 9ms
memory: 23868kb
input:
500000 0 507482 507483 507484 507485 507486 507487 507488 507489 507490 507491 507492 507493 507494 ...
output:
3313623507696416665
result:
ok "3313623507696416665"
Test #20:
score: 4
Accepted
time: 7ms
memory: 23924kb
input:
500000 0 184967 184968 184969 184970 184971 184972 184973 184974 184975 184976 184977 184978 184979 ...
output:
3136834726987393666
result:
ok "3136834726987393666"
Test #21:
score: 4
Accepted
time: 7ms
memory: 24032kb
input:
500000 0 532977 532978 532979 532980 532981 532982 532983 532984 532985 532986 532987 532988 532989 ...
output:
3194381893489801230
result:
ok "3194381893489801230"
Test #22:
score: 4
Accepted
time: 6ms
memory: 24032kb
input:
500000 0 599257 599258 599259 599260 599261 599262 599263 599264 599265 599266 599267 599268 599269 ...
output:
3354933513897756362
result:
ok "3354933513897756362"
Test #23:
score: 4
Accepted
time: 416ms
memory: 893088kb
input:
40000000 1 825772993 851948608 851948609 23077817 23077818 100000 10000000 446359966 479914397 10000...
output:
3794994452005049854674339
result:
ok "3794994452005049854674339"
Test #24:
score: 4
Accepted
time: 415ms
memory: 907256kb
input:
40000000 1 843670282 1068932343 1068932344 12005507 12005508 100000 20000000 191508704 225063135 200...
output:
2875588265896779695426252
result:
ok "2875588265896779695426252"
Test #25:
score: 4
Accepted
time: 436ms
memory: 927912kb
input:
40000000 1 308437383 27106938 27106939 1520476 1520477 100000 30000000 7283395 40837826 30000152 202...
output:
2049762805232475409502206
result:
ok "2049762805232475409502206"