QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#287267#4206. Event HoppingMysterious_Cat0 88ms16968kbC++172.5kb2023-12-20 09:04:542023-12-20 09:04:54

Judging History

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

  • [2023-12-20 09:04:54]
  • 评测
  • 测评结果:0
  • 用时:88ms
  • 内存:16968kb
  • [2023-12-20 09:04:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int NR = 1e5;
const int inf = 1e9;

int n, q, bn;
int c[NR * 2 + 5], b[NR * 2 + 5], L[NR + 5], R[NR + 5], mn[NR * 8 + 5], f[NR + 5][20];

void build(int p, int l, int r) {
    if(l == r) {
        mn[p] = c[l];
        return;
    }
    int mid = l + r >> 1;
    build(p * 2, l, mid);
    build(p * 2 + 1, mid + 1, r);
    if(mn[p * 2] == -1) {
        mn[p] = mn[p * 2 + 1];
    }
    else if(mn[p * 2 + 1] == -1) {
        mn[p] = mn[p * 2];
    }
    else {
        mn[p] = L[mn[p * 2]] < L[mn[p * 2 + 1]] ? mn[p * 2] : mn[p * 2 + 1];
    }
}

int query(int p, int l, int r, int a, int b) {
    if(l >= a && r <= b) {
        return mn[p];
    }
    int mid = l + r >> 1, res1 = -1, res2 = -1;
    if(a <= mid) {
        res1 = query(p * 2, l, mid, a, b);
    }
    if(b > mid) {
        res2 = query(p * 2 + 1, mid + 1, r, a, b);
    }
    if(res1 == -1) {
        return res2;
    }
    if(res2 == -1) {
        return res1;
    }
    return L[res1] < L[res2] ? res1 : res2;
}

int main() {
    // freopen("b.in", "r", stdin);
    // freopen("b.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> q;
    for(int i = 1; i <= n; i++) {
        cin >> L[i] >> R[i];
        b[++bn] = L[i];
        b[++bn] = R[i];
    }
    sort(b + 1, b + bn + 1);
    bn = unique(b + 1, b + bn + 1) - b - 1;
    memset(c, -1, sizeof(c));
    for(int i = 1; i <= n; i++) {
        L[i] = lower_bound(b + 1, b + bn + 1, L[i]) - b;
        R[i] = lower_bound(b + 1, b + bn + 1, R[i]) - b;
        if(c[R[i]] == -1 || L[i] < L[c[R[i]]]) {
            c[R[i]] = i;
        }
    }
    build(1, 1, bn);
    for(int i = 1; i <= n; i++) {
        f[i][0] = query(1, 1, bn, L[i], R[i]);
    }
    for(int j = 1; j <= 19; j++) {
        for(int i = 1; i <= n; i++) {
            f[i][j] = f[f[i][j - 1]][j - 1];
        }
    }
    for(int i = 1; i <= q; i++) {
        int s, t, ans = 0;
        cin >> s >> t;
        if(R[t] < R[s]) {
            cout << "impossible\n";
            continue;
        }
        if(L[t] <= R[s]) {
            cout << "0\n";
            continue;
        }
        for(int j = 19; j >= 0; j--) {
            if(L[f[t][j]] > R[s]) {
                ans += 1 << j;
                t = f[t][j];
            }
        }
        t = f[t][0];
        if(L[t] > R[s]) {
            cout << "impossible\n";
            continue;
        }
        cout << ans + 2 << '\n';
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 73ms
memory: 16844kb

input:

100000 100000
825913690 825916363
333322014 333324481
302015784 302018251
841002775 841005448
810249910 810252583
803554045 803556718
379590599 379593066
413477311 413479778
304105333 304107800
856802878 856805551
355907399 355909866
365590374 365592841
813775597 813778270
816058339 816061012
383873...

output:

0
impossible
0
impossible
impossible
impossible
31336
impossible
impossible
impossible
impossible
27166
16274
impossible
impossible
impossible
impossible
impossible
impossible
21353
17890
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
67...

result:

wrong answer 1st lines differ - expected: '1', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #13:

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

input:

1000 100
67878298 387720407
270457472 922959000
286470357 618323410
260791474 282940414
301337446 553875076
478221503 724555102
380447228 437131400
191801427 465825895
366088873 431222136
49483883 103442781
699926238 720636919
253150351 291688158
411085513 727726933
444078045 496386017
420626857 822...

output:

0
2
2
impossible
0
2
0
2
impossible
2
2
impossible
impossible
impossible
0
impossible
impossible
impossible
impossible
impossible
2
impossible
2
impossible
0
0
impossible
0
0
0
0
impossible
2
impossible
2
impossible
0
0
impossible
impossible
impossible
0
2
impossible
impossible
0
2
impossible
imposs...

result:

wrong answer 1st lines differ - expected: '1', found: '0'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Wrong Answer

Test #35:

score: 20
Accepted
time: 88ms
memory: 16860kb

input:

100000 100000
903318459 905410836
903528407 905653109
925180437 927048927
473524826 475597377
362562616 364539688
644980844 646918450
242583398 244653279
506338025 508361063
481496693 483530832
970053326 972147109
794840350 796900045
130664210 132709680
634100524 636336820
844429264 846504591
652483...

output:

500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
...

result:

ok 100000 lines

Test #36:

score: -20
Wrong Answer
time: 87ms
memory: 16968kb

input:

100000 100000
280978238 281996879
128582305 129520369
326480847 327450886
613575910 614525870
773187456 774194521
499427531 500501109
206817453 207828231
147432355 148457712
276397611 277442951
238269352 239211898
864332415 865500617
189404293 190348043
898692256 899607594
395766418 396755456
306101...

output:

impossible
434
impossible
248
338
332
390
impossible
607
771
246
impossible
421
impossible
628
117
549
impossible
impossible
impossible
382
impossible
495
impossible
impossible
357
impossible
522
impossible
54
impossible
impossible
impossible
464
impossible
impossible
225
255
484
60
86
244
579
363
7...

result:

wrong answer 2804th lines differ - expected: '1', found: '0'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%