QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#610015#5452. Tractor PathsDimash#6.25 22ms14032kbC++233.2kb2024-10-04 14:42:542024-10-04 14:42:55

Judging History

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

  • [2024-10-04 14:42:55]
  • 评测
  • 测评结果:6.25
  • 用时:22ms
  • 内存:14032kb
  • [2024-10-04 14:42:54]
  • 提交

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 = 0, col = 0;
    while(v) {
        int r = min(u, up[v][0]);
        ret++;
        if(ok[v]) {
            col++;
        }
        for(int j = v + 1; j < r; j++) {
            if(ok[j]) {
                if(r != u && j + d[j] >= min(u, up[r][0])) {
                    col++;
                }
            }
        }
        v = r;
        if(r == u) break;
    }
    // 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: 3ms
memory: 11768kb

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: 22ms
memory: 11924kb

input:

5000 5000
LLRLRLRLRLRLRLRLLLRLRRLLRRRLRLLLRRRLRLLLRRRLLRRLRLRLLRRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLLRLRRLRLRLLRRLRLRLRLRLRLRLRLLRRLRLRLRLLRLRLRLLRRRLRLRLRLRLRLRLRLRLLLLRRRLRLRRLRLRLRLRLLRLLRRRLRLRLRLRLLRLRRLRLRLRLRLRLLLRRRLRLLRRLLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRLRRLRLRLRLRLRLRLRLRLLR...

output:

1999 1126
631 344
559 292
646 341
713 397
1951 1096
134 117
1290 730
1254 743
1330 782
687 355
33 32
2 5
571 384
1057 578
1786 1018
208 169
2044 1158
953 563
1269 733
820 434
1499 828
1689 979
69 60
35 33
448 309
1665 965
627 348
732 388
163 134
123 102
681 431
1673 879
689 435
29 37
1801 1036
737 3...

result:

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

Test #3:

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

input:

5000 5000
LLRLRLRLRLLLLLRRRRLRRLRLLRLRRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLLRRLRLLRRLRLRLRLLRRLRLLRLLLLRRRLRRRLRLRLLRRLRLLLRLRRRLRLRLRLLRRLRLRLRLRLRLLRRLRLLRRLLRRLRLRLRLLLRRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLLRLLRLRRLRRLRLRLRLLRRLRLRLRLRLRL...

output:

186 91
73 68
68 64
4 9
170 162
1 0
1297 763
1426 798
469 239
1789 989
938 561
4 7
1316 684
615 388
555 283
1480 813
1092 599
572 388
115 54
2108 1162
107 112
1949 1088
533 348
4 21
1911 1007
1695 930
218 102
603 355
1895 1068
703 423
302 256
515 253
751 393
1725 915
870 453
896 444
1418 728
8 26
182...

result:

wrong answer 4th numbers differ - expected: '243', found: '68'

Test #4:

score: 0
Time Limit Exceeded

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLLRLRRLRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLLRRLRLRLLRRLRLLRRLRLRLLRLRRLRLRLRLRLRLRLLRRLRLRLLRLRLRRLRLRLLRRLRLLRRLRLLRRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLLRRLLRRLRLRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLLR...

output:

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

result:


Test #5:

score: 0
Time Limit Exceeded

input:

200000 200000
LLRLRLRLLRLRRLRLRLRLLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRLLRRLRRLRLRLRLLRRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLRLLRRLRLLLRLRRRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLLRRLLRRLLRLRLRRLLRLLLRRRRLRLRLRLRLLRRLLRLRRLRLRLRLRLRLLLRRRLRLRLRLRLRLRLRLLLRRLLLRRRRL...

output:

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

result:


Test #6:

score: 0
Time Limit Exceeded

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLLLRRRLRLLRLLLRRRLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLLRRLRLRLRLRLRLLRRLRLLRRLRLRLRLRLLRRLRLLRRLLRRLRLRLRLRLRLLLRRLRLRRLRLRLLR...

output:

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

result:


Test #7:

score: 0
Time Limit Exceeded

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLLLRRRLRLRLLRRLLRRLLRRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLLRLLRRLRRLRLLLRRRLRLRLRLRLLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLLRRLRLRLLLRLLRLRRRRLRLRLRLRLRLRLLRLLRRRLRLRLRLRLRLRLRLLRRLLLRRRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLLRRLRLLLRRRLRLRL...

output:

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

result:


Test #8:

score: 0
Time Limit Exceeded

input:

200000 200000
LLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLLRRLRLRLRLLLLRLRRRLRRLRLRLRLLLLRRLRRRLLRRLLRRLRLRLRLRLRLRLLRLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLLRLRRLRLRLRLRLLRLRLRRLRLLLRRRLRLRLRLRLRLRLRLLRRLRLLLRRLRLRRLRLRLLRRLRLLRRLLRRLRLRLRLRLRLRLLLRRRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLLR...

output:

130 164
15348 8842
28389 15387
26249 13677
30777 16081
94 152
181 170
72963 38930
117 144
61711 32744
12236 6797
39712 20796
35 61
40298 21735
59600 31546
53308 28728
1292 1218
70240 37363
719 673
4513 2419
52930 28434
78509 41538
106 119
20154 11200
5677 3623
351 324
1922 1794
15801 8807
391 366
52...

result:


Test #9:

score: 0
Time Limit Exceeded

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLLRRLRLRLLRRLLRLRRLLLRRLRRLRLRLLRRLRLRLRLRLRLLRLRRLLRLRRLRLLRRLRLRLRLRLRLRLRLRLLLRRLRRLRLRLRLLLLRRRRLRLRLRLRLRLRLRLRLLRRLLRRLRLLRRLRLLLRRRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRLRRLLLRRRLRLRLLRRLRLRLRLRL...

output:

32610 17614
4145 2208
35988 19142
15767 8244
33276 17409
4219 2253
75369 39461
41492 21633
285 246
25 31
19484 10285
262 225
8498 5092
77876 40816
17401 9051
36834 19339
65 76
34952 18533
84 97
25829 13505
19738 10274
52191 27453
68175 35879
692 649
20721 10815
397 381
1818 1383
68510 36129
17171 97...

result:


Test #10:

score: 0
Time Limit Exceeded

input:

200000 200000
LLRLLRRLRLLRRLRLLRRLRLLRRLRLLRRLRLRLRLLRRLRLRLRLRLRLLRLRRLRLLRRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLRLRLRLLLRLRLRLRRRLRLRLRLRLRLRLLRRLRLLRLRLRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRLRRLRLRLRLRLRLRLLLRLRRRLRLRLRL...

output:

49378 26259
11210 5781
49079 26124
78290 41321
41 89
62458 32966
45489 24121
8690 4487
4 34
54483 28996
76025 40020
39891 21058
237 290
33146 17484
534 519
339 360
62573 32961
218 289
14838 7708
17084 8877
7 54
25689 13434
36 113
8071 4132
5862 3471
44387 23233
834 387
994 674
47013 25029
116 153
16...

result:


Test #11:

score: 0
Time Limit Exceeded

input:

200000 200000
LLRLRLLRRLRLRLLRRLRLLLRRLRLRRLRLRLRLRLRLRLRLRLLRLRLLRLRRLRRLRLRLRLRLRLLRRLLRRLRLRLRLLRRLLRLRRLRLRLRLRLRLRLRLLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLLRRLLRRLRLRLRLRLRLRLRLLRRLLRRLRLLRRLRLLRRLLRLRRLRLRLLLLRRRRLRLRLRLLLRRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLLRRL...

output:

3446 2209
52081 27722
5 211
13168 7190
2149 1160
58 157
22969 12142
302 412
14457 7633
10020 5463
10220 5309
275 268
33373 17388
8196 4742
37956 20294
13755 7244
25808 14028
12436 6545
4520 2785
43989 23400
666 685
66624 35299
6869 3652
68874 36544
9225 5232
65715 34835
34016 18218
45072 23856
66510...

result:


Test #12:

score: 0
Time Limit Exceeded

input:

200000 200000
LLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRLRRLRLRLRLRLRLRLLRRLRLRLRLLRRLRLLRRLLRRLRLLRRLRLRLRLRLRLRLRLRLLLRLRRRLRLRLRLRLLRLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLLRLRRLRLLLRRRLRLRLRLRLRLRLLRRLLRLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLLRLRRRLRLLRRL...

output:

8341 4308
17304 8962
50324 26553
60725 31601
13661 7293
39520 21014
22480 11966
48811 25801
86 151
7 29
285 358
341 356
217 261
11814 6172
29 95
42930 22339
4834 2864
48869 25859
70120 36838
64176 33786
155 265
64718 34107
20594 10718
244 336
3197 1848
26941 14016
55596 29243
42074 22185
81 142
3621...

result:


Test #13:

score: 0
Time Limit Exceeded

input:

200000 200000
LLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLLRRLRLRLRLRLRLLRRLRLLRLRRLRLRLRLRLRLLRRLLRLRRLRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLLRRRLLLRRRLRLRLRLLRLRRLRLRLRLRLRLRLLLRRRLRLLLRRRLRLLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLLLLLRRRRRLRLRLRLLRRLRLRLRLLRLRRLLLRRRLRLRLLRRLRL...

output:

2938 2516
2257 1974
28652 15417
78285 41442
2805 2434
35559 18716
70624 37054
94 140
1412 1428
30527 16794
70850 38459
20 249
23909 12440
181 166
3552 1814
58999 32224
21608 11249
1273 1362
20951 10926
19372 10139
6513 3441
8526 4477
60167 31705
6990 4514
880 814
1230 1144
19950 11811
67659 35876
75...

result:


Test #14:

score: 0
Time Limit Exceeded

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLLRRLRLRLRLLLRRRLRLLRRLLRRLLLRRRLRLRLLLLLRRRRRLRLRLRLRLLRLRRLRLLLRRRLLRLRRLRLRLRLRLLRLLRRRLRLLRRLRLLLRRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLLRRLLLRLRRRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRLRLRRLLRLRRLLRRLRLRL...

output:

33415 17483
16839 9901
58006 30944
1653 1489
74712 40143
75580 40374
10240 5367
1022 896
51487 27123
65566 35357
35513 19500
26064 14187
25843 13559
5131 3336
15371 8017
64125 33612
1708 1478
69260 36948
1071 900
130 253
2574 2234
21988 11436
279 257
10624 5713
1402 1217
18687 9721
2210 1892
51620 2...

result:


Test #15:

score: 0
Time Limit Exceeded

input:

200000 200000
LLRLRLLRRLRLRLRLRLRLRLLRRLRLLRRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLLLRLRRRLRLRLRLRLRLLRRLLLLRLRRLRRRLRLRLLLRRLRRLRLRLRLRLRLRLRLRLLLLRRLLRRRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLLRRRLLRRLRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL...

output:

67484 35439
33071 17262
53695 28474
20598 10874
32384 16935
57205 30168
10800 5689
12056 6289
189 310
47415 25199
49108 25847
195 341
37344 19735
7354 3935
115 192
62047 32805
5 242
14 239
53696 28147
22297 12028
72528 38124
18864 10191
13171 6978
47426 25176
32419 17040
52712 27853
2004 1029
35980 ...

result:


Test #16:

score: 0
Time Limit Exceeded

input:

200000 200000
LLRLRLLRRLRLRLRLRLRLRLLRRLRLRLLRRLRLRLLRRLRLLRRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLLRLRRLLLRRRLRLRLRLLLRRRLRLRLRLLLRRRLRLLRRLLLRLRLLRRRRLRLRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLLRRLRLRLRLRLRLRLRLRL...

output:

44477 23132
26913 14207
26243 13914
45 397
49412 25706
30778 16073
27222 14191
20078 10822
87 304
51 461
66971 35370
106 412
80 401
76632 40064
4 240
34858 18537
61 88
65937 34830
21912 11417
4 282
25 290
76032 39901
17011 8991
78954 41206
11493 6350
40 486
12863 6877
64799 33792
74297 38885
44139 2...

result: