Submission #721673

# Submission time Handle Problem Language Result Execution time Memory
721673 2023-04-11T06:29:19 Z MDSPro Event Hopping (BOI22_events) C++17
0 / 100
581 ms 12980 KB
#include "bits/stdc++.h"

using namespace std;

int main(){
    cin.tie(0)->sync_with_stdio(0);

    int n,q; cin >> n >> q;
    vector<tuple<int,int,int>> ev;
    for(int i = 0; i < n; ++i){
        int x,y; cin >> x >> y;
        ev.emplace_back(x,y,i+1);
    }

    sort(ev.begin(),ev.end());  

    vector<int> nw_order(n+1);
    vector<int> left(n+1),right(n+1);
    for(int i = 0; i < n; ++i) {
        left[i] = get<0>(ev[i]);
        right[i] = get<1>(ev[i]);
        nw_order[get<2>(ev[i])] = i;
    }

    vector<vector<int>> nxt(20,vector<int>(n+1));
    nxt[0][n] = n;

    int r = 0;
    for(int i = 0; i < n; ++i){
        while(r+1 < n && left[r+1] <= right[i]) r++;
        if(i != r) nxt[0][i] = r;
        else nxt[0][i] = n;
    }
    for(int i = 1; i < 20; ++i) {
        for(int j = 0; j <= n; ++j){
            nxt[i][j] = nxt[i-1][nxt[i-1][j]];
        }
    }
    for(int i = 0; i <= n; ++i) cerr << nxt[0][i] << ' '; cerr << '\n';
    for(int i = 0; i <= n; ++i) cerr << nxt[1][i] << ' '; cerr << '\n';

    auto get = [&](int x, int y){
        int cur = 0;
        for(int i = 19; i >= 0; --i){
            if(nxt[i][x] <= y) {
                cur |= (i<<1);
                x = nxt[i][x];
            }
        }

        if(x != y) return -1;
        return cur;
    };

    while(q--){
        int a,b; cin >> a >> b;
        a = nw_order[a];
        b = nw_order[b];

        int ans = get(a,b);
        if(ans == -1) cout << "impossible\n";
        else cout << ans << '\n';
    }
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:39:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   39 |     for(int i = 0; i <= n; ++i) cerr << nxt[0][i] << ' '; cerr << '\n';
      |     ^~~
events.cpp:39:59: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   39 |     for(int i = 0; i <= n; ++i) cerr << nxt[0][i] << ' '; cerr << '\n';
      |                                                           ^~~~
events.cpp:40:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   40 |     for(int i = 0; i <= n; ++i) cerr << nxt[1][i] << ' '; cerr << '\n';
      |     ^~~
events.cpp:40:59: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   40 |     for(int i = 0; i <= n; ++i) cerr << nxt[1][i] << ' '; cerr << '\n';
      |                                                           ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 581 ms 12980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -