Submission #714302

# Submission time Handle Problem Language Result Execution time Memory
714302 2023-03-24T08:15:43 Z vjudge1 Event Hopping (BOI22_events) C++17
25 / 100
1500 ms 24616 KB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const int N=100'010;
const int LG=20;
struct event {
  int s, e, idx;
};
event es[N];
struct Binary_Lifting {
  int up[N][LG];
  void add(int node, int par) {
    up[node][0]=par;
    for(int i = 1;i<LG;i++) {
      up[node][i]=up[up[node][i-1]][i-1];
    }
  }
  int get(int start, int num) {
    if(es[start].e>=num)return 1;
    int res=1;
    for(int i = LG-1;i>=0;i--) {
      if(es[up[start][i]].e<num) {
        start=up[start][i];
        res+=(1<<i);
      }
    }
    if(es[up[start][0]].e>=num)return res+1;
    return -1;
  }
};
bool operator<(const event &a, const event &b) {
  return a.e>b.e;
}
Binary_Lifting bl;
vector<int> child[N];
int out[N];
void dfs(int at) {
  for(int to:child[at]){ 
    bl.add(to,at);  
    dfs(to);
  }
}
int main () {
  cin.tie(0)->sync_with_stdio(0);
  int n, q;
  cin >> n >> q;
  map<int,int> cc;
  for(int i = 0;i<n;i++) {
    cin >> es[i].e >> es[i].s;
    es[i].s*=-1;
    es[i].e*=-1;
    cc[es[i].s]=1;
    cc[es[i].e]=1;
    es[i].idx=i;
  }
  vector<event> on[2*n], off[2*n];
  {
    int cnt=0;
    for(auto &i:cc) {
      i.second=cnt++;
    }
    for(int i = 0;i<n;i++) {
      es[i].s=cc[es[i].s];
      es[i].e=cc[es[i].e];
    }
  }
  for(int i = 0;i<n;i++) {
    on[es[i].e].push_back(es[i]);
    off[es[i].s].push_back(es[i]);
  }
  multiset<event, less<>> ms;
  for(int i = 0;i<n;i++) {
    int mx=i;
    for(int j = 0;j<n;j++) {
      if(i==j)continue;
      if(es[i].s<=es[j].s and es[mx].e<es[j].e and es[j].s <= es[i].e) {
        mx=j;
      }
    }
    if(i!=mx) { 
      out[i]++;
      child[mx].push_back(i);
    }
  }
  for(int i = 0;i<n;i++) {
    if(out[i]==0){
      bl.add(i,i);
      dfs(i);
    }
  }
  while(q--) {
   int s, e;
   cin >> s >> e;
   swap(s,e);
   if(es[s-1].s>es[e-1].s){
     cout << "impossible" << "\n";
     continue;
   }
   if(s==e) {
     cout << 0 << "\n";
     continue;
   }
   int res=bl.get(s-1,es[e-1].s);
   if(res>=0)cout << res << "\n";
   else cout << "impossible\n";
  }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Execution timed out 1586 ms 24356 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 4 ms 3028 KB Output is correct
4 Correct 4 ms 2900 KB Output is correct
5 Correct 4 ms 3028 KB Output is correct
6 Correct 5 ms 2900 KB Output is correct
7 Correct 5 ms 3028 KB Output is correct
8 Correct 4 ms 3028 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 4 ms 3028 KB Output is correct
4 Correct 4 ms 2900 KB Output is correct
5 Correct 4 ms 3028 KB Output is correct
6 Correct 5 ms 2900 KB Output is correct
7 Correct 5 ms 3028 KB Output is correct
8 Correct 4 ms 3028 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 4 ms 3028 KB Output is correct
13 Correct 4 ms 2900 KB Output is correct
14 Correct 4 ms 3028 KB Output is correct
15 Correct 6 ms 2900 KB Output is correct
16 Correct 5 ms 3028 KB Output is correct
17 Correct 5 ms 3028 KB Output is correct
18 Correct 3 ms 2900 KB Output is correct
19 Correct 132 ms 5452 KB Output is correct
20 Correct 98 ms 5956 KB Output is correct
21 Correct 102 ms 6076 KB Output is correct
22 Correct 103 ms 5844 KB Output is correct
23 Correct 96 ms 6044 KB Output is correct
24 Correct 92 ms 6008 KB Output is correct
25 Correct 103 ms 5800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 4 ms 3028 KB Output is correct
4 Correct 4 ms 2900 KB Output is correct
5 Correct 4 ms 3028 KB Output is correct
6 Correct 5 ms 2900 KB Output is correct
7 Correct 5 ms 3028 KB Output is correct
8 Correct 4 ms 3028 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 4 ms 3028 KB Output is correct
13 Correct 4 ms 2900 KB Output is correct
14 Correct 5 ms 2976 KB Output is correct
15 Correct 6 ms 2900 KB Output is correct
16 Correct 5 ms 3028 KB Output is correct
17 Correct 5 ms 3032 KB Output is correct
18 Correct 3 ms 2900 KB Output is correct
19 Execution timed out 1578 ms 24616 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1573 ms 24484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Execution timed out 1586 ms 24356 KB Time limit exceeded
3 Halted 0 ms 0 KB -