UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205411#3685. 求和Daniel102410018251ms176108kbC++3.2kb2024-07-04 09:12:122024-07-04 13:03:52

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)(3033353539)
#define mod1 (int)(47)
#define mod2 (int)(mod/47)
int n, q;
int a[100005];
int f[2][400005][42];
int tag[400005];
pair<int, int> operator+(pair<int, int> x, pair<int, int> y){
    return make_pair((x.first + y.first) % mod1, (x.second + y.second) % mod2);
}
void up(int now){
    for(int i = 0; i < 11; i++){
        f[0][now][i] = f[0][now * 2][i] + f[0][now * 2 + 1][i];
        f[0][now][i] %= mod1;
    }
    for(int i = 0; i < 42; i++){
        f[1][now][i] = f[1][now * 2][i] + f[1][now * 2 + 1][i];
        f[1][now][i] %= mod2;
    }
}
int nw[42];
void wy(int p, int w){
    for(int i = 0; i < 11; i++){
        nw[i] = f[0][p][(i+w)%11];
    }
    for(int i = 0; i < 11; i++){
        f[0][p][i] = nw[i];
    }
    for(int i = 0; i < 42; i++){
        nw[i] = f[1][p][(i+w)%42];
    }
    for(int i = 0; i < 42; i++){
        f[1][p][i] = nw[i];
    }
}   
void down(int now){
    if(tag[now]){
        tag[now * 2] += tag[now];
        tag[now * 2 + 1] += tag[now];
        wy(now * 2, tag[now]);
        wy(now * 2 + 1, tag[now]);
        tag[now] = 0;
    }
}
void init_(int now, int x){
    f[0][now][0] = x % mod1;
    f[1][now][0] = x % mod2;
    for(int i = 1; i < 11; i++){
        f[0][now][i] = f[0][now][i - 1] * f[0][now][i - 1] % mod1 * f[0][now][i - 1] % mod1;
    }
    for(int i = 1; i < 42; i++){
        f[1][now][i] = f[1][now][i - 1] * f[1][now][i - 1] % mod2 * f[1][now][i - 1] % mod2;
    }
}
void init(int now, int l, int r){
    if(l == r){
        init_(now, a[l]);
        return;
    }
    int mid = l+r>>1;
    init(now * 2, l, mid);
    init(now * 2 + 1, mid + 1, r);
    up(now);
}
void change(int now, int l, int r, int x, int y){
    if(l == r){
        init_(now, y);
        return;
    }
    down(now);
    int mid = l+r>>1;
    if(x <= mid)change(now * 2, l, mid, x, y);
    else change(now * 2 + 1, mid + 1, r, x, y);
    up(now);
}
void run(int now, int l, int r, int x, int y){
    if(x <= l && r <= y){
        wy(now, 1);
        tag[now]++;
        return;
    }
    down(now);
    int mid = l+r>>1;
    if(x <= mid)run(now * 2, l, mid, x, y);
    if(y > mid)run(now * 2 + 1, mid + 1, r, x, y);
    up(now);
}
pair<int, int> query(int now, int l, int r, int x, int y){
    if(x <= l && r <= y){
        return make_pair(f[0][now][0], f[1][now][0]);
    }
    down(now);
    int mid = l+r>>1;
    pair<int, int> ans = make_pair(0, 0);
    if(x <= mid)ans = ans + query(now * 2, l, mid, x, y);
    if(y > mid)ans = ans + query(now * 2 + 1, mid + 1, r, x, y);
    return ans;
}
int solve(pair<int, int> x){
    int nw = x.second;
    while(nw % mod1 != x.first)nw += mod2;
    return nw;
}
signed main(){
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        scanf("%lld", &a[i]);
    }
    init(1, 1, n);
    while(q--){
        int op, x, y;
        scanf("%lld%lld%lld", &op, &x, &y);
        if(op == 1){
            printf("%lld\n", solve(query(1, 1, n, x, y)));
        }else if(op == 2){
            change(1, 1, n, x, y);
        }else{
            run(1, 1, n, x, y);
        }
    }
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 39ms
memory: 11904kb

input:

4995 5000
560337090 315168300 87037480 226298476 498745286 697301138 962175775 284875741 822056078 9...

output:

1564280593
2901089576
2543436300
2029819357
1465456354
905823468
2505643226
1482243886
366385314
286...

result:

ok 1000 lines

Test #2:

score: 5
Accepted
time: 39ms
memory: 11900kb

input:

4998 5000
906185813 302664385 690506381 612173700 83595446 564728431 362186210 75677780 199510901 23...

output:

366975603
1291712896
3028470789
2218278957
711414362
1084654342
2643719409
2609537057
2672035525
251...

result:

ok 2000 lines

Test #3:

score: 5
Accepted
time: 44ms
memory: 11900kb

input:

5000 5000
944608531 293232814 233228275 344230634 375212913 469372875 541571291 885290257 99237637 8...

output:

2251887898
789581056
2395886414
2471693861
873590913
2590951722
1561866760
311255510
1430111689
6568...

result:

ok 1000 lines

Test #4:

score: 5
Accepted
time: 29ms
memory: 11904kb

input:

5000 5000
365703965 520397431 202066254 763498793 940012061 368650322 498437006 652583440 778046167 ...

output:

334838188
2846920511
2996159937
866851786
2196903287
686704404
3030536222
714465008
2330464045
84269...

result:

ok 3000 lines

Test #5:

score: 5
Accepted
time: 414ms
memory: 174056kb

