Submission #604446

# Submission time Handle Problem Language Result Execution time Memory
604446 2022-07-25T06:37:51 Z krit3379 Event Hopping (BOI22_events) C++14
0 / 100
178 ms 22468 KB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 100005

struct A{
    int s,e,id;
    bool operator<(const A& o)const{
        if(e!=o.e)return e>o.e;
        return s<o.s;
    }
};

int s[N],e[N],dep[N],nxt[20][N],mi;
vector<int> g[N];
vector<A> edge;

void dfs(int s){
    for(auto x:g[s]){
        dep[x]=dep[s]+1;
        dfs(x);
    }
}

int main(){
    int n,q,i,j,a,b;
    scanf("%d %d",&n,&q);
    for(i=1;i<=n;i++){
        scanf("%d %d",&s[i],&e[i]);
        edge.push_back({s[i],e[i],i});
    }
    sort(edge.begin(),edge.end());
    mi=1e9;
    for(auto [s,e,id]:edge){
        if(mi<=e)nxt[0][id]=i;
        if(s<mi)mi=s,i=id;
    }
    for(i=1;i<=n;i++)g[nxt[0][i]].push_back(i);
    dfs(0);
    for(i=1;i<20;i++)for(j=1;j<=n;j++)nxt[i][j]=nxt[i-1][nxt[i-1][j]];
    while(q--){
        scanf("%d %d",&a,&b);
        if(dep[a]<dep[b])printf("impossible\n");
        else{
            int dif=dep[a]-dep[b];
            for(i=0;i<20;i++)if(dif&(1<<i))a=nxt[i][a];
            if(a==b)printf("%d\n",dif);
            else printf("impossible\n");
        }
    }
    return 0;
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:35:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   35 |     for(auto [s,e,id]:edge){
      |              ^
events.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d %d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~
events.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d %d",&s[i],&e[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
events.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 106 ms 19220 KB Output is correct
2 Correct 131 ms 22328 KB Output is correct
3 Correct 178 ms 22176 KB Output is correct
4 Correct 70 ms 17332 KB Output is correct
5 Correct 136 ms 21280 KB Output is correct
6 Incorrect 134 ms 22468 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -