QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#610130#5452. Tractor PathsDimash#18.75 237ms13972kbC++233.5kb2024-10-04 15:00:152024-10-04 15:00:16

Judging History

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

  • [2024-10-04 15:00:16]
  • 评测
  • 测评结果:18.75
  • 用时:237ms
  • 内存:13972kb
  • [2024-10-04 15:00:15]
  • 提交

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]);
    }
}

int dist(int v, int u) {
    if(v == u) return 0;
    int ret = 1;
    for(int i = l - 1; i >= 0;i--) {
        if(up[v][i] < u) {
            ret += (1 << i);
            v = up[v][i];
        }
    }
    return ret;
}
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(-1e9, -1e9);
    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 = dist(v, u), col = 0;
    int V = v;
    while(v) {
        int r = min(u, up[v][0]);
        if(ok[v]) {
            col++;
        }
        for(int j = v + 1; j < r; j++) {
            if(ok[j]) {
                if(dist(V, j) + dist(j, u) == ret) {
                    assert(r != u);
                    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;
    if(n > 5000) return;
    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;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 6.25
Accepted
time: 3ms
memory: 11844kb

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: 6.25
Accepted
time: 237ms
memory: 13972kb

input:

5000 5000
LLRLRLRLRLRLRLRLLLRLRRLLRRRLRLLLRRRLRLLLRRRLLRRLRLRLLRRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLLRLRRLRLRLLRRLRLRLRLRLRLRLRLLRRLRLRLRLLRLRLRLLRRRLRLRLRLRLRLRLRLRLLLLRRRLRLRRLRLRLRLRLLRLLRRRLRLRLRLRLLRLRRLRLRLRLRLRLLLRRRLRLLRRLLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRLRRLRLRLRLRLRLRLRLRLLR...

output:

1999 1394
631 344
559 293
646 342
713 397
1951 1292
134 296
1290 839
1254 1027
1330 1112
687 356
33 91
2 5
571 1010
1057 578
1786 1186
208 414
2044 1447
953 829
1269 912
820 435
1499 919
1689 1247
69 183
35 117
448 597
1665 1225
627 348
732 415
163 339
123 197
681 709
1673 881
689 747
29 98
1801 134...

result:

ok 10000 numbers

Test #3:

score: 6.25
Accepted
time: 209ms
memory: 13948kb

input:

5000 5000
LLRLRLRLRLLLLLRRRRLRRLRLLRLRRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLLRRLRLLRRLRLRLRLLRRLRLLRLLLLRRRLRRRLRLRLLRRLRLLLRLRRRLRLRLRLLRRLRLRLRLRLRLLRRLRLLRRLLRRLRLRLRLLLRRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLLRLLRLRRLRRLRLRLRLLRRLRLRLRLRLRL...

output:

186 91
73 243
68 116
4 18
170 389
1 0
1297 1191
1426 943
469 241
1789 1130
938 817
4 21
1316 690
615 539
555 285
1480 909
1092 657
572 711
115 55
2108 1351
107 601
1949 1302
533 496
4 51
1911 1034
1695 1015
218 102
603 403
1895 1531
703 565
302 484
515 253
751 396
1725 939
870 456
896 446
1418 732
8...

result:

ok 10000 numbers

Test #4:

score: 0
Wrong Answer
time: 2ms
memory: 3792kb

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLLRLRRLRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLLRRLRLRLLRRLRLLRRLRLRLLRLRRLRLRLRLRLRLRLLRRLRLRLLRLRLRRLRLRLLRRLRLLRRLRLLRRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLLRRLLRRLRLRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLLR...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #5:

score: 0
Wrong Answer
time: 2ms
memory: 3812kb

input:

200000 200000
LLRLRLRLLRLRRLRLRLRLLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRLLRRLRRLRLRLRLLRRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLRLLRRLRLLLRLRRRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLLRRLLRRLLRLRLRRLLRLLLRRRRLRLRLRLRLLRRLLRLRRLRLRLRLRLRLLLRRRLRLRLRLRLRLRLRLLLRRLLLRRRRL...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #6:

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

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLLLRRRLRLLRLLLRRRLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLLRRLRLRLRLRLRLLRRLRLLRRLRLRLRLRLLRRLRLLRRLLRRLRLRLRLRLRLLLRRLRLRRLRLRLLR...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #7:

score: 0
Wrong Answer
time: 2ms
memory: 3780kb

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLLLRRRLRLRLLRRLLRRLLRRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLLRLLRRLRRLRLLLRRRLRLRLRLRLLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLLRRLRLRLLLRLLRLRRRRLRLRLRLRLRLRLLRLLRRRLRLRLRLRLRLRLRLLRRLLLRRRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLLRRLRLLLRRRLRLRL...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #8:

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

input:

200000 200000
LLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLLRRLRLRLRLLLLRLRRRLRRLRLRLRLLLLRRLRRRLLRRLLRRLRLRLRLRLRLRLLRLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLLRLRRLRLRLRLRLLRLRLRRLRLLLRRRLRLRLRLRLRLRLRLLRRLRLLLRRLRLRRLRLRLLRRLRLLRRLLRRLRLRLRLRLRLRLLLRRRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLLR...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #9:

score: 0
Wrong Answer
time: 2ms
memory: 3760kb

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLLRRLRLRLLRRLLRLRRLLLRRLRRLRLRLLRRLRLRLRLRLRLLRLRRLLRLRRLRLLRRLRLRLRLRLRLRLRLRLLLRRLRRLRLRLRLLLLRRRRLRLRLRLRLRLRLRLRLLRRLLRRLRLLRRLRLLLRRRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRLRRLLLRRRLRLRLLRRLRLRLRLRL...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #10:

score: 0
Wrong Answer
time: 2ms
memory: 3836kb

input:

200000 200000
LLRLLRRLRLLRRLRLLRRLRLLRRLRLLRRLRLRLRLLRRLRLRLRLRLRLLRLRRLRLLRRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLRLRLRLLLRLRLRLRRRLRLRLRLRLRLRLLRRLRLLRLRLRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLLRLRRLRLRLRLRLRLRLLLRLRRRLRLRLRL...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #11:

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

input:

200000 200000
LLRLRLLRRLRLRLLRRLRLLLRRLRLRRLRLRLRLRLRLRLRLRLLRLRLLRLRRLRRLRLRLRLRLRLLRRLLRRLRLRLRLLRRLLRLRRLRLRLRLRLRLRLRLLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLLRRLRLLRRLLRRLRLRLRLRLRLRLRLLRRLLRRLRLLRRLRLLRRLLRLRRLRLRLLLLRRRRLRLRLRLLLRRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLLRRL...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #12:

score: 0
Wrong Answer
time: 2ms
memory: 3864kb

input:

200000 200000
LLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRLRRLRLRLRLRLRLRLLRRLRLRLRLLRRLRLLRRLLRRLRLLRRLRLRLRLRLRLRLRLRLLLRLRRRLRLRLRLRLLRLRRLLRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLLRLRRLRLLLRRRLRLRLRLRLRLRLLRRLLRLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLLRLRRRLRLLRRL...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #13:

score: 0
Wrong Answer
time: 2ms
memory: 3848kb

input:

200000 200000
LLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLLRRLRLRLRLRLRLLRRLRLLRLRRLRLRLRLRLRLLRRLLRLRRLRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLLRRRLLLRRRLRLRLRLLRLRRLRLRLRLRLRLRLLLRRRLRLLLRRRLRLLRRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLLLLLRRRRRLRLRLRLLRRLRLRLRLLRLRRLLLRRRLRLRLLRRLRL...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #14:

score: 0
Wrong Answer
time: 2ms
memory: 3864kb

input:

200000 200000
LLLRRLRLRLRLRLRLRLRLRLRLRLLLRRRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLLRRLRLRLRLLLRRRLRLLRRLLRRLLLRRRLRLRLLLLLRRRRRLRLRLRLRLLRLRRLRLLLRRRLLRLRRLRLRLRLRLLRLLRRRLRLLRRLRLLLRRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLLRRLLLRLRRRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRLRLRRLLRLRRLLRRLRLRL...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #15:

score: 0
Wrong Answer
time: 2ms
memory: 3772kb

input:

200000 200000
LLRLRLLRRLRLRLRLRLRLRLLRRLRLLRRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLLLRLRRRLRLRLRLRLRLLRRLLLLRLRRLRRRLRLRLLLRRLRRLRLRLRLRLRLRLRLRLLLLRRLLRRRRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLLLRRRLLRRLRLRLRLLLRRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements

Test #16:

score: 0
Wrong Answer
time: 2ms
memory: 3788kb

input:

200000 200000
LLRLRLLRRLRLRLRLRLRLRLLRRLRLRLLRRLRLRLLRRLRLLRRLRLLRRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLLRLRRLLLRRRLRLRLRLLLRRRLRLRLRLLLRRRLRLLRRLLLRLRLLRRRRLRLRLLRRLLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRLRLRLRLRLRLRLRLRLRLLRRLRLLRRLRLLRRLRLRLRLRLRLRLRLRL...

output:


result:

wrong answer Answer contains longer sequence [length = 400000], but output contains 0 elements