QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#226915 | #3534. Equal Mod Segments | 275307894a | AC ✓ | 134ms | 48432kb | C++14 | 2.2kb | 2023-10-26 18:16:06 | 2023-10-26 18:16:07 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=3e5+5,M=(1<<16)+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,A[N],st[N],sh,Mx;
struct node{
int x,l,r;
bool operator <(const node &B)const{return x<B.x;}
};
vector<node> Q[N],S[N];
void addl(int x,int id,int l,int r){/*cerr<<"add1 "<<x<<' '<<id<<' '<<l<<' '<<r<<'\n';*/S[x].emplace_back((node){l,id,1});S[x].emplace_back((node){r+1,id,-1});}
void addr(int x,int id,int l,int r){/*cerr<<"add2 "<<x<<' '<<id<<' '<<l<<' '<<r<<'\n';*/Q[x].emplace_back((node){id,l,r});}
namespace BIT{
int f[N];void add(int x,int y){while(x<=n) f[x]+=y,x+=x&-x;}
int qry(int x){int ans=0;while(x) ans+=f[x],x-=x&-x;return ans;}
}
void Solve(){
int i,j;scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d",&A[i]),Mx=max(Mx,A[i]);
for(i=1;i<=n;i++) {
int x=A[i],LA=i;
while(x>=A[st[1]]&&sh){
int l=0,r=sh+1,mid;while(l+1<r) mid=l+r>>1,(A[st[mid]]<=x?l:r)=mid;
addl(x,i,st[l]+1,LA);LA=st[l];x%=A[LA];
}
addl(x,i,1,LA);
while(sh&&A[st[sh]]>=A[i]) sh--;st[++sh]=i;
}
sh=0;for(i=n;i;i--){
int x=A[i],LA=i;
while(x>=A[st[1]]&&sh){
int l=0,r=sh+1,mid;while(l+1<r) mid=l+r>>1,(A[st[mid]]<=x?l:r)=mid;
addr(x,i,LA,st[l]-1);LA=st[l];x%=A[LA];
}
addr(x,i,LA,n);
while(sh&&A[st[sh]]>=A[i]) sh--;st[++sh]=i;
}
ll ans=0;
for(i=0;i<=Mx;i++){
sort(Q[i].begin(),Q[i].end());sort(S[i].begin(),S[i].end());
int R=0;
for(auto j:Q[i]){
while(R<S[i].size()&&S[i][R].x<=j.x) BIT::add(S[i][R].l,S[i][R].r),R++;
ans+=BIT::qry(j.r)-BIT::qry(j.l-1);
}
while(R--) BIT::add(S[i][R].l,-S[i][R].r);
}
printf("%lld\n",ans);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 20416kb
input:
2 5 5
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 20432kb
input:
3 8 3 5
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 3ms
memory: 18852kb
input:
200 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 259999 25...
output:
20100
result:
ok 1 number(s): "20100"
Test #4:
score: 0
Accepted
time: 0ms
memory: 18452kb
input:
194 417 5709 7419 4229 3228 1748 6064 6234 7768 3824 2479 791 7486 5636 7791 5835 3281 2617 1530 4663 482 8044 1566 8851 4282 4606 3835 730 8483 7987 4215 3657 2623 2180 5517 3492 4992 3917 921 1698 6654 2975 910 4700 6053 8047 7696 178 3332 4789 8362 4694 9262 5246 6122 9150 6509 4843 6304 1366 426...
output:
312
result:
ok 1 number(s): "312"
Test #5:
score: 0
Accepted
time: 3ms
memory: 20408kb
input:
200 4 3 5 3 3 4 5 1 4 2 4 5 3 1 4 3 1 1 1 1 2 5 4 1 2 4 2 1 3 4 4 3 2 5 3 1 5 3 3 4 5 5 5 3 4 5 1 2 1 2 3 3 3 3 3 2 4 5 4 1 4 1 1 1 4 1 3 5 2 1 1 4 1 5 4 3 3 2 4 2 3 5 1 2 3 2 3 3 2 2 5 2 2 5 5 3 3 4 1 5 2 1 5 3 4 3 1 3 1 2 1 2 5 1 5 5 5 2 5 4 3 3 4 5 3 1 2 5 1 3 3 3 5 4 3 5 4 5 1 3 3 5 3 1 4 2 4 1 ...
output:
19479
result:
ok 1 number(s): "19479"
Test #6:
score: 0
Accepted
time: 0ms
memory: 20444kb
input:
200 453 4417 8692 31650 47504 48506 53239 54115 54131 59214 62975 63448 78689 86379 87696 96876 105081 113534 150879 154102 160251 169116 169566 175584 179258 202132 206881 218776 225249 225761 252718 256717 266214 266219 270330 271220 278376 282759 294210 2 3496 10310 20704 44000 52768 59880 76745 ...
output:
8135
result:
ok 1 number(s): "8135"
Test #7:
score: 0
Accepted
time: 0ms
memory: 20420kb
input:
200 9844 9619 8557 8341 7204 7136 6619 5550 4929 4574 4264 2528 2304 2238 2126 2043 1922 1445 1133 5 352 753 1614 3379 3659 4195 4233 4316 4499 4738 4858 5100 5407 7470 7679 7952 8681 9710 9882 5 910 938 1230 1364 2135 2738 3285 4776 4906 5773 6208 6334 6391 7106 9095 9429 9485 9662 9968 5 1095 2205...
output:
3843
result:
ok 1 number(s): "3843"
Test #8:
score: 0
Accepted
time: 126ms
memory: 48332kb
input:
100000 256470 165976 188677 90704 138561 169855 11477 220928 68938 71795 105280 104364 161409 264238 93683 90840 184749 253535 170732 257245 67815 142857 284864 61031 230237 252482 185014 189016 261840 89301 106890 32003 153334 156576 292619 106833 95448 285751 181692 139903 92597 200639 242902 5731...
output:
1948408753
result:
ok 1 number(s): "1948408753"
Test #9:
score: 0
Accepted
time: 3ms
memory: 19804kb
input:
4995 2638 2794 3287 3590 5903 7464 9819 10006 12836 12891 13430 14115 14806 15465 16787 19477 21690 23135 23156 24664 24722 25884 27388 29057 29483 30517 31513 31923 33398 33896 34037 34840 35295 35681 39266 40798 40867 43758 45727 47062 49925 50167 50819 51440 51571 52437 52976 53109 53352 56118 58...
output:
3953891
result:
ok 1 number(s): "3953891"
Test #10:
score: 0
Accepted
time: 3ms
memory: 21076kb
input:
5000 30 34 37 73 77 79 217 625 747 855 866 959 1080 1105 1158 1174 1191 1601 1607 1674 1686 2047 2099 2331 2353 2471 2500 2680 2829 2829 2903 3035 3043 3151 3233 3263 3336 3345 3692 3743 3762 3786 3843 3853 3998 4019 4185 4266 4339 4473 4511 4546 4696 4707 4945 4973 4981 5044 5132 5286 5381 5441 545...
output:
3129066
result:
ok 1 number(s): "3129066"
Test #11:
score: 0
Accepted
time: 9ms
memory: 21676kb
input:
5000 195028 284998 46594 88935 1587 77233 43985 231936 200923 268368 148076 26915 56476 107969 182341 183456 162889 86660 253971 225769 285724 218016 66768 11542 252752 194524 167385 122787 190022 129926 284114 100653 141345 28432 281728 262169 143882 127342 251148 64205 107148 35513 11111 43893 770...
output:
76779
result:
ok 1 number(s): "76779"
Test #12:
score: 0
Accepted
time: 7ms
memory: 21368kb
input:
5000 146 394 111 505 238 471 259 947 387 249 953 357 635 448 485 337 837 822 455 467 586 906 979 565 801 345 353 92 499 104 445 816 839 931 456 680 583 802 141 676 874 7 69 185 816 729 163 553 561 643 865 376 430 925 114 720 830 2 5 638 43 537 448 971 146 693 883 267 831 421 809 385 510 636 227 482 ...
output:
7626501
result:
ok 1 number(s): "7626501"
Test #13:
score: 0
Accepted
time: 2ms
memory: 18944kb
input:
5000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 3...
output:
12502500
result:
ok 1 number(s): "12502500"
Test #14:
score: 0
Accepted
time: 134ms
memory: 47756kb
input:
100000 120319 152397 257218 208221 266407 247600 214443 131659 235221 112926 50634 62006 96000 290101 135920 248420 246192 254408 5504 12724 200547 136510 113169 39349 236555 192114 21488 194892 101294 159217 162971 63858 119877 131551 231014 178708 179357 65458 201722 287122 231737 225077 150225 14...
output:
312108493
result:
ok 1 number(s): "312108493"
Test #15:
score: 0
Accepted
time: 127ms
memory: 48432kb
input:
100000 256268 176214 144425 126755 38265 235416 151510 44762 183678 98966 228969 266677 281341 47247 16257 132061 253199 12338 96654 104523 161439 3044 56215 135470 73901 107518 87029 16104 134989 217549 67285 186257 21157 31441 135290 295731 145298 15646 155033 86380 174595 218877 201084 46223 2180...
output:
745284141
result:
ok 1 number(s): "745284141"
Test #16:
score: 0
Accepted
time: 110ms
memory: 46204kb
input:
100000 66065 47491 93520 15331 74739 99317 42484 66790 56802 7265 39400 15287 65486 62274 16351 31494 17579 7833 8942 15974 19857 44109 77360 89645 19772 69349 46242 23672 78317 848 53160 60100 82855 29949 87623 95286 36723 27043 14281 60724 57692 34555 59068 3210 53300 5601 99379 14887 88334 18326 ...
output:
1364782589
result:
ok 1 number(s): "1364782589"
Test #17:
score: 0
Accepted
time: 41ms
memory: 31116kb
input:
100000 3 7 9 9 5 4 9 4 2 9 2 5 1 7 7 8 5 6 9 7 9 2 8 3 10 2 9 5 10 2 6 7 6 5 3 9 5 3 8 4 10 8 4 8 6 6 10 9 9 7 7 6 5 6 1 4 6 10 3 9 1 10 5 9 4 3 5 6 6 4 7 10 1 6 7 1 10 6 9 4 6 8 6 4 8 1 4 8 10 3 6 5 1 10 8 3 9 5 4 5 1 1 8 6 5 3 3 6 1 7 8 5 1 5 5 8 5 7 3 7 8 10 3 4 1 2 9 5 4 3 3 9 6 5 4 1 1 9 4 6 4 ...
output:
4999349870
result:
ok 1 number(s): "4999349870"
Test #18:
score: 0
Accepted
time: 32ms
memory: 28648kb
input:
100000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000 290000...
output:
5000050000
result:
ok 1 number(s): "5000050000"
Test #19:
score: 0
Accepted
time: 60ms
memory: 32808kb
input:
99950 299504 294322 292672 288293 287294 286866 282288 280786 280779 270560 264138 256604 256204 252825 252450 250685 249144 245721 236768 236409 236038 232404 218152 216148 213336 208638 208556 204697 199902 198051 197054 195183 194803 193921 190622 188775 187755 182081 171038 160894 156624 155699 ...
output:
2103071493
result:
ok 1 number(s): "2103071493"
Test #20:
score: 0
Accepted
time: 43ms
memory: 33908kb
input:
100000 11 15 19 23 48 51 55 66 87 89 107 122 127 131 147 151 167 180 182 185 189 191 199 204 219 231 250 288 293 294 296 300 300 304 304 305 312 313 315 328 336 351 375 375 375 381 382 387 410 427 432 436 447 452 459 471 475 492 492 501 503 517 527 531 538 539 539 541 558 562 565 567 581 581 596 603...
output:
4414534666
result:
ok 1 number(s): "4414534666"
Test #21:
score: 0
Accepted
time: 46ms
memory: 29696kb
input:
100000 4 7 9 14 33 45 47 49 53 53 62 66 87 97 99 99 102 108 118 127 129 137 143 153 159 163 166 174 178 189 203 217 225 228 235 247 248 250 265 277 313 313 318 349 350 367 369 379 379 399 406 413 420 424 428 430 434 448 454 454 460 465 467 481 483 507 510 515 517 522 541 542 544 544 555 559 566 572 ...
output:
652204973
result:
ok 1 number(s): "652204973"
Test #22:
score: 0
Accepted
time: 30ms
memory: 28548kb
input:
100000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000...
output:
4999850004
result:
ok 1 number(s): "4999850004"