input:

99995 100000
627170516 806450977 796922038 712179637 20889986 224118490 752278359 269194617 32795538...

output:

45029487
2625791217
152410644
871516773
1607825256
2064173865
745920046
2464417012
1563607020
103042...

result:

ok 50000 lines

Test #6:

score: 5
Accepted
time: 372ms
memory: 174052kb

input:

100000 100000
464588555 573022233 446880891 58600071 173178884 950878909 169487783 496590025 2434310...

output:

3006294435
1576428888
1387843447
1670866068
943068978
1085639764
90023288
2919040082
872445378
36777...

result:

ok 50000 lines

Test #7:

score: 5
Accepted
time: 1532ms
memory: 176100kb

input:

100000 100000
128106965 244896481 262127896 59073304 381228901 148793441 977137490 927946509 3356326...

output:

2116716101
755786427
1331864207
1730997090
2341687922
2847284146
1459379932
598765073
2216787053
160...

result:

ok 50000 lines

Test #8:

score: 5
Accepted
time: 1062ms
memory: 176104kb

input:

100000 100000
767696177 720383168 808335697 722349953 439945810 830624928 520319481 313343600 214585...

output:

2339082075
62828403
2195585841
1935433704
64274176
1419349799
2624432662
993775168
2596026906
258698...

result:

ok 50000 lines

Test #9:

score: 5
Accepted
time: 1035ms
memory: 176100kb

input:

100000 100000
264358139 968461196 756795022 853885063 274424020 197587187 971944767 789468237 984948...

output:

2957543122
2513050060
1174773260
2753837783
437919605
2983055953
230346152
2174210858
1214719813
213...

result:

ok 50000 lines

Test #10:

score: 5
Accepted
time: 1122ms
memory: 176104kb

input:

100000 100000
1 0 1 1 0 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 0 0 1 1 1 0 0 0 1 0 1 ...

output:

1182327475
1543628977
2603101091
566552174
4079
10782
2151114638
906548030
4253
1534846777
364146938...

result:

ok 50000 lines

Test #11:

score: 5
Accepted
time: 1266ms
memory: 176108kb

input:

100000 100000
1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 1 0 0 1 0 0 0 0 0 1 1 0 ...

output:

143751215
1915618096
2692274671
3033035046
4334
5307
1535491733
305257590
795330224
2272
737763079
2...

result:

ok 50000 lines

Test #12:

score: 5
Accepted
time: 1344ms
memory: 176104kb

input:

100000 100000
0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 ...

output:

5604
6890
16174
28536
17289
5985
367770048
1896877952
2075263174
17217
2368791483
1356
332727398
172...

result:

ok 50000 lines

Test #13:

score: 5
Accepted
time: 1444ms
memory: 176104kb

input:

100000 100000
0 0 1 1 1 0 1 1 1 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 0 0 0 ...

output:

31662
2115152038
9432
20962
23223
7709
20668
22892191
1749383918
40384
19622
6451
1047695402
5381
36...

result:

ok 50000 lines

Test #14:

score: 5
Accepted
time: 1448ms
memory: 176108kb

input:

100000 100000
0 1 0 0 0 1 1 1 1 0 0 1 0 0 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1 0 ...

output:

27888
165800994
811556047
23834
15730
141919810
5540
1617
5927
10993
9845
22042
24142
23836
9954
179...

result:

ok 50000 lines

Test #15:

score: 5
Accepted
time: 647ms
memory: 88676kb

input:

50000 50000
390746953 681901037 828965529 50770778 327055854 333375483 246994426 340769414 755377378...

output:

1371476568
1161490571
2348256916
2550229371
1981015932
2188916164
2737471812
2571518909
2507666314
2...

result:

ok 25000 lines

Test #16:

score: 5
Accepted
time: 708ms
memory: 88676kb

input:

50000 50000
683221234 802599934 78075342 62624912 536548902 741273036 802706556 303127706 20802826 2...

output:

1802485830
344530573
2330804597
1425044138
83037080
1094635341
65176435
3031579318
541924388
1309599...

result:

ok 25000 lines

Test #17:

score: 5
Accepted
time: 776ms
memory: 88672kb

input:

50000 50000
110613812 818097004 808739705 780789270 811394320 159608379 808593739 710296230 47127950...

output:

1270713823
476222922
2593312745
795410080
2585596251
2009499259
1008189839
1084036998
2654987563
264...

result:

ok 25000 lines

Test #18:

score: 5
Accepted
time: 1770ms
memory: 176100kb

input:

100000 100000
405840180 238771696 544776256 420336487 361103209 350223118 119987822 750812810 222024...

output:

92392772
1374682987
1642284458
173568578
2231629359
938784939
2378987064
2449282846
1932349380
42967...

result:

ok 50000 lines

Test #19:

score: 5
Accepted
time: 1544ms
memory: 176100kb

input:

100000 100000
650731749 17818698 895081643 426908086 775431749 508657623 133114974 912107958 7636584...

output:

2483982014
968757493
1506704358
223628691
849152893
788276515
2095226878
1597718692
2067398254
17518...

result:

ok 50000 lines

Test #20:

score: 5
Accepted
time: 1616ms
memory: 176100kb

input:

100000 100000
209917094 864085355 999275861 663773621 166200908 364331894 275548653 461370070 226189...

output:

750283000
1749509447
2376030834
2596272571
2318896921
1806435985
1753492692
2628350756
2796900231
16...

result:

ok 50000 lines