Submission #599053

# Submission time Handle Problem Language Result Execution time Memory
599053 2022-07-19T09:32:14 Z Vanilla Event Hopping (BOI22_events) C++17
0 / 100
68 ms 2476 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 1e5 + 2;
struct nd {
    int x;
    int y;
    int idx;

    bool operator < (const nd& oth) const {
        return make_pair(x, y) < make_pair(oth.x, oth.y);
    }
} a [maxn];

int ps [maxn];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,q;
    cin >> n >> q;
    for (int i = 0; i < n; i++){
        cin >> a[i].x >> a[i].y;
        a[i].idx = i;
    }
    sort(a, a + n);
    for (int i = 0; i < n; i++){
        ps[a[i].idx] = i;
    }
    while (q--){
        int x,y;
        cin >> x >> y;
        x = ps[x - 1], y = ps[y - 1];
        if (x > y) {
            cout << "impossible\n";
            continue;
        }
        cout << y - x << "\n";
        // cout << x << " " << y << "\n";
        // int r = a[x].y, rs = 0;
        // int mx = -1;
        // while (1) {
        //     if (x == y) {
        //         rs++;
        //         break;
        //     }
        //     else if (a[x].x <= r) mx = max(a[x].y, mx);
        //     else {
        //         if (a[x].x <= mx) {
        //             rs++;
        //             r = mx;
        //             // mx = a[x].y;
        //         }
        //         else {
        //             rs = -1;
        //             break;
        //         }
        //     }
        //     cout << a[x].x << " " << a[x].y  << " " << r << " " << mx << " " << rs << "\n";
        //     x++;
        // }
        // cout << (rs == -1 ? "impossible" : to_string(rs)) << "\n";
    }
    return 0;
}
# 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 1 ms 212 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 -
# 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 62 ms 2476 KB Output is correct
2 Correct 51 ms 2404 KB Output is correct
3 Correct 68 ms 2452 KB Output is correct
4 Incorrect 61 ms 2352 KB Output isn't correct
5 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 -