Submission #637070

# Submission time Handle Problem Language Result Execution time Memory
637070 2022-08-31T11:47:45 Z DJeniUp Event Hopping (BOI22_events) C++17
100 / 100
241 ms 32808 KB
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<ll,ll>pairll;
typedef long double ld;

#define fr first
#define sc second
#define pb push_back
#define INF 1000000000007
#define N 100007
#define endl '\n'
#define MOD 998244353

ll n,m,f[100007],a[100007],p[N][27];

pairll t[4*N];

priority_queue<pairll, vector<pairll>, greater<pairll> >q;

struct D{
    ll l,r,num;
}d[N];

bool mcp(D d1, D d2){
    return d1.r<d2.r;
}

void BT(ll x,ll l,ll r){
    if(l==r){
        t[x]={d[l].l,l};
        return ;
    }
    ll m1=(l+r)/2;
    BT(x*2+1,l,m1);
    BT(x*2+2,m1+1,r);
    if(t[x*2+1].fr<t[x*2+2].fr){
        t[x]=t[x*2+1];
    }else{
        t[x]=t[x*2+2];
    }
    return ;
}

pairll R(ll x,ll l,ll r,ll tl,ll tr){
    if(tr<tl)return {INF,0};
    if(r<tl || tr<l)return {INF,0};
    if(tl<=l && r<=tr)return t[x];
    ll m1=(l+r)/2;
    pairll m2=R(x*2+1,l,m1,tl,tr);
    pairll m3=R(x*2+2,m1+1,r,tl,tr);
    if(m2.fr<m3.fr)return m2;
    return m3;
}

pairll S(ll x,ll y){
    if(d[x].l<=d[y].r)return {x,0};
    ll g=0;
    for(int i=20;i>=0;i--){
        if(d[p[x][i]].l>d[y].r){
            g+=(1<<i);
            x=p[x][i];
        }
    }
    return {x,g};
}
 
int main()
{
    //cin>>n>>m;
    scanf("%lld %lld", &n, &m);
    for(int i=1;i<=n;i++){
        ll x,y;
        //cin>>x>>y;
        scanf("%lld %lld", &x, &y);
        d[i]={x,y,i};
    }
    sort(d+1,d+1+n,mcp);
    for(int i=1;i<=n;i++){
        a[d[i].num]=i;
    }
    BT(0,1,n);
    for(int i=1;i<=n;i++){
        ll l=1;
        ll r=i;
        while(l<r){
            ll m1=(l+r)/2;
            if(d[m1].r<d[i].l)l=m1+1;
            else r=m1;
        }
        ll l1=1;
        ll r1=n;
        while(l1<r1){
            ll m1=(l1+r1+1)/2;
            if(d[m1].r>d[i].r)r1=m1-1;
            else l1=m1;
        }
        pairll m1=R(0,1,n,l,l1);
        if(m1.fr>=d[i].l)p[i][0]=0;
        else p[i][0]=m1.sc;
    }
    for(int i=1;i<=20;i++){
        for(int j=1;j<=n;j++){
            p[j][i]=p[p[j][i-1]][i-1];
        }
    }
    for(int i=1;i<=m;i++){
        ll x,y;
        //cin>>x>>y;
        scanf("%lld %lld", &x, &y);
        
        x=a[x];
        y=a[y];
        if(d[y].r<d[x].r){
            //cout<<"impossible"<<endl;
            printf("impossible\n");
            continue;
        }
        pairll m1=S(y,x);
        swap(x,y);
        if(x==y)printf("0\n");
        else {
            ll res=INF;
            ll h=m1.fr;
            ll g=m1.sc;
            for(int i=1;i<=10;i++){
                g++;
                if(d[h].l<=d[y].r && d[y].r<=d[h].r)res=min(res,g);
                h=p[h][0];
            }
            if(res==INF)cout<<"impossible"<<endl;
            else cout<<res<<endl;
        }
    }
    
    return 0;
}
 

Compilation message

events.cpp: In function 'int main()':
events.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     scanf("%lld %lld", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
events.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         scanf("%lld %lld", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
events.cpp:112:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |         scanf("%lld %lld", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 119 ms 29244 KB Output is correct
3 Correct 114 ms 29160 KB Output is correct
4 Correct 134 ms 29248 KB Output is correct
5 Correct 128 ms 29296 KB Output is correct
6 Correct 124 ms 29236 KB Output is correct
7 Correct 117 ms 29260 KB Output is correct
8 Correct 119 ms 29684 KB Output is correct
9 Correct 114 ms 32764 KB Output is correct
10 Correct 176 ms 32632 KB Output is correct
11 Correct 149 ms 32768 KB Output is correct
12 Correct 102 ms 32020 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 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 596 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 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 584 KB Output is correct
13 Correct 1 ms 584 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 580 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 42 ms 3244 KB Output is correct
20 Correct 37 ms 3292 KB Output is correct
21 Correct 42 ms 3492 KB Output is correct
22 Correct 35 ms 3560 KB Output is correct
23 Correct 33 ms 3444 KB Output is correct
24 Correct 30 ms 3404 KB Output is correct
25 Correct 49 ms 3012 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 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 82 ms 30572 KB Output is correct
20 Correct 77 ms 29816 KB Output is correct
21 Correct 107 ms 30524 KB Output is correct
22 Correct 86 ms 30576 KB Output is correct
23 Correct 79 ms 30552 KB Output is correct
24 Correct 87 ms 30496 KB Output is correct
25 Correct 49 ms 29900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 29260 KB Output is correct
2 Correct 117 ms 29240 KB Output is correct
3 Correct 131 ms 29176 KB Output is correct
4 Correct 122 ms 29772 KB Output is correct
5 Correct 166 ms 29620 KB Output is correct
6 Correct 197 ms 29428 KB Output is correct
7 Correct 193 ms 29368 KB Output is correct
8 Correct 159 ms 29508 KB Output is correct
9 Correct 75 ms 28620 KB Output is correct
10 Correct 123 ms 29020 KB Output is correct
11 Correct 123 ms 28876 KB Output is correct
12 Correct 122 ms 29048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 119 ms 29244 KB Output is correct
3 Correct 114 ms 29160 KB Output is correct
4 Correct 134 ms 29248 KB Output is correct
5 Correct 128 ms 29296 KB Output is correct
6 Correct 124 ms 29236 KB Output is correct
7 Correct 117 ms 29260 KB Output is correct
8 Correct 119 ms 29684 KB Output is correct
9 Correct 114 ms 32764 KB Output is correct
10 Correct 176 ms 32632 KB Output is correct
11 Correct 149 ms 32768 KB Output is correct
12 Correct 102 ms 32020 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 584 KB Output is correct
25 Correct 1 ms 584 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 580 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 42 ms 3244 KB Output is correct
32 Correct 37 ms 3292 KB Output is correct
33 Correct 42 ms 3492 KB Output is correct
34 Correct 35 ms 3560 KB Output is correct
35 Correct 33 ms 3444 KB Output is correct
36 Correct 30 ms 3404 KB Output is correct
37 Correct 49 ms 3012 KB Output is correct
38 Correct 1 ms 316 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Correct 82 ms 30572 KB Output is correct
48 Correct 77 ms 29816 KB Output is correct
49 Correct 107 ms 30524 KB Output is correct
50 Correct 86 ms 30576 KB Output is correct
51 Correct 79 ms 30552 KB Output is correct
52 Correct 87 ms 30496 KB Output is correct
53 Correct 49 ms 29900 KB Output is correct
54 Correct 123 ms 29260 KB Output is correct
55 Correct 117 ms 29240 KB Output is correct
56 Correct 131 ms 29176 KB Output is correct
57 Correct 122 ms 29772 KB Output is correct
58 Correct 166 ms 29620 KB Output is correct
59 Correct 197 ms 29428 KB Output is correct
60 Correct 193 ms 29368 KB Output is correct
61 Correct 159 ms 29508 KB Output is correct
62 Correct 75 ms 28620 KB Output is correct
63 Correct 123 ms 29020 KB Output is correct
64 Correct 123 ms 28876 KB Output is correct
65 Correct 122 ms 29048 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 120 ms 32308 KB Output is correct
68 Correct 120 ms 32296 KB Output is correct
69 Correct 139 ms 32448 KB Output is correct
70 Correct 119 ms 32332 KB Output is correct
71 Correct 130 ms 32344 KB Output is correct
72 Correct 118 ms 32384 KB Output is correct
73 Correct 122 ms 32808 KB Output is correct
74 Correct 114 ms 32804 KB Output is correct
75 Correct 167 ms 32700 KB Output is correct
76 Correct 153 ms 32756 KB Output is correct
77 Correct 103 ms 32080 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1 ms 596 KB Output is correct
80 Correct 2 ms 596 KB Output is correct
81 Correct 1 ms 596 KB Output is correct
82 Correct 2 ms 596 KB Output is correct
83 Correct 1 ms 596 KB Output is correct
84 Correct 1 ms 580 KB Output is correct
85 Correct 1 ms 596 KB Output is correct
86 Correct 39 ms 3212 KB Output is correct
87 Correct 39 ms 3264 KB Output is correct
88 Correct 45 ms 3536 KB Output is correct
89 Correct 33 ms 3532 KB Output is correct
90 Correct 35 ms 3384 KB Output is correct
91 Correct 30 ms 3364 KB Output is correct
92 Correct 36 ms 3020 KB Output is correct
93 Correct 84 ms 30540 KB Output is correct
94 Correct 78 ms 29780 KB Output is correct
95 Correct 97 ms 30512 KB Output is correct
96 Correct 87 ms 30624 KB Output is correct
97 Correct 82 ms 30524 KB Output is correct
98 Correct 95 ms 30592 KB Output is correct
99 Correct 49 ms 29848 KB Output is correct
100 Correct 221 ms 32436 KB Output is correct
101 Correct 241 ms 32492 KB Output is correct
102 Correct 148 ms 32588 KB Output is correct
103 Correct 124 ms 32136 KB Output is correct
104 Correct 161 ms 31920 KB Output is correct
105 Correct 163 ms 32076 KB Output is correct
106 Correct 159 ms 31736 KB Output is correct
107 Correct 206 ms 31788 KB Output is correct
108 Correct 137 ms 32376 KB Output is correct
109 Correct 145 ms 32436 KB Output is correct
110 Correct 182 ms 32280 KB Output is correct
111 Correct 154 ms 32388 KB Output is correct