# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
603237 | 2022-07-23T17:56:23 Z | peuch | Event Hopping (BOI22_events) | C++17 | 269 ms | 13592 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int MAXK = 22; int n, q; struct interval{ int l, r, id; interval (int _l = 0, int _r = 0){ l = _l; r = _r; id = 0; } void scan(int _id){ scanf("%d %d", &l, &r); id = _id; } bool operator < (interval x){ if(r == x.r) return l < x.l; return r < x.r; } }v[MAXN], ori[MAXN]; int dp[MAXN][MAXK]; int getDP(int i, int j){ if(dp[i][j] != 0) return dp[i][j]; return dp[i][j] = getDP(getDP(i, j - 1), j - 1); } int main(){ scanf("%d %d", &n, &q); for(int i = 1; i <= n; i++){ v[i].scan(i); ori[i] = v[i]; } sort(v + 1, v + 1 + n); vector<interval > pilha; for(int i = 1; i <= n; i++){ while(!pilha.empty() && pilha.back().l >= v[i].l) pilha.pop_back(); pilha.push_back(v[i]); int k = lower_bound(pilha.begin(), pilha.end(), interval(-1, v[i].l)) - pilha.begin(); dp[v[i].id][0] = pilha[k].id; } for(int i = 1; i <= q; i++){ int a, b; scanf("%d %d", &a, &b); if(a == b){ printf("0\n"); continue; } if(ori[b].r < ori[a].r){ printf("impossible\n"); continue; } if(ori[a].r >= ori[b].l && ori[a].r >= ori[b].r){ printf("1\n"); continue; } int ans = 0; for(int k = MAXK - 1; k >= 0; k--){ int viz = getDP(b, k); if(ori[viz].l <= ori[a].r) continue; b = viz; ans += (1 << k); } if(getDP(b, 0) == b){ printf("impossible\n"); continue; } ans += 2; printf("%d\n", ans); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 83 ms | 13144 KB | Output is correct |
3 | Correct | 182 ms | 13464 KB | Output is correct |
4 | Incorrect | 269 ms | 13412 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 2 ms | 2644 KB | Output is correct |
3 | Correct | 2 ms | 2644 KB | Output is correct |
4 | Incorrect | 2 ms | 2664 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 2 ms | 2644 KB | Output is correct |
3 | Correct | 2 ms | 2644 KB | Output is correct |
4 | Incorrect | 2 ms | 2664 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 2 ms | 2644 KB | Output is correct |
3 | Correct | 2 ms | 2644 KB | Output is correct |
4 | Incorrect | 2 ms | 2664 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 88 ms | 13300 KB | Output is correct |
2 | Correct | 156 ms | 13564 KB | Output is correct |
3 | Incorrect | 243 ms | 13592 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 83 ms | 13144 KB | Output is correct |
3 | Correct | 182 ms | 13464 KB | Output is correct |
4 | Incorrect | 269 ms | 13412 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |