Submission #580375

# Submission time Handle Problem Language Result Execution time Memory
580375 2022-06-21T07:27:57 Z 반딧불(#8355) Event Hopping (BOI22_events) C++17
25 / 100
1500 ms 2064 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Range{
    int l, r, idx;
    Range(){}
    Range(int l, int r, int idx): l(l), r(r), idx(idx){}
    bool operator<(const Range &nxt)const{
        return r<nxt.r;
    }
};

struct dat{
    int x, v, idx;
    dat(){}
    dat(int x, int v, int idx): x(x), v(v), idx(idx){}
    bool operator<(const dat &r)const{
        if(x!=r.x) return x<r.x;
        return v>r.v;
    }
};

int n, q;
Range arr[100002];

void input();
void process();
void output();

int main(){
    input();
    process();
    output();
}

void input(){
    scanf("%d %d", &n, &q);
    for(int i=1; i<=n; i++){
        scanf("%d %d", &arr[i].l, &arr[i].r);
        arr[i].idx = i;
    }
}

int nxt[100002];
int sps[100002][20];
int idx[100002];

void process(){
    sort(arr+1, arr+n+1);
    for(int i=1; i<=n; i++) idx[arr[i].idx] = i;

    for(int i=1; i<=n; i++){
        int minL = 2e9;
        for(int j=1; j<=n; j++){
            if(arr[i].l <= arr[j].r && arr[j].r <= arr[i].r){
                if(minL > arr[j].l) minL = arr[j].l, nxt[i] = j;
            }
        }
    }

//    vector<dat> vec;
//    for(int i=n; i>=1; i--){
//        vec.push_back(dat(arr[i].r, arr[i].l, i));
//    }
//    sort(vec.rbegin(), vec.rend());
//    vector<dat> vec2;
//    for(auto x: vec){
//        if(vec2.empty() || vec2.back().v > x.v) vec2.push_back(x);
//    }
//    reverse(vec2.begin(), vec2.end());
//    for(int i=1; i<=n; i++){
//        nxt[i] = lower_bound(vec2.begin(), vec2.end(), dat(arr[i].l, INT_MAX, 0))->idx;
//        if(arr[nxt[i]].r < arr[i].l || arr[nxt[i]].r > arr[i].r) nxt[i] = i;
//    }


    for(int i=1; i<=n; i++) sps[i][0] = nxt[i];
    for(int d=1; d<20; d++) for(int i=1; i<=n; i++) sps[i][d] = sps[sps[i][d-1]][d-1];
}

void output(){
    while(q--){
        int l, r;
        scanf("%d %d", &l, &r);
        l = idx[l], r = idx[r];
        if(l==r) puts("0");
        else if(arr[r].r < arr[l].r) puts("impossible");
        else{
            int ans = 0;
            for(int d=19; d>=0; d--){
                if(arr[sps[r][d]].l > arr[l].r) ans += (1<<d), r = sps[r][d];
            }
            if(ans > n) puts("impossible");
            else printf("%d\n", ans+(arr[r].l <= arr[l].r && arr[l].r <= arr[r].r ? 1 : 2));
        }
    }
}

Compilation message

events.cpp: In function 'void input()':
events.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
events.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d %d", &arr[i].l, &arr[i].r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
events.cpp: In function 'void output()':
events.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         scanf("%d %d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1564 ms 2064 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 61 ms 1500 KB Output is correct
20 Correct 69 ms 1304 KB Output is correct
21 Correct 62 ms 1588 KB Output is correct
22 Correct 69 ms 1720 KB Output is correct
23 Correct 58 ms 1500 KB Output is correct
24 Correct 54 ms 1676 KB Output is correct
25 Correct 52 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Execution timed out 1598 ms 1996 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1585 ms 2016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1564 ms 2064 KB Time limit exceeded
3 Halted 0 ms 0 KB -