Submission #660093

# Submission time Handle Problem Language Result Execution time Memory
660093 2022-11-20T10:47:33 Z Karuk Event Hopping (BOI22_events) C++14
25 / 100
1500 ms 174508 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>b?a:b;
}
const int k=(1<<30);
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)/2;
    return max(ask(from,to,cur*2,beg,mid),ask(from,to,cur*2+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 0 ms 320 KB Output is correct
2 Execution timed out 1534 ms 165292 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 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 9 ms 2644 KB Output is correct
4 Correct 9 ms 2772 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 8 ms 1672 KB Output is correct
7 Correct 11 ms 2900 KB Output is correct
8 Correct 13 ms 2852 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 9 ms 2644 KB Output is correct
4 Correct 9 ms 2772 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 8 ms 1672 KB Output is correct
7 Correct 11 ms 2900 KB Output is correct
8 Correct 13 ms 2852 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 10 ms 2752 KB Output is correct
13 Correct 9 ms 2772 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 10 ms 1708 KB Output is correct
16 Correct 12 ms 2900 KB Output is correct
17 Correct 11 ms 2900 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 43 ms 2548 KB Output is correct
20 Correct 77 ms 11364 KB Output is correct
21 Correct 42 ms 2732 KB Output is correct
22 Correct 85 ms 7300 KB Output is correct
23 Correct 98 ms 12732 KB Output is correct
24 Correct 85 ms 12436 KB Output is correct
25 Correct 94 ms 12612 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 9 ms 2644 KB Output is correct
4 Correct 9 ms 2772 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 8 ms 1672 KB Output is correct
7 Correct 11 ms 2900 KB Output is correct
8 Correct 13 ms 2852 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 2644 KB Output is correct
13 Correct 9 ms 2800 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 8 ms 1668 KB Output is correct
16 Correct 11 ms 2900 KB Output is correct
17 Correct 12 ms 2900 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 1469 ms 166504 KB Output is correct
20 Correct 502 ms 33132 KB Output is correct
21 Correct 1349 ms 97632 KB Output is correct
22 Correct 1377 ms 149916 KB Output is correct
23 Execution timed out 1584 ms 159196 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1426 ms 165348 KB Output is correct
2 Correct 1464 ms 171144 KB Output is correct
3 Execution timed out 1502 ms 174508 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Execution timed out 1534 ms 165292 KB Time limit exceeded
3 Halted 0 ms 0 KB -