QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#744217#7494. 盼君勿忘TheZone100 ✓1798ms9340kbC++203.2kb2024-11-13 21:12:282024-11-13 21:12:37

Judging History

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

  • [2024-11-13 21:12:37]
  • 评测
  • 测评结果:100
  • 用时:1798ms
  • 内存:9340kb
  • [2024-11-13 21:12:28]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cmath>
#include<unordered_set>
#include<vector>
#define INF (1ll<<60)
using namespace std;
typedef long long ll;
namespace Lan {
    inline string sread() {
        string s=" ";char e=getchar();
        while(e==' '||e=='\n')e=getchar();
        while(e!=' '&&e!='\n')s+=e,e=getchar();
        return s;
    }
    inline void swrite(string s){
        for(char e:s)putchar(e);
        printf("\n");
    }
    inline ll read() {
        ll x=0,y=1;char c=getchar();
        while(!isdigit(c)){if(c=='-')y=-1;c=getchar();}
        while(isdigit(c)){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
        return x*=y;
    }
    inline void write(ll x) {
        if(x<0){x=-x,putchar('-');}ll sta[35],top=0;
        do sta[top++]=x%10,x/=10;while(x);
        while(top)putchar(sta[--top]+'0');
    }
}using namespace Lan;
const int N=1e5+9;
const int B=1e3+9;
int a[N],c[N],sum[N];//数,数量,出现k次的和
int L[B],R[B],pos[N];
ll t1[N],t2[N];
ll ans[N];
int cur,mi;
unordered_set<int> st;
struct Q{
    int l,r,p,id;
    friend bool operator < (const Q &a,const Q &b){
        return pos[a.l]^pos[b.l]?pos[a.l]<pos[b.l]:pos[a.l]&1?a.r<b.r:a.r>b.r;
    }
}que[N];
inline void init(int mod){//处理sqrt(n)
    t1[0]=1;
    for(int i=1;i<=mi;i++){
        t1[i]=t1[i-1]*2%mod;
    }
    t2[0]=1;
    for(int i=1;i<=mi;i++){
        t2[i]=t2[i-1]*t1[mi]%mod;
    }
}
inline ll cqmi(int x,int mod){//O(1)询问
    return t1[x%mi]*t2[x/mi]%mod;
}
inline ll query(int l,int r,int p){
    ll res=0;
    for(auto &i : st){
        res+=sum[i]*(cqmi(r-l+1,p)-cqmi(r-l+1-i,p)+p)%p;
    }
    res%=p;
    return res;
}
inline void add(int pos){
    sum[c[a[pos]]]-=a[pos];
    if(!sum[c[a[pos]]]){
        st.erase(c[a[pos]]);
    }
    c[a[pos]]++;
    if(!sum[c[a[pos]]]){
        st.insert(c[a[pos]]);
    }
    sum[c[a[pos]]]+=a[pos];
}
inline void del(int pos){
    sum[c[a[pos]]]-=a[pos];
    if(!sum[c[a[pos]]]){
        st.erase(c[a[pos]]);
    }
    c[a[pos]]--;
    if(!sum[c[a[pos]]]){
        st.insert(c[a[pos]]);
    }
    sum[c[a[pos]]]+=a[pos]; 
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int n,m;
    n=read();
    m=read();
    for(int i=1;i<=n;i++){
        a[i]=read();
    }
    for(int i=1;i<=m;i++){
        que[i].l=read(),que[i].r=read(),que[i].p=read();
        que[i].id=i;
    }
    mi=sqrt(n)+1;
    int blo=n/sqrt(m);
    int t=ceil(1.0*n/blo);
    for(int i=1;i<=t;i++){
        L[i]=(i-1)*blo+1;
        R[i]=i*blo;
    }
    R[t]=n;
    for(int i=1;i<=t;i++){
        for(int j=L[i];j<=R[i];j++){
            pos[j]=i;
        }
    }
    sort(que+1,que+1+m);
    int l=1,r=0;
    for(int i=1;i<=m;i++){
        while(que[i].l<l){
            add(--l);
        }
        while(que[i].l>l){
            del(l++);
        }
        while(que[i].r>r){
            add(++r);
        }
        while(que[i].r<r){
            del(r--);
        }
        init(que[i].p);
        ans[que[i].id]=query(que[i].l,que[i].r,que[i].p);
    }
    for(int i=1;i<=m;i++){
        cout<<ans[i]<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 6.66667
Accepted
time: 474ms
memory: 9084kb

input:

100000 100000
4914 8501 4785 2053 6350 9180 1945 4406 1096 4881 9969 5901 3473 5233 1929 9521 30 8643 5126 7771 2503 8992 3901 9046 6241 2795 3780 3025 101 3316 3293 5066 3721 7209 2603 5061 6465 6114 6305 1511 3457 5726 9821 4405 8022 5017 1903 5931 4409 8829 2525 9109 2766 2256 9447 5797 8400 7003...

output:

40315539
106546044
233248171
265492583
271416182
42200552
6680757
26717959
17952368
5054508
28560901
69548568
14795316
100858342
170969088
18157552
2717211
77720904
244854959
524452254
21977576
79023241
34917916
35340341
208311246
621496024
18068428
1752558
60498376
107090795
14540503
124378732
4986...

result:

ok 100000 numbers

Test #2:

score: 6.66667
Accepted
time: 657ms
memory: 8424kb

input:

100000 100000
976 898 281 385 823 529 170 997 225 56 731 707 497 489 651 585 321 177 451 332 887 653 949 841 261 833 411 611 889 86 146 449 553 241 411 504 562 849 876 882 1 505 193 657 766 511 844 472 101 999 221 921 612 417 695 506 29 853 865 810 551 544 76 971 737 865 696 507 511 609 265 417 411 ...

output:

85307308
179442224
11468184
235946992
101892866
147877938
73544265
111587072
115949118
141676740
92370322
361991365
13904102
8632192
10606147
1772230
316505395
95888005
174096124
126423240
270436182
88762528
13668140
76588284
24175243
2969919
78311619
166675579
45126668
15107778
426640022
1429094
20...

result:

ok 100000 numbers

Test #3:

score: 6.66667
Accepted
time: 1484ms
memory: 8696kb

input:

100000 100000
1 45 51 31 53 40 85 21 49 1 71 41 21 31 7 23 37 86 59 16 28 25 76 35 23 45 18 15 81 7 45 45 1 11 69 2 89 93 69 81 41 37 96 4 51 65 96 28 26 97 51 93 66 65 5 56 56 1 31 32 95 3 51 30 31 98 61 66 75 23 41 51 60 91 3 49 89 41 61 77 86 75 15 21 77 29 90 1 96 17 13 26 26 74 81 51 44 76 29 2...

output:

11435621
12665510
134030270
7578021
79217075
118628851
53592716
25072354
662410817
181298594
283128727
70508202
19918197
4545153
199110312
10538822
1906900
178463614
28349138
41555029
15745656
195215046
689973
7424908
92097391
317101752
603463919
457779999
80887965
329446772
1645744
188301756
405307...

result:

ok 100000 numbers

Test #4:

score: 6.66667
Accepted
time: 1798ms
memory: 9020kb

input:

100000 100000
1 7 1 1 7 1 9 1 9 6 1 1 1 1 1 5 7 8 6 4 7 1 8 3 1 3 3 1 3 1 5 9 1 1 9 1 6 6 3 2 8 5 6 9 1 3 1 1 7 9 5 6 10 9 5 6 1 5 7 7 4 1 1 9 6 3 3 7 1 7 1 1 3 1 7 1 1 1 5 5 2 9 1 7 9 8 1 1 1 1 1 5 9 9 7 10 1 5 2 4 1 9 1 2 5 6 7 4 1 8 1 3 9 1 6 2 1 2 1 4 6 7 10 5 1 1 9 6 9 9 5 8 7 7 3 7 1 9 3 1 1 1...

output:

29827198
258512101
21600595
519825880
5148274
69078970
7638838
101167
190383980
19279894
492179658
259400877
17163616
8434673
331278387
133472328
17873945
782182314
38612589
356884473
22557349
20451224
26551174
65358483
118781943
473586
44544013
153627112
171646184
46156370
16105358
207330371
494352...

result:

ok 100000 numbers

Test #5:

score: 6.66667
Accepted
time: 460ms
memory: 9264kb

input:

100000 100000
9321 40734 87649 86401 26921 4597 69741 67585 46149 5467 88709 80996 13207 62721 31683 86221 45645 69503 17770 92296 44721 67767 80077 12243 98674 58331 42769 23003 22273 57004 2981 11541 60468 26280 13761 88462 87708 21862 25592 70505 41362 51873 92096 20393 55725 65450 41803 56364 80...

output:

160731452
40621558
5307061
260846555
52711919
190750099
321065391
18485934
2668194
37503404
7691089
16127253
3372897
372185862
3602447
12044147
54403648
26873670
254106375
21456259
87933549
2046427
90720712
40625716
489321152
509410542
8636418
64250353
2845562
5423616
566575411
251120711
77340105
11...

result:

ok 100000 numbers

Test #6:

score: 6.66667
Accepted
time: 710ms
memory: 8992kb

input:

100000 100000
325 402 386 322 428 381 431 364 362 432 180 422 282 430 360 346 290 381 419 361 369 440 400 426 315 160 380 227 375 444 402 434 408 409 412 374 428 183 314 295 382 435 394 374 423 419 165 446 429 374 440 323 409 398 422 425 372 437 401 442 440 439 390 444 414 432 363 431 96 361 363 441...

output:

39955312
69528426
482932708
13147886
150454048
139514830
22416970
109249493
30583951
359918040
25394790
82603277
29776123
23166908
13791709
78074123
305018132
474804694
32279116
320620800
610212620
54008298
223056419
12171701
346333158
669396875
372830603
164378479
116793118
274792596
235027428
2338...

result:

ok 100000 numbers

Test #7:

score: 6.66667
Accepted
time: 779ms
memory: 7968kb

input:

100000 100000
380 300 322 422 444 402 370 435 431 394 439 63 445 373 434 442 397 255 376 377 427 445 365 297 250 436 408 409 395 255 345 440 437 420 250 307 387 392 396 433 434 406 427 324 422 352 343 180 339 446 436 40 409 433 255 402 446 419 379 447 422 394 409 446 262 318 346 427 268 405 339 406 ...

output:

45092623
25332126
492804723
61180177
316698378
170439
145926242
61137420
126472272
617744
321032069
53534362
60716631
39408953
151893780
29120366
9062212
50880806
19858010
88569220
30853120
16184192
11247316
312530796
33474399
107327881
51890462
77163583
77643977
13356
281365671
75174544
132097840
1...

result:

ok 100000 numbers

Test #8:

score: 6.66667
Accepted
time: 724ms
memory: 8748kb

input:

100000 100000
51531 28801 78289 42703 29609 38481 51601 27721 51753 25831 5377 37951 31637 58349 24545 93841 61209 11677 12957 7228 47459 32771 94753 34602 91638 6075 43809 70521 5161 67908 84425 62793 76982 84861 13701 72412 42915 41553 86665 55721 71371 70126 92061 31821 59546 69851 88835 48751 11...

output:

7093834
876491916
742519745
5076034
241349598
52762889
386225536
313061584
12006155
49517265
21565628
407860628
28914227
189537418
25730315
179364826
24617712
219780297
336091847
30925755
226868783
97825084
287114112
136057380
10987708
23154220
6406793
75748735
206590348
26254919
170143726
2734624
1...

result:

ok 100000 numbers

Test #9:

score: 6.66667
Accepted
time: 752ms
memory: 9040kb

input:

100000 100000
1411 71384 2297 24889 52849 7501 80601 73765 44636 56881 39786 30989 60401 42169 87026 5001 87621 46141 66085 60641 76165 58943 11873 29633 54677 70057 55509 39905 92860 35891 75141 85467 2799 18393 90225 45182 38401 3429 92349 87398 98661 13644 51521 33171 49377 78559 28731 31481 2493...

output:

7383246
367967594
1203235
11315763
76847974
204586678
132201964
289451944
307905128
434035539
85756146
32650307
15820829
136532472
81262662
1998998
485900
154583735
294536297
254116052
739654862
55286134
6567846
10827725
8982454
3070598
2030054
102834284
92113318
18295251
331116629
306760767
9675228...

result:

ok 100000 numbers

Test #10:

score: 6.66667
Accepted
time: 660ms
memory: 8400kb

input:

100000 100000
54555 76849 58071 71436 17417 89229 12321 31697 4198 92997 88273 87857 51857 79047 66681 69644 52691 79481 90949 73266 22477 77221 23057 61645 30081 78733 61036 82229 79858 29313 68515 28346 74653 66801 23013 58949 1757 29206 23149 83677 66525 73667 32977 93184 46661 84616 22633 58754 ...

output:

316795859
577528
8920206
81341052
14102193
139984036
1500780
435592683
15710884
3349908
6825386
7471362
48258988
9858988
6454574
29722694
20389817
7659398
4037507
4177042
514918824
153918333
66944761
30084022
60724825
103672224
28792867
2042226
336541396
96056159
143354883
14683221
59938900
286151
7...

result:

ok 100000 numbers

Test #11:

score: 6.66667
Accepted
time: 666ms
memory: 8992kb

input:

100000 100000
92481 69505 85271 90286 19484 44209 19726 35431 45701 83397 89723 74315 18013 27513 89933 43387 98288 54279 29816 93781 71041 65001 18898 37473 5277 68988 23065 27268 27678 41971 57841 26497 7591 11061 90911 27656 20665 801 27337 31213 80675 55150 48339 1481 5947 66231 14909 3485 72818...

output:

43661562
394875774
132634590
783947140
172526710
2254410
176186593
363864731
251503493
105990464
4665472
372609792
16770835
7179764
11403498
247387508
67067135
168325050
44652780
39683598
66104566
825989971
7011716
94215549
7904678
15065972
26557306
229136145
405771585
69797
81786342
67935877
125803...

result:

ok 100000 numbers

Test #12:

score: 6.66667
Accepted
time: 745ms
memory: 8328kb

input:

100000 100000
63105 84240 58943 14380 77191 96548 18355 79505 26491 43891 2732 62409 49166 45054 46185 51113 6549 13732 9205 54521 67269 41121 75111 2081 51303 9781 33883 10277 3605 14685 5754 85304 95421 51973 23333 92900 3 68351 44423 44145 58305 97441 86417 21770 20814 12197 46501 68929 90021 319...

output:

89481804
362032852
393670848
385167996
44435683
46369688
601946
13169992
103912253
222072436
235440860
257139318
6590765
19107052
267980445
313939810
125135424
28305072
139572627
558652756
46808386
337912402
526856504
1345152
209070280
38912439
8702272
6314304
64132754
191956425
8469989
30283830
990...

result:

ok 100000 numbers

Test #13:

score: 6.66667
Accepted
time: 754ms
memory: 8892kb

input:

100000 100000
52148 58762 78421 23093 10789 46125 93929 89937 40209 20976 15185 68544 24380 69341 94097 82866 74989 18183 33855 84586 92964 68021 24125 32375 95473 44529 88272 57541 36545 35241 49512 5036 22737 20006 50365 66701 94213 94437 20865 73481 61897 87612 88367 24217 79151 71594 1933 45341 ...

output:

27436793
59585040
184304482
384203868
278892907
175246824
330310726
9936467
396674914
311413832
103604859
107666838
156855329
68620051
434153708
605445316
346538362
43519321
172131474
4873151
4685000
132622120
36194690
52057540
269597952
118675345
2785484
31403568
79553666
113641305
127821301
458210...

result:

ok 100000 numbers

Test #14:

score: 6.66667
Accepted
time: 1007ms
memory: 9340kb

input:

100000 100000
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15 1...

output:

1334132
66783084
28014636
173861085
43469826
86442788
145591449
14154336
134773292
8593270
141864974
6121082
148131318
97998648
29155162
39928058
72233582
155573008
196387776
62476037
16531321
12889687
102356137
79642186
89056833
538067
269826549
173382258
221298283
143015110
79847968
30971852
96113...

result:

ok 100000 numbers

Test #15:

score: 6.66667
Accepted
time: 856ms
memory: 8692kb

input:

100000 100000
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15 1...

output:

78165963
702909759
46443726
40262984
9321756
171667848
28655679
25196135
266273120
23474468
554424074
49536201
773467372
30888914
75577712
196381920
178356755
241704473
435944
276571699
22147456
222139867
13076705
83522162
86254072
64609334
75373064
30754599
26457856
2631270
50962403
46806362
111669...

result:

ok 100000 numbers

Extra Test:

score: 0
Extra Test Passed