QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#76663#8. 奇数国Alkaid100 ✓92ms11156kbC++202.5kb2023-02-11 19:23:142023-02-11 19:23:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-11 19:23:18]
  • 评测
  • 测评结果:100
  • 用时:92ms
  • 内存:11156kb
  • [2023-02-11 19:23:14]
  • 提交

answer

#pragma GCC optimize(2) 
#include <bits/stdc++.h>
#define N 100010
#define lc o << 1
#define rc o << 1 | 1
#define mid ((l + r) >> 1)
#define int long long

using namespace std;

int n, a[N], tot, iv[N];

const int m = 100000;
const int mod = 19961993;

struct Tree {
    int mul;
    bitset <62> arr;
}t[N * 4];

inline void up(int o) {
    t[o].mul = t[lc].mul * t[rc].mul % mod;
    t[o].arr = t[lc].arr | t[rc].arr;
}

inline int power(int a, int b) {
    int res = 1;
    while(b) {
        if(b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
} 

void change(int o, int l, int r, int pos, int val) {
    if(l == r) {
        t[o].mul = val;
        t[o].arr.reset();
        for(int i = 0; i < tot; i++) {
            if(val % a[i] == 0)
                t[o].arr.set(i);
        }
        return;
    }

    if(pos <= mid)
        change(lc, l, mid, pos, val);
    else
        change(rc, mid + 1, r, pos, val);
    up(o);
}

inline int check(int x) {
    for(int i = 2; i * i <= x; i++) {
        if(x % i == 0)
            return 0;        
    }
    return 1;
}

bitset <62> tmp;
int res = 1;

void query(int o, int l, int r, int ql, int qr) {
    if(ql <= l && r <= qr) {
        res = res * t[o].mul % mod;
        tmp |= t[o].arr;
        return;
    }

    if(ql <= mid)
        query(lc, l, mid, ql, qr);
    if(qr > mid)
        query(rc, mid + 1, r, ql, qr);
}

void build(int o, int l, int r) {
    if(l == r) {
        t[o].mul = 3;
        t[o].arr.set(1);
        return;
    }
    build(lc, l, mid);
    build(rc, mid + 1, r);
    up(o);
}

inline int calc() {
    int ans = res;
    for(int i = 0; i < tot; i++) {
        if(tmp.test(i))
            ans = ans * (a[i] - 1) % mod * iv[i] % mod;
    }
    return ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T;
    cin >> T;

    for(int i = 2; i <= 281; i++) {
        if(check(i))
            a[tot++] = i, iv[tot - 1] = power(a[tot - 1], mod - 2);
    }

    build(1, 1, m);

    while(T--) {
        int op;
        cin >> op;
        if(op == 0) {
            int l, r;
            cin >> l >> r;
            tmp.reset();
            res = 1;
            query(1, 1, m, l, r);
            printf("%lld\n", calc());
        } else {
            int pos, val;
            cin >> pos >> val;
            change(1, 1, m, pos, val);
        }
    }
}

詳細信息

Test #1:

score: 10
Accepted
time: 2ms
memory: 10932kb

input:

122
1 47 84606
1 39 10304
0 31 46
0 47 50
1 16 80142
1 15 55620
1 56 8487
1 22 65813
0 17 28
1 45 73139
0 41 47
1 15 73640
1 40 44390
1 68 70490
0 63 69
0 39 40
0 12 16
1 25 3444
0 25 27
1 18 31800
1 60 89056
1 60 52890
0 53 60
0 53 60
1 63 3243
1 54 9100
0 51 59
1 35 36461
1 61 52428
0 55 61
1 50 6...

output:

3448280
745416
15367180
14289639
10917504
9491521
8175517
8640
9635568
9635568
19678455
3235156
5207440
5144376
17488754
8655822
28416
12480089
18015309
12629915
18671900
14434821
9925905
15636830
4782066
7369580
16162298
5905396
6846560
10589666
9483328
15896882
6423617
1311861
1578993
577687
15459...

result:

ok 54 lines

Test #2:

score: 10
Accepted
time: 6ms
memory: 10464kb

input:

10000
1 3204 2085
0 3193 3210
0 5567 5581
0 5070 5093
1 7744 53578
0 7726 7744
1 5938 90890
0 5933 5946
1 2282 404
0 2275 2293
0 5529 5552
0 5411 5427
1 1288 83658
1 1691 75254
1 8728 1909
1 9085 92560
0 9068 9085
0 8728 8731
1 6452 52632
0 6444 6458
0 1691 1704
0 1270 1288
0 5233 5248
0 5400 5420
0...

output:

2185946
9565938
4839678
9705858
5439877
14389309
4839678
6245470
8732244
32472
6583080
17055554
6296040
8735821
6833245
4839678
18
8735821
4839678
3883281
1547687
16285244
4839678
8931746
15555839
17586309
11215879
19586450
17798404
2232085
11637945
3722575
5172420
16573412
9266331
11329460
16785123...

result:

ok 4983 lines

Test #3:

score: 10
Accepted
time: 19ms
memory: 9700kb

input:

20000
0 4519 6399
0 5538 5991
0 5830 7147
1 5838 256887
0 5544 7321
1 3889 10561
1 2843 775260
0 1555 2973
0 2570 5389
0 5338 6500
1 9416 950309
1 5569 690690
1 3145 135315
1 2365 35167
1 3940 43
1 5310 5353
1 8337 568841
1 5796 169
1 3104 746130
0 2515 3432
1 10626 35611
0 8635 12588
1 10562 946774...

output:

1047614
6037414
3115948
9426030
17643323
4398595
1744917
1772208
10154868
2447480
16082590
15175137
11361553
13058625
8518416
11492582
19781466
14381365
13867763
18330162
7595955
15168974
6738709
14807205
4744226
16989783
9975850
7282007
15068475
18826700
8683432
4559401
684611
10302610
3761265
6088...

result:

ok 9926 lines

Test #4:

score: 10
Accepted
time: 34ms
memory: 10664kb

input:

30000
1 12080 458075
0 9890 15050
1 7144 149
0 4091 10808
1 5942 843378
0 2599 9264
1 9921 6647
0 6378 12730
1 8131 602651
0 5475 11565
1 9005 870870
0 6625 12774
1 11492 690690
0 8194 14863
1 4340 256
0 918 6863
1 7069 344488
0 3763 10001
1 12418 8192
0 9118 15941
1 11125 690690
0 8462 14279
1 9951...

output:

4210970
4685773
398991
650641
18472001
4784400
14943690
3438891
1995553
4032157
15097889
15356816
3064337
11934953
3343121
5041064
12645997
4605704
15279827
1160997
15541294
13329495
10559163
6441485
11411914
4067931
10545031
19425481
5479228
8237162
14047281
17690532
1926174
5889553
5468095
1042080...

result:

ok 15000 lines

Test #5:

score: 10
Accepted
time: 46ms
memory: 10880kb

input:

50000
1 29347 187726
0 25914 32532
1 20674 8192
0 15953 24784
1 24117 4752
0 19706 27975
1 22413 538
0 18457 27027
1 25177 931944
0 20749 29602
1 25822 52728
0 22542 28875
1 27405 746130
0 23587 31278
1 24494 24187
0 20318 27988
1 23628 85158
0 20006 28203
1 20524 24389
0 16166 24111
1 29127 733825
...

output:

1556121
15677403
672262
19172131
8198945
11686976
3839404
319175
6311620
7587994
17658897
14413678
3188607
6684463
12160545
2429119
960062
11841785
19202868
8805839
2853717
2189337
11918610
297217
12385352
9781987
1149808
2026027
5584558
15447179
15008815
12498467
4035295
4672760
7775541
11823473
92...

result:

ok 25000 lines

Test #6:

score: 10
Accepted
time: 65ms
memory: 10148kb

input:

60000
1 6 2
1 12 3
1 18 5
1 24 7
1 30 11
1 36 13
1 42 17
1 48 19
1 54 23
1 60 29
1 66 31
1 72 37
1 78 41
1 84 43
1 90 47
1 96 53
1 102 59
1 108 61
1 114 67
1 120 71
1 126 73
1 132 79
1 138 83
1 144 89
1 150 97
1 156 101
1 162 103
1 168 107
1 174 109
1 180 113
1 186 127
1 192 131
1 198 137
1 204 139
...

output:

4205032
4735146
1058042
15787465
2479203
19177313
1203515
11351507
12940314
13005578
17323708
1609093
17784151
3453554
7059698
18868749
6143711
19060208
11446441
15272149
5551899
8641623
17568183
13405468
8268092
4519992
15387075
2517231
13709782
16253486
1827527
12455426
3115997
18560570
4672979
53...

result:

ok 25084 lines

Test #7:

score: 10
Accepted
time: 57ms
memory: 10768kb

input:

70000
1 7 2
1 14 3
1 21 5
1 28 7
1 35 11
1 42 13
1 49 17
1 56 19
1 63 23
1 70 29
1 77 31
1 84 37
1 91 41
1 98 43
1 105 47
1 112 53
1 119 59
1 126 61
1 133 67
1 140 71
1 147 73
1 154 79
1 161 83
1 168 89
1 175 97
1 182 101
1 189 103
1 196 107
1 203 109
1 210 113
1 217 127
1 224 131
1 231 137
1 238 13...

output:

16484986
18831901
11872854
1174075
4598254
16905220
19177418
17281159
1940037
12628512
18582965
6755506
8098833
6459453
18582965
8296869
6976100
15356278
15453278
1305523
12446822
4844262
12446822
14973268
19842842
277602
19842842
16892039
8125774
13992217
14461453
4531759
13348432
10993871
6306877
...

result:

ok 44942 lines

Test #8:

score: 10
Accepted
time: 59ms
memory: 9980kb

input:

80000
1 8 2
1 16 3
1 24 5
1 32 7
1 40 11
1 48 13
1 56 17
1 64 19
1 72 23
1 80 29
1 88 31
1 96 37
1 104 41
1 112 43
1 120 47
1 128 53
1 136 59
1 144 61
1 152 67
1 160 71
1 168 73
1 176 79
1 184 83
1 192 89
1 200 97
1 208 101
1 216 103
1 224 107
1 232 109
1 240 113
1 248 127
1 256 131
1 264 137
1 272 ...

output:

11485550
7506222
14092162
18333503
10239196
3311779
1766560
3311779
14840124
11153996
4079448
951728
1621111
951728
17226635
5696610
16396463
3554456
5594198
9278211
17231052
9278211
10891233
639281
7661158
12922406
1230468
4579988
14563499
523385
718191
5965249
10715807
4915577
5965249
10715807
141...

result:

ok 40842 lines

Test #9:

score: 10
Accepted
time: 74ms
memory: 10604kb

input:

90000
1 9 2
1 18 3
1 27 5
1 36 7
1 45 11
1 54 13
1 63 17
1 72 19
1 81 23
1 90 29
1 99 31
1 108 37
1 117 41
1 126 43
1 135 47
1 144 53
1 153 59
1 162 61
1 171 67
1 180 71
1 189 73
1 198 79
1 207 83
1 216 89
1 225 97
1 234 101
1 243 103
1 252 107
1 261 109
1 270 113
1 279 127
1 288 131
1 297 137
1 306...

output:

17196202
19552301
10199336
12186738
11978447
19552301
10605585
10812205
12803489
10605585
16242675
14943802
10605585
11920483
6327792
16434396
6640216
6327792
6225078
7860493
2863293
14104546
7860493
10273832
4471381
6089705
6617445
6850228
2120250
6617445
14984860
3447100
6617445
8893003
4082656
10...

result:

ok 46743 lines

Test #10:

score: 10
Accepted
time: 92ms
memory: 11156kb

input:

100000
1 10 2
1 20 3
1 30 5
1 40 7
1 50 11
1 60 13
1 70 17
1 80 19
1 90 23
1 100 29
1 110 31
1 120 37
1 130 41
1 140 43
1 150 47
1 160 53
1 170 59
1 180 61
1 190 67
1 200 71
1 210 73
1 220 79
1 230 83
1 240 89
1 250 97
1 260 101
1 270 103
1 280 107
1 290 109
1 300 113
1 310 127
1 320 131
1 330 137
1...

output:

8431547
11098747
15587793
5209003
16796797
3125056
18173140
14606833
4895893
19634196
6464181
16859831
8471729
218769
14955328
4517038
1493678
7137991
11144631
15131702
1302603
17936428
13984170
3119361
11106457
7373221
17765477
19554966
9759356
8101464
11075850
5173366
5270006
12310730
3153884
9894...

result:

ok 67590 lines