답안 #593940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593940 2022-07-11T17:47:11 Z azberjibiou Event Hopping (BOI22_events) C++17
100 / 100
900 ms 13192 KB
#include <bits/stdc++.h>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fir first
#define sec second
#define pdd pair<long double, long double>
#define pii pair<int, int>
#define pll pair<ll, ll>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
const int mxN=100010;
const int MOD=1e9+7;
int N, Q, M;
pii A[mxN];
vector <int> coor;
int sps[mxN][18];
int mins[mxN];
int ans[mxN];
pii rng[mxN];
pii qry[mxN];
void make_coor()
{
    for(int i=1;i<=N;i++)   coor.push_back(A[i].sec);
    sort(coor.begin(), coor.end());
    coor.erase(unique(coor.begin(), coor.end()), coor.end());
    for(int i=1;i<=N;i++)   A[i].fir=lower_bound(coor.begin(), coor.end(), A[i].fir)-coor.begin();
    for(int i=1;i<=N;i++)   A[i].sec=lower_bound(coor.begin(), coor.end(), A[i].sec)-coor.begin();
    M=coor.size();
}
int seg[4*mxN];
void init(int idx, int s, int e)
{
    if(s==e)
    {
        seg[idx]=mins[s];
        return;
    }
    int mid=(s+e)/2;
    init(2*idx, s, mid);
    init(2*idx+1, mid+1, e);
    seg[idx]=min(seg[2*idx], seg[2*idx+1]);
}
int solv(int idx, int s1, int e1, int s2, int e2)
{
    if(s2>e1 || s1>e2)  return M;
    if(s2<=s1 && e1<=e2)    return seg[idx];
    int mid=(s1+e1)/2;
    return min(solv(2*idx, s1, mid, s2, e2), solv(2*idx+1, mid+1, e1, s2, e2));
}
int main()
{
    gibon
    cin >> N >> Q;
    for(int i=1;i<=N;i++)   cin >> A[i].fir >> A[i].sec;
    make_coor();
    for(int i=1;i<=N;i++)   sps[i][0]=A[i].fir;
    for(int i=1;i<18;i++)
    {
        for(int j=0;j<M;j++)    mins[j]=M;
        for(int j=1;j<=N;j++)   mins[A[j].sec]=min(mins[A[j].sec], sps[j][i-1]);
        init(1, 0, M-1);
        for(int j=1;j<=N;j++)   sps[j][i]=solv(1, 0, M-1, sps[j][i-1], A[j].sec);
    }
    for(int i=1;i<=Q;i++)   cin >> qry[i].fir >> qry[i].sec;
    for(int i=1;i<=Q;i++)   rng[i]=A[qry[i].sec];
    for(int i=16;i>=0;i--)
    {
        for(int j=0;j<M;j++)    mins[j]=M;
        for(int j=1;j<=N;j++)   mins[A[j].sec]=min(mins[A[j].sec], sps[j][i]);
        init(1, 0, M-1);
        for(int j=1;j<=Q;j++)
        {
            int res=solv(1, 0, M-1, rng[j].fir, rng[j].sec);
            if(res>A[qry[j].fir].sec)   ans[j]+=(1<<i), rng[j].fir=res;
        }
    }
    for(int i=1;i<=Q;i++)
    {
        if(sps[qry[i].sec][17]>A[qry[i].fir].sec || A[qry[i].sec].sec<A[qry[i].fir].sec)    cout << "impossible\n";
        else if(qry[i].sec==qry[i].fir) cout << "0\n";
        else if(A[qry[i].sec].fir<=A[qry[i].fir].sec)   cout << "1\n";
        else    cout << ans[i]+2 << '\n';
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 560 ms 12632 KB Output is correct
3 Correct 702 ms 12632 KB Output is correct
4 Correct 718 ms 12628 KB Output is correct
5 Correct 690 ms 12748 KB Output is correct
6 Correct 685 ms 12636 KB Output is correct
7 Correct 671 ms 12680 KB Output is correct
8 Correct 481 ms 13192 KB Output is correct
9 Correct 498 ms 13076 KB Output is correct
10 Correct 737 ms 13004 KB Output is correct
11 Correct 737 ms 12996 KB Output is correct
12 Correct 285 ms 12368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 211 ms 3188 KB Output is correct
20 Correct 203 ms 3312 KB Output is correct
21 Correct 270 ms 3516 KB Output is correct
22 Correct 237 ms 3532 KB Output is correct
23 Correct 328 ms 3128 KB Output is correct
24 Correct 184 ms 3056 KB Output is correct
25 Correct 190 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 4 ms 432 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 414 ms 10028 KB Output is correct
20 Correct 422 ms 10188 KB Output is correct
21 Correct 316 ms 9296 KB Output is correct
22 Correct 391 ms 10164 KB Output is correct
23 Correct 313 ms 10092 KB Output is correct
24 Correct 390 ms 10072 KB Output is correct
25 Correct 41 ms 8684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 538 ms 12528 KB Output is correct
2 Correct 697 ms 12640 KB Output is correct
3 Correct 717 ms 12528 KB Output is correct
4 Correct 472 ms 13164 KB Output is correct
5 Correct 741 ms 13004 KB Output is correct
6 Correct 802 ms 12884 KB Output is correct
7 Correct 810 ms 12680 KB Output is correct
8 Correct 845 ms 12900 KB Output is correct
9 Correct 300 ms 10088 KB Output is correct
10 Correct 642 ms 12508 KB Output is correct
11 Correct 598 ms 12268 KB Output is correct
12 Correct 637 ms 12368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 560 ms 12632 KB Output is correct
3 Correct 702 ms 12632 KB Output is correct
4 Correct 718 ms 12628 KB Output is correct
5 Correct 690 ms 12748 KB Output is correct
6 Correct 685 ms 12636 KB Output is correct
7 Correct 671 ms 12680 KB Output is correct
8 Correct 481 ms 13192 KB Output is correct
9 Correct 498 ms 13076 KB Output is correct
10 Correct 737 ms 13004 KB Output is correct
11 Correct 737 ms 12996 KB Output is correct
12 Correct 285 ms 12368 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 3 ms 432 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 211 ms 3188 KB Output is correct
32 Correct 203 ms 3312 KB Output is correct
33 Correct 270 ms 3516 KB Output is correct
34 Correct 237 ms 3532 KB Output is correct
35 Correct 328 ms 3128 KB Output is correct
36 Correct 184 ms 3056 KB Output is correct
37 Correct 190 ms 3028 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 4 ms 432 KB Output is correct
42 Correct 3 ms 340 KB Output is correct
43 Correct 3 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 414 ms 10028 KB Output is correct
48 Correct 422 ms 10188 KB Output is correct
49 Correct 316 ms 9296 KB Output is correct
50 Correct 391 ms 10164 KB Output is correct
51 Correct 313 ms 10092 KB Output is correct
52 Correct 390 ms 10072 KB Output is correct
53 Correct 41 ms 8684 KB Output is correct
54 Correct 538 ms 12528 KB Output is correct
55 Correct 697 ms 12640 KB Output is correct
56 Correct 717 ms 12528 KB Output is correct
57 Correct 472 ms 13164 KB Output is correct
58 Correct 741 ms 13004 KB Output is correct
59 Correct 802 ms 12884 KB Output is correct
60 Correct 810 ms 12680 KB Output is correct
61 Correct 845 ms 12900 KB Output is correct
62 Correct 300 ms 10088 KB Output is correct
63 Correct 642 ms 12508 KB Output is correct
64 Correct 598 ms 12268 KB Output is correct
65 Correct 637 ms 12368 KB Output is correct
66 Correct 0 ms 340 KB Output is correct
67 Correct 543 ms 12528 KB Output is correct
68 Correct 705 ms 12648 KB Output is correct
69 Correct 722 ms 12556 KB Output is correct
70 Correct 690 ms 12656 KB Output is correct
71 Correct 671 ms 12760 KB Output is correct
72 Correct 678 ms 12660 KB Output is correct
73 Correct 485 ms 13180 KB Output is correct
74 Correct 472 ms 13040 KB Output is correct
75 Correct 746 ms 12940 KB Output is correct
76 Correct 771 ms 12944 KB Output is correct
77 Correct 314 ms 12384 KB Output is correct
78 Correct 0 ms 340 KB Output is correct
79 Correct 3 ms 340 KB Output is correct
80 Correct 3 ms 340 KB Output is correct
81 Correct 3 ms 340 KB Output is correct
82 Correct 2 ms 340 KB Output is correct
83 Correct 3 ms 340 KB Output is correct
84 Correct 2 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 310 ms 3184 KB Output is correct
87 Correct 210 ms 3192 KB Output is correct
88 Correct 282 ms 3548 KB Output is correct
89 Correct 314 ms 3520 KB Output is correct
90 Correct 331 ms 3168 KB Output is correct
91 Correct 200 ms 2968 KB Output is correct
92 Correct 196 ms 3008 KB Output is correct
93 Correct 446 ms 10096 KB Output is correct
94 Correct 478 ms 10040 KB Output is correct
95 Correct 337 ms 9316 KB Output is correct
96 Correct 422 ms 10092 KB Output is correct
97 Correct 323 ms 10092 KB Output is correct
98 Correct 402 ms 10096 KB Output is correct
99 Correct 42 ms 8660 KB Output is correct
100 Correct 836 ms 12788 KB Output is correct
101 Correct 825 ms 12688 KB Output is correct
102 Correct 884 ms 12812 KB Output is correct
103 Correct 659 ms 12420 KB Output is correct
104 Correct 637 ms 12168 KB Output is correct
105 Correct 658 ms 12384 KB Output is correct
106 Correct 675 ms 12652 KB Output is correct
107 Correct 839 ms 12908 KB Output is correct
108 Correct 713 ms 12112 KB Output is correct
109 Correct 687 ms 12108 KB Output is correct
110 Correct 900 ms 12256 KB Output is correct
111 Correct 848 ms 12292 KB Output is correct