QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#609968#5452. Tractor PathsDimash#6.25 169ms53604kbC++232.8kb2024-10-04 14:36:052024-10-04 14:36:06

Judging History

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

  • [2024-10-04 14:36:06]
  • 评测
  • 测评结果:6.25
  • 用时:169ms
  • 内存:53604kb
  • [2024-10-04 14:36:05]
  • 提交

answer

#include <bits/stdc++.h>
    
using namespace std;
    
typedef long long ll;
const int  N = 1e6 + 12, MOD = (int)1e9 + 7;

int n, q, d[N], up[N][19], l = 19, c[N][19], dep[N];

pair<int, int> t[N * 4];

void upd(int pos, int val, int v = 1, int tl = 1, int tr = n) {
    if(tl == tr) {
        t[v].first = val;
        t[v].second = tl;
    } else {
        int tm = (tl + tr) >> 1;
        if(pos <= tm) upd(pos, val, v + v, tl, tm);
        else upd(pos, val, v + v + 1, tm + 1, tr);
        t[v] = max(t[v + v], t[v + v + 1]);
    }
}

pair<int, int> get(int l, int r, int v = 1, int tl = 1, int tr = n) {
    if(l > r || tl > r || l > tr) return make_pair(0, 0);
    if(tl >= l && tr <= r) return t[v];
    int tm = (tl + tr) >> 1;
    return max(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr));
}
bool ok[N];
pair<int, int> solve(int v, int u) {
    int ret = 1, col = 0;
    for(int i = l - 1; i >= 0;i--) {
        if(up[v][i] < u) {
            ret += (1 << i);
            col += c[v][i];
            v = up[v][i];
        }
    }
    if(ok[v]) col++;
    if(ok[u]) col++;
    return make_pair(ret, col);
}
string s;
vector<int> vert[N];
void prec() {
    int it = 1, col = 0;
    for(int i = 1; i <= n + n; i++) {
        char x = s[i - 1];
        if(x == 'R') {
            col--;
            d[it++] = col;
        } else {
            col++;
        }
    }
    upd(n, n);
    for(int i = 0; i < l; i++) {
        up[n][i] = n;
    }
    for(int i = n - 1; i >= 1;i--) {
        int j = get(i + 1, i + d[i]).second;
        dep[i] = dep[j] + 1;
        up[i][0] = j;
        for(int k = 1; k < 19; k++) {
            up[i][k] = up[up[i][k - 1]][k - 1];
        }
        upd(i, i + d[i]);
    }
    for(int i = 1; i <= n; i++) {
        if(ok[i]) vert[dep[i]].push_back(i);
    }
    for(int i = 1; i <= n - 1; i++) {
        int j = up[i][0];
        int L = upper_bound(vert[dep[j]].begin(), vert[dep[j]].end(), i) - vert[dep[j]].begin();
        int R = lower_bound(vert[dep[j]].begin(), vert[dep[j]].end(), j) - vert[dep[j]].begin();
        c[i][0] = R - L + ok[i];
    }
    for(int i = 1; i < l; i++) {
        for(int j = 1; j <= n; j++) {
            c[j][i] = c[j][i - 1] + c[up[j][i - 1]][i - 1];
        }
    }
}
vector<int> sp;
void test() {
    cin >> n >> q >> s;
    for(int i = 1; i <= n; i++) {
        char x;
        cin >> x;
        if(x == '1') {
            ok[i] = 1;
            sp.push_back(i);
        }
    }
    prec();
    while(q--) {
        int a, b;
        cin >> a >> b;
        auto [res, c] = solve(a, b);
        cout << res << ' ' << c << '\n';
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); 
    
    int t = 1; 
    // cin >> t;
    
    while(t--) 
        test();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 6.25
Accepted
time: 0ms
memory: 13928kb

input:

8 10
LLLLRLLLLRRRRRRR
11011010
1 2
1 3
1 4
1 5
1 6
1 7
1 8
2 3
2 4
2 5

output:

1 2
1 1
1 2
2 4
2 3
2 4
2 3
1 1
1 2
1 2

result:

ok 20 numbers

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 13964kb

input:

5000 5000
LLRLRLRLRLRLRLRLLLRLRRLLRRRLRLLLRRRLRLLLRRRLLRRLRLRLLRRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLLRLRRLRLRLLRRLRLRLRLRLRLRLRLLRRLRLRLRLLRLRLRLLRRRLRLRLRLRLRLRLRLRLLLLRRRLRLRRLRLRLRLRLLRLLRRRLRLRLRLRLLRLRRLRLRLRLRLRLLLRRRLRLLRRLLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRLRRLRLRLRLRLRLRLRLRLLR...

output:

1999 1391
631 344
559 293
646 342
713 397
1951 1299
134 381
1290 839
1254 1086
1330 1047
687 356
33 84
2 17
571 845
1057 578
1786 1161
208 454
2044 1515
953 829
1269 912
820 435
1499 919
1689 1294
69 277
35 251
448 572
1665 1215
627 348
732 427
163 336
123 197
681 790
1673 881
689 900
29 82
1801 152...

result:

wrong answer 2nd numbers differ - expected: '1394', found: '1391'

Test #3:

score: 0
Wrong Answer
time: 5ms
memory: 14032kb

input:

5000 5000
LLRLRLRLRLLLLLRRRRLRRLRLLRLRRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLLRRLRLLRRLRLRLRLLRRLRLLRLLLLRRRLRRRLRLRLLRRLRLLLRLRRRLRLRLRLLRRLRLRLRLRLRLLRRLRLLRRLLRRLRLRLRLLLRRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLLRLLRLRRLRRLRLRLRLLRRLRLRLRLRLRL...

output:

186 91
73 243
68 81
4 66
170 360
1 0
1297 988
1426 943
469 241
1789 1094
938 753
4 19
1316 690
615 571
555 285
1480 849
1092 639
572 655
115 55
2108 1351
107 324
1949 1293
533 500
4 58
1911 1034
1695 1059
218 102
603 399
1895 1338
703 565
302 447
515 253
751 396
1725 939
870 456
896 446
1418 732
8 9...

result:

wrong answer 6th numbers differ - expected: '116', found: '81'

Test #4:

score: 0
Wrong Answer
time: 151ms
memory: 49704kb

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLLRLRRLRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLLRRLRLRLLRRLRLLRRLRLRLLRLRRLRLRLRLRLRLRLLRRLRLRLLRLRLRRLRLRLLRRLRLLRRLRLLRRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLLRRLLRRLRLRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLLR...

output:

16484 1
655 0
1517 0
11032 1
17293 3
30870 4
33999 3
74780 6
1850 0
29599 2
71012 6
266 0
14695 3
1648 0
82 0
56064 5
1364 0
4 0
67268 6
10 0
29492 4
47 0
4052 2
20545 3
1439 0
67845 6
21604 1
21288 3
29672 4
57680 4
41159 5
41529 5
15172 3
87 0
42937 5
30017 1
28295 4
33 0
26750 4
43539 5
43553 5
3...

result:

wrong answer 10th numbers differ - expected: '4', found: '3'

Test #5:

score: 0
Wrong Answer
time: 154ms
memory: 51012kb

input:

200000 200000
LLRLRLRLLRLRRLRLRLRLLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRLLRRLRRLRLRLRLLRRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLRLLRRLRLLLRLRRRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLLRRLLRRLLRLRLRRLLRLLLRRRRLRLRLRLRLLRRLLRLRRLRLRLRLRLRLLLRRRLRLRLRLRLRLRLRLLLRRLLLRRRRL...

output:

26131 5
20974 5
1273 2
1512 3
19550 2
163 0
32871 1
69437 5
73141 6
22 0
40408 2
59158 4
3843 0
28987 6
1280 1
43180 5
1685 4
22520 5
80845 7
21239 1
31403 3
1468 2
43505 1
69232 3
41 0
47329 2
389 2
65752 7
5471 1
309 1
24754 6
1794 4
33241 1
7709 4
45311 2
38478 1
12876 0
50626 7
575 0
730 2
20 0
...

result:

wrong answer 28th numbers differ - expected: '7', found: '6'

Test #6:

score: 0
Wrong Answer
time: 151ms
memory: 45608kb

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLLLRRRLRLLRLLLRRRLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLLRRLRLRLRLRLRLLRRLRLLRRLRLRLRLRLLRRLRLLRRLLRRLRLRLRLRLRLLLRRLRLRRLRLRLLR...

output:

48136 4
21402 7
41513 4
131 6
15137 0
14 0
30997 2
144 1
15998 0
67175 7
26 1
179 1
20 0
73265 10
39492 2
74604 4
4124 0
15777 2
45843 9
43185 3
66571 10
12661 0
38966 2
19994 7
41 0
18 0
75 1
64372 10
143 1
23 0
38583 2
52285 4
2 0
22974 5
7064 0
43522 4
121 3
59010 4
23787 8
35 0
69 2
45678 6
8943...

result:

wrong answer 42nd numbers differ - expected: '6', found: '10'

Test #7:

score: 0
Wrong Answer
time: 148ms
memory: 49720kb

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLLLRRRLRLRLLRRLLRRLLRRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLLRLLRRLRRLRLLLRRRLRLRLRLRLLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLLRRLRLRLLLRLLRLRRRRLRLRLRLRLRLRLLRLLRRRLRLRLRLRLRLRLRLLRRLLLRRRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLLRRLRLLLRRRLRLRL...

output:

31339 1
7836 0
55074 1
21182 0
15631 0
721 3
51516 1
15481 3
40668 0
67728 1
30161 3
36547 0
178 1
9 0
68926 1
217 1
10052 0
3929 6
41507 0
63304 2
18966 0
20636 1
8210 0
726 1
65546 5
13261 2
23103 0
812 4
249 3
31587 4
47501 1
162 1
53257 2
114 1
13496 0
26613 0
33769 1
95 1
44876 3
44295 3
41811 ...

result:

wrong answer 16th numbers differ - expected: '1', found: '3'

Test #8:

score: 0
Wrong Answer
time: 159ms
memory: 53496kb

input:

200000 200000
LLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLLRRLRLRLRLLLLRLRRRLRRLRLRLRLLLLRRLRRRLLRRLLRRLRLRLRLRLRLRLLRLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLLRLRRLRLRLRLRLLRLRLRRLRLLLRRRLRLRLRLRLRLRLRLLRRLRLLLRRLRLRRLRLRLLRRLRLLRRLLRRLRLRLRLRLRLRLLLRRRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLLR...

output:

130 802
15348 34541
28389 27055
26249 13714
30777 16127
94 6425
181 5079
72963 64060
117 1652
61711 40888
12236 11180
39712 20861
35 778
40298 40076
59600 35424
53308 54501
1292 15763
70240 54763
719 14019
4513 2877
52930 51035
78509 47522
106 5372
20154 32441
5677 14052
351 2541
1922 27417
15801 21...

result:

wrong answer 2nd numbers differ - expected: '1128', found: '802'

Test #9:

score: 0
Wrong Answer
time: 163ms
memory: 49212kb

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLLRRLRLRLLRRLLRLRRLLLRRLRRLRLRLLRRLRLRLRLRLRLLRLRRLLRLRRLRLLRRLRLRLRLRLRLRLRLRLLLRRLRRLRLRLRLLLLRRRRLRLRLRLRLRLRLRLRLLRRLLRRLRLLRRLRLLLRRRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRLRRLLLRRRLRLRLLRRLRLRLRLRL...

output:

32610 29146
4145 2219
35988 29470
15767 8266
33276 17463
4219 2259
75369 41615
41492 21684
285 5163
25 549
19484 12986
262 1641
8498 18439
77876 44853
17401 9082
36834 22060
65 2888
34952 28047
84 1070
25829 13543
19738 10308
52191 32509
68175 44303
692 8838
20721 10856
397 6800
1818 12066
68510 462...

result:

wrong answer 2nd numbers differ - expected: '29140', found: '29146'

Test #10:

score: 0
Wrong Answer
time: 160ms
memory: 53284kb

input:

200000 200000
LLRLLRRLRLLRRLRLLRRLRLLRRLRLLRRLRLRLRLLRRLRLRLRLRLRLLRLRRLRLLRRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLRLRLRLLLRLRLRLRRRLRLRLRLRLRLRLLRRLRLLRLRLRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRLRRLRLRLRLRLRLRLLLRLRRRLRLRLRL...

output:

49378 58488
11210 5793
49079 54256
78290 65662
41 2972
62458 64430
45489 37705
8690 4500
4 33
54483 61780
76025 43668
39891 35687
237 14186
33146 21693
534 29490
339 21727
62573 52094
218 10110
14838 7730
17084 8895
7 213
25689 13485
36 1625
8071 4145
5862 33816
44387 23305
834 389
994 2891
47013 51...

result:

wrong answer 2nd numbers differ - expected: '57487', found: '58488'

Test #11:

score: 0
Wrong Answer
time: 159ms
memory: 52812kb

input:

200000 200000
LLRLRLLRRLRLRLLRRLRLLLRRLRLRRLRLRLRLRLRLRLRLRLLRLRLLRLRRLRRLRLRLRLRLRLLRRLLRRLRLRLRLLRRLLRLRRLRLRLRLRLRLRLRLLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLLRRLLRRLRLRLRLRLRLRLRLLRRLLRRLRLLRRLRLLRRLLRLRRLRLRLLLLRRRRLRLRLRLLLRRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLLRRL...

output:

3446 16297
52081 35920
5 543
13168 12433
2149 1162
58 1540
22969 14028
302 10472
14457 7646
10020 7974
10220 5326
275 1619
33373 17441
8196 20176
37956 32306
13755 7262
25808 37697
12436 6568
4520 11795
43989 41036
666 17700
66624 48123
6869 3657
68874 51052
9225 16936
65715 48590
34016 31172
45072 ...

result:

wrong answer 2nd numbers differ - expected: '21559', found: '16297'

Test #12:

score: 0
Wrong Answer
time: 158ms
memory: 53212kb

input:

200000 200000
LLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRLRRLRLRLRLRLRLRLLRRLRLRLRLLRRLRLLRRLLRRLRLLRRLRLRLRLRLRLRLRLRLLLRLRRRLRLRLRLRLLRLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLLRLRRLRLLLRRRLRLRLRLRLRLRLLRRLLRLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLLRLRRRLRLLRRL...

output:

8341 4320
17304 8989
50324 34737
60725 31695
13661 10448
39520 47687
22480 28056
48811 42251
86 3686
7 459
285 27236
341 23951
217 20684
11814 6191
29 2838
42930 22412
4834 10042
48869 52711
70120 47056
64176 51462
155 7601
64718 50346
20594 10752
244 5745
3197 4473
26941 14057
55596 33040
42074 366...

result:

wrong answer 6th numbers differ - expected: '35657', found: '34737'

Test #13:

score: 0
Wrong Answer
time: 169ms
memory: 53604kb

input:

200000 200000
LLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLLRRLRLRLRLRLRLLRRLRLLRLRRLRLRLRLRLRLLRRLLRLRRLRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLLRRRLLLRRRLRLRLRLLRLRRLRLRLRLRLRLRLLLRRRLRLLLRRRLRLLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLLLLLRRRRRLRLRLRLLRRLRLRLRLLRLRRLLLRRRLRLRLLRRLRL...

output:

2938 16650
2257 14773
28652 21828
78285 44761
2805 17119
35559 18762
70624 37153
94 9859
1412 16226
30527 27904
70850 63478
20 4415
23909 12478
181 3007
3552 1817
58999 58470
21608 11277
1273 15589
20951 10958
19372 10162
6513 3451
8526 4490
60167 32498
6990 17479
880 4158
1230 7496
19950 33810
6765...

result:

wrong answer 2nd numbers differ - expected: '16907', found: '16650'

Test #14:

score: 0
Wrong Answer
time: 167ms
memory: 53016kb

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLLRRLRLRLRLLLRRRLRLLRRLLRRLLLRRRLRLRLLLLLRRRRRLRLRLRLRLLRLRRLRLLLRRRLLRLRRLRLRLRLRLLRLLRRRLRLLRRLRLLLRRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLLRRLLLRLRRRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRLRLRRLLRLRRLLRRLRLRL...

output:

33415 17529
16839 31181
58006 45048
1653 13679
74712 60831
75580 57032
10240 5377
1022 6826
51487 33094
65566 57939
35513 38293
26064 25183
25843 16180
5131 14451
15371 8032
64125 33700
1708 13886
69260 51475
1071 8910
130 1480
2574 19396
21988 11463
279 1158
10624 5726
1402 10435
18687 9741
2210 17...

result:

wrong answer 4th numbers differ - expected: '31998', found: '31181'

Test #15:

score: 0
Wrong Answer
time: 156ms
memory: 52780kb

input:

200000 200000
LLRLRLLRRLRLRLRLRLRLRLLRRLRLLRRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLLLRLRRRLRLRLRLRLRLLRRLLLLRLRRLRRRLRLRLLLRRLRRLRLRLRLRLRLRLRLRLLLLRRLLRRRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLLRRRLLRRLRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL...

output:

67484 35566
33071 17330
53695 37641
20598 10903
32384 16989
57205 36127
10800 5703
12056 6312
189 4076
47415 30305
49108 26087
195 3381
37344 19970
7354 6124
115 2555
62047 40906
5 310
14 1525
53696 28238
22297 20519
72528 38438
18864 27506
13171 7002
47426 30691
32419 17107
52712 39130
2004 1032
35...

result:

wrong answer 6th numbers differ - expected: '37821', found: '37641'

Test #16:

score: 0
Wrong Answer
time: 153ms
memory: 53320kb

input:

200000 200000
LLRLRLLRRLRLRLRLRLRLRLLRRLRLRLLRRLRLRLLRRLRLLRRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLLRLRRLLLRRRLRLRLRLLLRRRLRLRLRLLLRRRLRLLRRLLLRLRLLRRRRLRLRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLLRRLRLRLRLRLRLRLRLRL...

output:

44477 23219
26913 26714
26243 18272
45 5140
49412 25800
30778 16132
27222 14237
20078 19693
87 19944
51 8212
66971 44148
106 9328
80 9274
76632 47293
4 441
34858 23881
61 5781
65937 45174
21912 11450
4 253
25 345
76032 48456
17011 19121
78954 42251
11493 17293
40 14816
12863 14474
64799 33914
74297 ...

result:

wrong answer 4th numbers differ - expected: '22178', found: '26714'