Submission #656523

# Submission time Handle Problem Language Result Execution time Memory
656523 2022-11-07T18:49:30 Z Lobo Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 10700 KB
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 1e5+10;

int n, q, lf[maxn], rg[maxn], sq[maxn], eq[maxn], ansq[maxn], atv[maxn];
vector<int> qrys[maxn];
void solve() {
    cin >> n >> q;
    vector<pair<pair<int,int>,int>> ord; // first smaller rg and smaller lf
    for(int i = 1; i <= n; i++) {
        cin >> lf[i] >> rg[i];
        ord.pb(mp(mp(rg[i],lf[i]),i));
    }
    sort(all(ord));

    for(int i = 1; i <= q; i++) {
        cin >> sq[i] >> eq[i];
        qrys[eq[i]].pb(i);
    }

    for(auto X : ord) {
        int i = X.sc;
        // cout << i << endl;
        atv[i] = 1;

        for(auto id : qrys[i]) {
            // cout << " " << id << endl;
            int j = sq[id];
            if(i == j) {
                ansq[id] = 0;
                continue;
            }
            if(rg[i] == rg[j]) {
                ansq[id] = 1;
                continue;
            }
            if(atv[j] == 0) {
                ansq[id] = -1;
                continue;
            }
            ansq[id] = 0;
            while(j != i) {
                int nx = -1;
                for(int k = 1; k <= n; k++) {
                    if(atv[k] == 0 || lf[k] > rg[j]) continue;
                    if(nx == -1 || rg[nx] < rg[k]) nx = k;
                }
                if(nx == j) {
                    ansq[id] = -1;
                    break;
                }
                j = nx;
                ansq[id]++;
                if(j == i) {
                    break;
                }
                if(rg[j] == rg[i]) {
                    ansq[id]++;
                    break;
                }
            }
        }
    }

    for(int i = 1; i <= q; i++) {
        if(ansq[i] == -1) cout << "impossible" << endl;
        else cout << ansq[i] << endl;
    }
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Execution timed out 1583 ms 10700 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 209 ms 2644 KB Output is correct
4 Correct 26 ms 2772 KB Output is correct
5 Correct 34 ms 2644 KB Output is correct
6 Incorrect 2 ms 2772 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 209 ms 2644 KB Output is correct
4 Correct 26 ms 2772 KB Output is correct
5 Correct 34 ms 2644 KB Output is correct
6 Incorrect 2 ms 2772 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 209 ms 2644 KB Output is correct
4 Correct 26 ms 2772 KB Output is correct
5 Correct 34 ms 2644 KB Output is correct
6 Incorrect 2 ms 2772 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1572 ms 10680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Execution timed out 1583 ms 10700 KB Time limit exceeded
3 Halted 0 ms 0 KB -