Submission #656527

# Submission time Handle Problem Language Result Execution time Memory
656527 2022-11-07T18:59:27 Z Lobo Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 10692 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(k == i) {
                        nx = k;
                        break;
                    }
                    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 1585 ms 10692 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 1 ms 2644 KB Output is correct
3 Correct 244 ms 2760 KB Output is correct
4 Correct 27 ms 2644 KB Output is correct
5 Correct 42 ms 2644 KB Output is correct
6 Correct 3 ms 2772 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 244 ms 2760 KB Output is correct
4 Correct 27 ms 2644 KB Output is correct
5 Correct 42 ms 2644 KB Output is correct
6 Correct 3 ms 2772 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 246 ms 2776 KB Output is correct
13 Correct 26 ms 2688 KB Output is correct
14 Correct 46 ms 2772 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 2 ms 2692 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Execution timed out 1583 ms 6608 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 244 ms 2760 KB Output is correct
4 Correct 27 ms 2644 KB Output is correct
5 Correct 42 ms 2644 KB Output is correct
6 Correct 3 ms 2772 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 238 ms 2776 KB Output is correct
13 Correct 33 ms 2696 KB Output is correct
14 Correct 44 ms 2772 KB Output is correct
15 Correct 3 ms 2688 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Execution timed out 1560 ms 9344 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1588 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 1585 ms 10692 KB Time limit exceeded
3 Halted 0 ms 0 KB -