QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#190557#4103. 生成魔咒Qingyu100 ✓83ms84648kbRust1.9kb2023-09-29 04:10:272023-09-29 04:10:29

Judging History

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

  • [2023-09-29 04:10:29]
  • 评测
  • 测评结果:100
  • 用时:83ms
  • 内存:84648kb
  • [2023-09-29 04:10:27]
  • 提交

answer

#![allow(non_upper_case_globals, unused_imports)]

use std::cmp::{max, min};
use std::collections::BTreeMap;
use std::io::{self, BufRead, Write};

const sz: usize = 2e6 as usize + 10;
static mut size: usize = 0;
static mut last: usize = 0;
static mut ans: u64 = 0;
static mut fa: [usize; sz] = [0; sz];
static mut len: [usize; sz] = [0; sz];
static mut ch: Vec<BTreeMap<usize, usize>> = Vec::new();
static mut null: usize = 0;

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    unsafe {
        solve(stdin.lock(), stdout.lock());
    }
}

unsafe fn solve<R, W>(mut input: R, mut output: W)
where
    R: BufRead,
    W: Write,
{
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    buf.clear();
    ch.resize(sz, BTreeMap::new());
    input.read_line(&mut buf).unwrap();
    let arg: Vec<usize> = buf
        .split_whitespace()
        .map(|s| s.parse::<usize>().unwrap())
        .collect();
    size = 1;
    last = 1;
    for i in arg.iter() {
        insert(*i);
        writeln!(output, "{}", ans).unwrap();
    }
}

unsafe fn insert(x: usize) {
    size += 1;
    let np = size;
    let mut p = last;
    last = np;
    len[last] = len[p] + 1;
    let q;
    while p != null && ch[p].get(&x) == None {
        ch[p].insert(x, np);
        p = fa[p];
    }
    if p == null {
        fa[size] = 1;
    } else {
        q = *ch[p].get(&x).unwrap();
        if len[q] == len[p] + 1 {
            fa[np] = q;
        } else {
            size += 1;
            let nq = size;
            len[nq] = len[p] + 1;
            fa[nq] = fa[q];
            fa[q] = nq;
            fa[np] = nq;
            ch[nq] = ch[q].clone();
            while p != null && ch[p].get(&x) == Some(&q) {
                ch[p].insert(x, size);
                p = fa[p];
            }
        }
    }
    ans += (len[np] - len[fa[np]]) as u64;
}

详细

Test #1:

score: 10
Accepted
time: 10ms
memory: 49060kb

input:

10
284481732 681129159 911669271 284481732 284481732 284481732 587356940 284481732 911669271 681129159

output:

1
3
6
9
13
17
24
31
39
48

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 12ms
memory: 49076kb

input:

80
665546003 145901544 665546003 145901544 665546003 710875624 710875624 24099234 612035736 145901544 629832890 13962423 757182437 665546003 665546003 145901544 665546003 612035736 665546003 665546003 145901544 145901544 13962423 665546003 665546003 665546003 13962423 145901544 145901544 710875624 7...

output:

1
3
5
7
9
15
21
29
38
47
58
70
83
96
110
124
138
155
173
191
209
230
252
275
298
322
348
375
402
431
460
491
523
555
587
622
657
693
729
767
806
845
886
929
972
1015
1060
1105
1151
1197
1245
1294
1346
1398
1450
1504
1560
1617
1675
1733
1791
1852
1914
1976
2038
2103
2168
2234
2300
2366
2436
2506
2576...

result:

ok 80 lines

Test #3:

score: 10
Accepted
time: 16ms
memory: 49020kb

input:

91
891583761 491854419 891583761 891583761 795942648 957281584 891583761 891583761 957281584 891583761 795942648 891583761 795942648 585186976 795942648 795942648 795942648 891583761 795942648 795942648 795942648 891583761 795942648 891583761 795942648 491854419 891583761 795942648 957281584 9572815...

output:

1
3
5
8
13
19
25
31
39
47
56
67
78
92
106
121
136
152
168
186
204
222
240
261
282
307
332
358
384
413
443
473
506
539
573
608
645
682
719
757
797
837
877
920
964
1008
1052
1098
1146
1194
1243
1294
1345
1398
1451
1507
1563
1619
1675
1734
1793
1852
1914
1976
2039
2103
2168
2233
2299
2367
2436
2506
257...

result:

ok 91 lines

Test #4:

score: 10
Accepted
time: 10ms
memory: 51332kb

input:

859
171625140 171625140 171625140 205951597 205951597 171625140 171625140 205951597 171625140 171625140 468520557 205951597 205951597 171625140 468520557 171625140 171625140 205951597 171625140 171625140 205951597 468520557 205951597 205951597 171625140 205951597 171625140 171625140 205951597 205951...

output:

1
2
3
7
11
16
21
26
33
40
51
62
73
84
97
112
127
142
157
172
189
210
231
252
273
297
321
345
369
395
424
453
484
515
546
577
612
647
682
719
757
795
834
873
912
955
998
1042
1088
1134
1181
1230
1280
1330
1380
1432
1485
1539
1594
1649
1705
1764
1823
1883
1943
2003
2064
2129
2194
2262
2330
2398
2466
2...

result:

ok 859 lines

Test #5:

score: 10
Accepted
time: 13ms
memory: 49340kb

input:

900
785593309 785593309 785593309 785593309 448521196 448521196 785593309 448521196 785593309 448521196 448521196 450327548 785593309 603330951 785593309 785593309 785593309 448521196 785593309 448521196 450327548 603330951 785593309 603330951 603330951 448521196 448521196 448521196 785593309 448521...

output:

1
2
3
4
9
14
20
26
33
40
48
60
72
86
100
114
128
142
158
174
193
214
235
257
281
306
331
357
383
409
435
461
490
522
556
591
626
661
696
732
768
804
840
876
916
960
1005
1051
1097
1144
1191
1238
1285
1332
1379
1426
1481
1536
1593
1652
1711
1770
1829
1890
1952
2016
2080
2145
2210
2275
2340
2405
2474
...

result:

ok 900 lines

Test #6:

score: 10
Accepted
time: 16ms
memory: 49252kb

input:

732
646823165 646823165 904422767 904422767 646823165 904422767 646823165 610473160 646823165 904422767 904422767 975813742 904422767 904422767 904422767 904422767 586406717 586406717 904422767 646823165 904422767 210234031 646823165 646823165 975813742 904422767 646823165 904422767 210234031 646823...

output:

1
2
5
8
12
16
21
29
37
45
53
65
77
89
102
115
132
149
167
185
203
225
247
269
293
317
342
367
392
417
442
471
501
532
564
597
630
664
698
735
776
817
858
899
942
985
1028
1074
1122
1170
1218
1266
1315
1368
1422
1476
1530
1584
1641
1698
1755
1812
1869
1929
1993
2057
2121
2185
2251
2319
2387
2455
2523...

result:

ok 732 lines

Test #7:

score: 10
Accepted
time: 68ms
memory: 84580kb

input:

98429
899472697 636003270 899472697 899472697 467701280 636003270 915227486 899472697 899472697 467701280 899472697 467701280 915227486 467701280 324048526 467701280 467701280 899472697 39513526 467701280 636003270 324048526 467701280 636003270 65759607 899472697 39513526 636003270 899472697 8994726...

output:

1
3
5
8
13
18
25
32
39
46
56
66
78
91
106
121
137
153
172
191
210
231
252
274
299
324
349
376
403
430
460
491
522
553
587
621
658
695
732
769
806
846
888
931
974
1018
1062
1108
1155
1202
1249
1298
1347
1400
1453
1508
1563
1619
1677
1735
1793
1853
1913
1973
2033
2095
2157
2221
2288
2356
2425
2494
256...

result:

ok 98429 lines

Test #8:

score: 10
Accepted
time: 39ms
memory: 76616kb

input:

81570
84449732 976836655 976836655 961734130 776380437 776380437 84449732 776380437 976836655 976836655 976836655 776380437 776380437 138164411 776380437 776380437 84449732 976836655 823024381 976836655 84449732 776380437 776380437 990792200 509314294 776380437 776380437 823024381 976836655 97683665...

output:

1
3
5
9
14
19
25
32
40
48
57
68
79
93
107
121
135
151
170
189
209
229
250
274
299
324
349
376
403
431
462
493
524
556
589
623
659
696
733
770
808
848
888
929
971
1013
1058
1103
1152
1201
1251
1301
1351
1401
1453
1508
1563
1620
1677
1736
1795
1856
1917
1978
2041
2106
2172
2238
2304
2372
2440
2511
258...

result:

ok 81570 lines

Test #9:

score: 10
Accepted
time: 51ms
memory: 84648kb

input:

89963
528402587 2569956 528402587 2569956 528402587 2569956 906602731 2569956 528402587 528402587 2569956 2569956 2569956 528402587 528402587 906602731 528402587 528402587 20199743 528402587 906602731 2569956 2569956 528402587 528402587 2569956 2569956 2569956 2569956 528402587 528402587 528402587 9...

output:

1
3
5
7
9
11
18
25
32
41
50
61
72
84
96
111
127
143
162
181
200
220
241
262
283
305
327
349
375
401
427
457
487
517
550
583
617
651
687
724
761
801
841
882
924
967
1010
1053
1098
1144
1190
1239
1288
1337
1386
1440
1496
1553
1610
1667
1724
1785
1847
1909
1971
2034
2099
2164
2230
2299
2368
2438
2509
2...

result:

ok 89963 lines

Test #10:

score: 10
Accepted
time: 83ms
memory: 80172kb

input:

87804
36898514 56462380 437198812 36898514 437198812 36898514 437198812 36898514 409594298 437198812 36898514 31665100 36898514 36898514 484501120 437198812 36898514 527881758 339320197 409594298 437198812 437198812 56462380 31665100 437198812 36898514 476683124 437198812 36898514 36898514 437198812...

output:

1
3
6
9
13
17
21
25
34
43
52
64
76
89
104
119
134
152
171
190
209
230
252
275
299
323
350
377
404
432
461
491
523
556
589
625
661
698
736
774
812
852
892
935
979
1023
1069
1115
1162
1209
1257
1307
1357
1410
1464
1518
1573
1629
1685
1742
1801
1861
1921
1984
2047
2111
2175
2239
2305
2371
2439
2508
257...

result:

ok 87804 lines