Submission #649742

# Submission time Handle Problem Language Result Execution time Memory
649742 2022-10-11T09:47:41 Z ToroTN Event Hopping (BOI22_events) C++14
100 / 100
138 ms 19192 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define X first
#define Y second
pair<int,int> seg[400005];
int n,t,s[100005],e[100005],l,r,x,y,idx[100005],it,p[100005][25],num,ex[100005],ans;
vector<tuple<int,int,int> > v;
void build(int tree,int st,int ed)
{
    int md=(st+ed)/2;
    if(st==ed)
    {
        seg[tree]={get<1>(v[st]),st};
        return;
    }
    build(2*tree,st,md);
    build(2*tree+1,md+1,ed);
    seg[tree]=max(seg[2*tree],seg[2*tree+1]);
}
pair<int,int> query(int tree,int st,int ed,int l,int r)
{
    int md=(st+ed)/2;
    if(st>r||ed<l)
    {
        return {(int)-2e9,(int)-2e9};
    }
    if(st>=l&&ed<=r)return seg[tree];
    return max(query(2*tree,st,md,l,r),query(2*tree+1,md+1,ed,l,r));
}
int main()
{
    scanf("%d%d",&n,&t);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&s[i],&e[i]);
        v.pb({-e[i],-s[i],i});
    }
    v.pb({-2e9,-2e9,-2e9});
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++)
    {
        idx[get<2>(v[i])]=i;
        l=get<0>(v[i]);
        r=get<1>(v[i]);
        //printf("%d %d %d\n",l,r,i);
    }
    build(1,1,n);
    for(int i=1;i<=n;i++)
    {
        it=lower_bound(v.begin(),v.end(),make_tuple(get<1>(v[i])+1,-2e9,-2e9))-v.begin()-1;
        num=query(1,1,n,i+1,it).Y;
        ex[i]=it;
        p[i][0]=num;
        //printf("itnum=%d %d\n",it,num);
    }
    for(int i=1;i<=n;i++)
    {
        if(p[i][0]<1||p[i][0]>n)p[i][0]=i;
    }
    for(int i=1;i<=20;i++)
    {
        for(int j=1;j<=n;j++)
        {
            p[j][i]=p[p[j][i-1]][i-1];
        }
    }
    while(t--)
    {
        scanf("%d%d",&x,&y);
        if(x==y)
        {
            printf("0\n");
            continue;
        }
        if(e[x]>e[y])
        {
            printf("impossible\n");
            continue;
        }
        x=idx[x];
        y=idx[y];
        ans=0;
        //printf("y=%d x=%d\n",y,x);
        for(int i=20;i>=0;i--)
        {
            //printf("%d\n",p[y][i]);
            if(p[y][i]<x&&ex[p[y][i]]<x)
            {
                if(y!=p[y][i])
                {
                    y=p[y][i];
                    ans+=(1<<i);
                }
                /*y=p[y][i];
                ans+=(1<<i);*/
            }
            //printf("%d %d\n",i,y);
        }
        if(x<=ex[y])
        {
            printf("%d\n",ans+1);
        }else if(x<=ex[p[y][0]])
        {
            printf("%d\n",ans+2);
        }else
        {
            printf("impossible\n");

        }
    }
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d%d",&n,&t);
      |     ~~~~~^~~~~~~~~~~~~~
