Submission #580305

# Submission time Handle Problem Language Result Execution time Memory
580305 2022-06-21T04:58:17 Z 반딧불(#8355) Event Hopping (BOI22_events) C++17
0 / 100
93 ms 12288 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 l<nxt.l;
    }
};

struct dat{
    int s, x, idx;
    dat(){}
    dat(int s, int x, int idx): s(s), x(x), idx(idx){}
    bool operator<(const dat &r)const{
        return s<r.s;
    }
};

int n, q;
Range arr[100002];
int nxt[100002];
int sps[100002][20];
int rLim, rIdx;

int main(){
    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;
    }
    sort(arr+1, arr+n+1);

    vector<dat> vec;
    for(int i=1; i<=n; i++){
        if(rLim < arr[i].r) rLim = arr[i].r, rIdx = arr[i].idx;
        if(arr[i].l == arr[i+1].l) continue;
        vec.push_back(dat(arr[i].l, rLim, rIdx));
    }
    sort(arr+1, arr+n+1, [&](Range &x, Range &y){
        return x.r<y.r;
    });
    sort(vec.begin(), vec.end());
    for(int i=1; i<=n; i++){
        auto it = prev(upper_bound(vec.begin(), vec.end(), dat(arr[i].r, 0, 0)));
        sps[arr[i].idx][0] = nxt[arr[i].idx] = it->idx;
    }
    for(int d=1; d<20; d++) for(int i=1; i<=n; i++) sps[i][d] = sps[sps[i][d-1]][d-1];
    sort(arr+1, arr+n+1, [&](Range &x, Range &y){
        return x.idx<y.idx;
    });

    while(q--){
        int l, r;
        scanf("%d %d", &l, &r);
        if(l==r) puts("0");
        else if(arr[r].l <= arr[l].r && arr[l].r <= arr[r].r) puts("1");
        else puts("impossible");
    }
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
events.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d %d", &arr[i].l, &arr[i].r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
events.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         scanf("%d %d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 12288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -