Submission #660104

# Submission time Handle Problem Language Result Execution time Memory
660104 2022-11-20T11:08:41 Z Karuk Event Hopping (BOI22_events) C++14
70 / 100
1500 ms 129920 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
pair<int,int>max(pair<int,int>a,pair<int,int>b) {
    return a.first>b.first?a:b;
}
const int k=(1<<30);
unordered_map<int,pair<int,int> >maxv;
void upd(int x,int va,int ind) {
    pair<int,int>val={va,ind};
    while(x>0) {
        maxv[x]=max(maxv[x],val);
        x>>=1;
    }
}
pair<int,int> ask(int &from,int &to,int cur=1,int beg=0,int en=k-1) {
    if(from<=beg && en<=to)return maxv[cur];
    if(to<beg || en<from)return {-1,-1};
    int mid=(beg+en)>>1;
    return max(ask(from,to,cur<<1,beg,mid),ask(from,to,(cur<<1)|1,mid+1,en));
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,q;cin>>n>>q;
    pair<int,int>a[n];
    for(int i=0;i<n;i++) {
        int x,y;
        cin>>x>>y;
        a[i]={x,y};
        upd(y+k,k-x,i);
    }
    pair<int,int> prev[n][25];
    for(int i=0;i<n;i++) {
        pair<int,int>d=ask(a[i].first,a[i].second);
        d.first=k-d.first;
        prev[i][0]=d;
    }
    for(int j=1;j<25;j++) {
        for(int i=0;i<n;i++) {
            prev[i][j]=prev[prev[i][j-1].second][j-1];
        }
    }
    for(int i=0;i<q;i++) {
        int x,y;cin>>x>>y;x--;y--;
        if(x==y)cout<<0<<endl;
        else if(a[x].second>=a[y].first && a[x].second<=a[y].second)cout<<1<<endl;
        else if(a[x].second>a[y].second){cout<<"impossible"<<endl;}
        else {
            int cnt=0;
            int cur=y;
            int en=a[x].second;
            for(int j=24;j>=0;j--) {
                if(prev[cur][j].first>en) {
                    cur=prev[cur][j].second;
                    cnt+=(1<<j);
                }
            }
            if(prev[cur][0].first>en)cout<<"impossible"<<endl;
            else cout<<cnt+2<<endl;
        }
    }
    return 0;
}
///9:30
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1234 ms 116216 KB Output is correct
3 Correct 1192 ms 119316 KB Output is correct
4 Correct 1340 ms 121080 KB Output is correct
5 Correct 1216 ms 121848 KB Output is correct
6 Correct 1267 ms 121536 KB Output is correct
7 Correct 1252 ms 118244 KB Output is correct
8 Correct 1135 ms 113148 KB Output is correct
9 Correct 1232 ms 123936 KB Output is correct
10 Correct 1200 ms 115276 KB Output is correct
11 Correct 1212 ms 114188 KB Output is correct
12 Correct 186 ms 32316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 5 ms 1968 KB Output is correct
4 Correct 6 ms 1968 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 4 ms 1236 KB Output is correct
7 Correct 6 ms 1968 KB Output is correct
8 Correct 7 ms 2008 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 5 ms 1968 KB Output is correct
4 Correct 6 ms 1968 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 4 ms 1236 KB Output is correct
7 Correct 6 ms 1968 KB Output is correct
8 Correct 7 ms 2008 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1968 KB Output is correct
13 Correct 6 ms 1968 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 5 ms 1236 KB Output is correct
16 Correct 8 ms 1968 KB Output is correct
17 Correct 6 ms 1968 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 39 ms 2384 KB Output is correct
20 Correct 57 ms 7876 KB Output is correct
21 Correct 38 ms 2380 KB Output is correct
22 Correct 50 ms 5392 KB Output is correct
23 Correct 58 ms 8600 KB Output is correct
24 Correct 55 ms 8496 KB Output is correct
25 Correct 73 ms 10848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 5 ms 1968 KB Output is correct
4 Correct 6 ms 1968 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 4 ms 1236 KB Output is correct
7 Correct 6 ms 1968 KB Output is correct
8 Correct 7 ms 2008 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1968 KB Output is correct
13 Correct 7 ms 1968 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 4 ms 1244 KB Output is correct
16 Correct 7 ms 1968 KB Output is correct
17 Correct 6 ms 1968 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 1303 ms 116500 KB Output is correct
20 Correct 255 ms 29616 KB Output is correct
21 Correct 811 ms 70472 KB Output is correct
22 Correct 1075 ms 108276 KB Output is correct
23 Correct 1372 ms 121356 KB Output is correct
24 Correct 1429 ms 126044 KB Output is correct
25 Correct 209 ms 20544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1235 ms 116428 KB Output is correct
2 Correct 1160 ms 119228 KB Output is correct
3 Correct 1339 ms 120880 KB Output is correct
4 Correct 1220 ms 123904 KB Output is correct
5 Correct 1242 ms 115092 KB Output is correct
6 Correct 1441 ms 126968 KB Output is correct
7 Correct 1425 ms 126888 KB Output is correct
8 Correct 1405 ms 125400 KB Output is correct
9 Correct 1392 ms 121248 KB Output is correct
10 Correct 1424 ms 126376 KB Output is correct
11 Correct 1412 ms 125140 KB Output is correct
12 Correct 1414 ms 126376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1234 ms 116216 KB Output is correct
3 Correct 1192 ms 119316 KB Output is correct
4 Correct 1340 ms 121080 KB Output is correct
5 Correct 1216 ms 121848 KB Output is correct
6 Correct 1267 ms 121536 KB Output is correct
7 Correct 1252 ms 118244 KB Output is correct
8 Correct 1135 ms 113148 KB Output is correct
9 Correct 1232 ms 123936 KB Output is correct
10 Correct 1200 ms 115276 KB Output is correct
11 Correct 1212 ms 114188 KB Output is correct
12 Correct 186 ms 32316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 5 ms 1968 KB Output is correct
16 Correct 6 ms 1968 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 4 ms 1236 KB Output is correct
19 Correct 6 ms 1968 KB Output is correct
20 Correct 7 ms 2008 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 6 ms 1968 KB Output is correct
25 Correct 6 ms 1968 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 5 ms 1236 KB Output is correct
28 Correct 8 ms 1968 KB Output is correct
29 Correct 6 ms 1968 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 39 ms 2384 KB Output is correct
32 Correct 57 ms 7876 KB Output is correct
33 Correct 38 ms 2380 KB Output is correct
34 Correct 50 ms 5392 KB Output is correct
35 Correct 58 ms 8600 KB Output is correct
36 Correct 55 ms 8496 KB Output is correct
37 Correct 73 ms 10848 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 6 ms 1968 KB Output is correct
41 Correct 7 ms 1968 KB Output is correct
42 Correct 2 ms 596 KB Output is correct
43 Correct 4 ms 1244 KB Output is correct
44 Correct 7 ms 1968 KB Output is correct
45 Correct 6 ms 1968 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 1303 ms 116500 KB Output is correct
48 Correct 255 ms 29616 KB Output is correct
49 Correct 811 ms 70472 KB Output is correct
50 Correct 1075 ms 108276 KB Output is correct
51 Correct 1372 ms 121356 KB Output is correct
52 Correct 1429 ms 126044 KB Output is correct
53 Correct 209 ms 20544 KB Output is correct
54 Correct 1235 ms 116428 KB Output is correct
55 Correct 1160 ms 119228 KB Output is correct
56 Correct 1339 ms 120880 KB Output is correct
57 Correct 1220 ms 123904 KB Output is correct
58 Correct 1242 ms 115092 KB Output is correct
59 Correct 1441 ms 126968 KB Output is correct
60 Correct 1425 ms 126888 KB Output is correct
61 Correct 1405 ms 125400 KB Output is correct
62 Correct 1392 ms 121248 KB Output is correct
63 Correct 1424 ms 126376 KB Output is correct
64 Correct 1412 ms 125140 KB Output is correct
65 Correct 1414 ms 126376 KB Output is correct
66 Correct 0 ms 316 KB Output is correct
67 Correct 1262 ms 119408 KB Output is correct
68 Correct 1216 ms 122420 KB Output is correct
69 Correct 1329 ms 124072 KB Output is correct
70 Correct 1253 ms 125020 KB Output is correct
71 Correct 1261 ms 124692 KB Output is correct
72 Correct 1247 ms 121336 KB Output is correct
73 Correct 1146 ms 116044 KB Output is correct
74 Correct 1235 ms 126852 KB Output is correct
75 Correct 1203 ms 118244 KB Output is correct
76 Correct 1198 ms 117284 KB Output is correct
77 Correct 193 ms 34572 KB Output is correct
78 Correct 0 ms 320 KB Output is correct
79 Correct 6 ms 1968 KB Output is correct
80 Correct 6 ms 1964 KB Output is correct
81 Correct 2 ms 576 KB Output is correct
82 Correct 4 ms 1232 KB Output is correct
83 Correct 7 ms 2092 KB Output is correct
84 Correct 6 ms 1960 KB Output is correct
85 Correct 2 ms 460 KB Output is correct
86 Correct 37 ms 3368 KB Output is correct
87 Correct 56 ms 8940 KB Output is correct
88 Correct 42 ms 3468 KB Output is correct
89 Correct 42 ms 6364 KB Output is correct
90 Correct 61 ms 9680 KB Output is correct
91 Correct 55 ms 9604 KB Output is correct
92 Correct 67 ms 11052 KB Output is correct
93 Correct 1158 ms 118584 KB Output is correct
94 Correct 259 ms 30820 KB Output is correct
95 Correct 832 ms 72316 KB Output is correct
96 Correct 1068 ms 110208 KB Output is correct
97 Correct 1404 ms 123096 KB Output is correct
98 Correct 1370 ms 128068 KB Output is correct
99 Correct 204 ms 21928 KB Output is correct
100 Execution timed out 1507 ms 129920 KB Time limit exceeded
101 Halted 0 ms 0 KB -