events.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         scanf("%d%d",&s[i],&e[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
events.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 104 ms 15592 KB Output is correct
3 Correct 105 ms 15576 KB Output is correct
4 Correct 125 ms 15552 KB Output is correct
5 Correct 102 ms 15588 KB Output is correct
6 Correct 101 ms 15564 KB Output is correct
7 Correct 105 ms 15648 KB Output is correct
8 Correct 92 ms 15984 KB Output is correct
9 Correct 95 ms 15988 KB Output is correct
10 Correct 120 ms 15936 KB Output is correct
11 Correct 110 ms 16016 KB Output is correct
12 Correct 79 ms 16024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 452 KB Output is correct
13 Correct 1 ms 448 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 504 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 38 ms 2608 KB Output is correct
20 Correct 43 ms 2672 KB Output is correct
21 Correct 36 ms 2872 KB Output is correct
22 Correct 30 ms 2896 KB Output is correct
23 Correct 32 ms 2828 KB Output is correct
24 Correct 30 ms 2820 KB Output is correct
25 Correct 33 ms 2452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 70 ms 16956 KB Output is correct
20 Correct 66 ms 16092 KB Output is correct
21 Correct 87 ms 16808 KB Output is correct
22 Correct 76 ms 16916 KB Output is correct
23 Correct 69 ms 16916 KB Output is correct
24 Correct 76 ms 16908 KB Output is correct
25 Correct 67 ms 16192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 15624 KB Output is correct
2 Correct 107 ms 15508 KB Output is correct
3 Correct 108 ms 15540 KB Output is correct
4 Correct 92 ms 16036 KB Output is correct
5 Correct 111 ms 15960 KB Output is correct
6 Correct 120 ms 15668 KB Output is correct
7 Correct 123 ms 15640 KB Output is correct
8 Correct 105 ms 15828 KB Output is correct
9 Correct 60 ms 14972 KB Output is correct
10 Correct 105 ms 15324 KB Output is correct
11 Correct 105 ms 15124 KB Output is correct
12 Correct 105 ms 15364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 104 ms 15592 KB Output is correct
3 Correct 105 ms 15576 KB Output is correct
4 Correct 125 ms 15552 KB Output is correct
5 Correct 102 ms 15588 KB Output is correct
6 Correct 101 ms 15564 KB Output is correct
7 Correct 105 ms 15648 KB Output is correct
8 Correct 92 ms 15984 KB Output is correct
9 Correct 95 ms 15988 KB Output is correct
10 Correct 120 ms 15936 KB Output is correct
11 Correct 110 ms 16016 KB Output is correct
12 Correct 79 ms 16024 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 2 ms 500 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 452 KB Output is correct
25 Correct 1 ms 448 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 504 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 38 ms 2608 KB Output is correct
32 Correct 43 ms 2672 KB Output is correct
33 Correct 36 ms 2872 KB Output is correct
34 Correct 30 ms 2896 KB Output is correct
35 Correct 32 ms 2828 KB Output is correct
36 Correct 30 ms 2820 KB Output is correct
37 Correct 33 ms 2452 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 504 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 70 ms 16956 KB Output is correct
48 Correct 66 ms 16092 KB Output is correct
49 Correct 87 ms 16808 KB Output is correct
50 Correct 76 ms 16916 KB Output is correct
51 Correct 69 ms 16916 KB Output is correct
52 Correct 76 ms 16908 KB Output is correct
53 Correct 67 ms 16192 KB Output is correct
54 Correct 104 ms 15624 KB Output is correct
55 Correct 107 ms 15508 KB Output is correct
56 Correct 108 ms 15540 KB Output is correct
57 Correct 92 ms 16036 KB Output is correct
58 Correct 111 ms 15960 KB Output is correct
59 Correct 120 ms 15668 KB Output is correct
60 Correct 123 ms 15640 KB Output is correct
61 Correct 105 ms 15828 KB Output is correct
62 Correct 60 ms 14972 KB Output is correct
63 Correct 105 ms 15324 KB Output is correct
64 Correct 105 ms 15124 KB Output is correct
65 Correct 105 ms 15364 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 101 ms 18712 KB Output is correct
68 Correct 108 ms 18640 KB Output is correct
69 Correct 113 ms 18580 KB Output is correct
70 Correct 110 ms 18748 KB Output is correct
71 Correct 106 ms 18704 KB Output is correct
72 Correct 106 ms 18824 KB Output is correct
73 Correct 96 ms 19120 KB Output is correct
74 Correct 96 ms 19140 KB Output is correct
75 Correct 131 ms 19192 KB Output is correct
76 Correct 115 ms 19096 KB Output is correct
77 Correct 89 ms 18316 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 2 ms 500 KB Output is correct
80 Correct 1 ms 468 KB Output is correct
81 Correct 1 ms 448 KB Output is correct
82 Correct 1 ms 468 KB Output is correct
83 Correct 1 ms 468 KB Output is correct
84 Correct 2 ms 468 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 36 ms 2624 KB Output is correct
87 Correct 36 ms 2672 KB Output is correct
88 Correct 37 ms 2892 KB Output is correct
89 Correct 31 ms 2960 KB Output is correct
90 Correct 35 ms 2888 KB Output is correct
91 Correct 30 ms 2760 KB Output is correct
92 Correct 32 ms 2480 KB Output is correct
93 Correct 72 ms 16920 KB Output is correct
94 Correct 67 ms 16056 KB Output is correct
95 Correct 83 ms 16768 KB Output is correct
96 Correct 78 ms 16956 KB Output is correct
97 Correct 65 ms 16944 KB Output is correct
98 Correct 77 ms 16928 KB Output is correct
99 Correct 66 ms 16144 KB Output is correct
100 Correct 132 ms 18724 KB Output is correct
101 Correct 138 ms 18812 KB Output is correct
102 Correct 115 ms 18876 KB Output is correct
103 Correct 105 ms 18412 KB Output is correct
104 Correct 109 ms 18264 KB Output is correct
105 Correct 127 ms 18532 KB Output is correct
106 Correct 123 ms 18084 KB Output is correct
107 Correct 133 ms 18076 KB Output is correct
108 Correct 117 ms 18708 KB Output is correct
109 Correct 112 ms 18760 KB Output is correct
110 Correct 132 ms 18612 KB Output is correct
111 Correct 135 ms 18720 KB Output is correct