답안 #599864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
599864 2022-07-20T03:53:49 Z JooDdae Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 17988 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n, q, sp[100100][20], mn[100100][20], R[100100], rev[100100];
array<int, 3> a[100100];

int find(int a, int b){
    int k = 31 - __builtin_clz(b - a);
    return min(mn[a][k], mn[b-(1<<k)+1][k]);
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> q;
    for(int i=1;i<=n;i++) cin >> a[i][1] >> a[i][0], a[i][2] = i;
    sort(a+1, a+1+n);

    for(int i=n;i>=1;i--){
        auto [e, s, id] = a[i];

        R[i] = a[i+1][0] == e ? R[i+1] : i;
        rev[id] = i;
        sp[i][0] = mn[i][0] = lower_bound(a+1, a+1+n, array<int, 3>({s, 0, 0})) - a;
    }

    for(int j=1;j<20;j++) for(int i=1;i<=n;i++) if(i+(1<<j)-1 <= n) mn[i][j] = min(mn[i][j-1], mn[i+(1<<j-1)][j-1]);

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

        if(R[b] < a) {
            cout << "impossible\n";
        } else if(a == b) {
            cout << "0\n";
        } else {
            int ans = 0;
            
            while(a < b && ++ans){
                int l = b;
                b = find(b, e);

                if(b == l){
                    ans = -1;
                    break;
                }
            }
            
            if(ans < 0) cout << "impossible\n";
            else cout << ans << "\n";
        }
    }
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:27:106: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   27 |     for(int j=1;j<20;j++) for(int i=1;i<=n;i++) if(i+(1<<j)-1 <= n) mn[i][j] = min(mn[i][j-1], mn[i+(1<<j-1)][j-1]);
      |                                                                                                         ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Execution timed out 1572 ms 17988 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Incorrect 1 ms 468 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Incorrect 1 ms 468 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Incorrect 1 ms 468 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1556 ms 17924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Execution timed out 1572 ms 17988 KB Time limit exceeded
3 Halted 0 ms 0 KB -