답안 #649726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
649726 2022-10-11T09:22:39 Z ToroTN Event Hopping (BOI22_events) C++14
30 / 100
133 ms 19176 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(e[x]>e[y])
        {
            printf("impossible\n");
            continue;
        }
        x=idx[x];
        y=idx[y];
        ans=0;
        //printf("%d %d\n",y,x);
        for(int i=20;i>=0;i--)
        {
            if(p[y][i]<x)
            {
                if(y!=p[y][i])
                {
                    y=p[y][i];
                    ans+=(1<<i);
                }
                /*y=p[y][i];
                ans+=(1<<i);*/
            }
        }
        if(x==y)
        {
            printf("0\n");
            continue;
        }
        if(x<=ex[y])
        {
            printf("%d\n",ans+1);
        }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);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 106 ms 16348 KB Output is correct
3 Correct 104 ms 16316 KB Output is correct
4 Correct 113 ms 16296 KB Output is correct
5 Correct 108 ms 16424 KB Output is correct
6 Correct 105 ms 16392 KB Output is correct
7 Correct 105 ms 16408 KB Output is correct
8 Correct 109 ms 16736 KB Output is correct
9 Correct 94 ms 19176 KB Output is correct
10 Correct 120 ms 18968 KB Output is correct
11 Correct 115 ms 19112 KB Output is correct
12 Correct 85 ms 18368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 1 ms 468 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 1 ms 468 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 1 ms 468 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 16252 KB Output is correct
2 Correct 105 ms 16420 KB Output is correct
3 Correct 106 ms 16252 KB Output is correct
4 Correct 90 ms 16832 KB Output is correct
5 Correct 127 ms 16668 KB Output is correct
6 Correct 132 ms 16516 KB Output is correct
7 Correct 133 ms 16444 KB Output is correct
8 Correct 110 ms 16596 KB Output is correct
9 Correct 62 ms 15744 KB Output is correct
10 Correct 106 ms 16176 KB Output is correct
11 Correct 105 ms 15908 KB Output is correct
12 Correct 107 ms 16152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 106 ms 16348 KB Output is correct
3 Correct 104 ms 16316 KB Output is correct
4 Correct 113 ms 16296 KB Output is correct
5 Correct 108 ms 16424 KB Output is correct
6 Correct 105 ms 16392 KB Output is correct
7 Correct 105 ms 16408 KB Output is correct
8 Correct 109 ms 16736 KB Output is correct
9 Correct 94 ms 19176 KB Output is correct
10 Correct 120 ms 18968 KB Output is correct
11 Correct 115 ms 19112 KB Output is correct
12 Correct 85 ms 18368 KB Output is correct
13 Correct 1 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 Incorrect 1 ms 468 KB Output isn't correct
19 Halted 0 ms 0 KB -