Submission #849363

# Submission time Handle Problem Language Result Execution time Memory
849363 2023-09-14T14:20:13 Z vjudge1 Event Hopping (BOI22_events) C++17
0 / 100
48 ms 3760 KB
#include <bits/stdc++.h>
#define all(v) ((v).begin(),(v).end())
#define ll long long
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll mxN = 1e5 + 2;
using namespace std;
struct range{
  int l,r,id;
};
bool operator<(range a,range b){
  return a.r < b.r;
}
bool operator==(range a,range b){
  return tie(a.l,a.r,a.id) == tie(b.l,b.r,b.id);
}
range a[mxN];
range og[mxN];
int reach[mxN];
signed main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0  );
  int n,q;
  cin >>n>>q;
  for(int i = 0;i < n;i++){
    cin >>a[i].l>>a[i].r;
    a[i].id = 0;
    og[i] = a[i];
  }
  sort(a,a + n);
  int val = n - 1;
  reach[n - 1] = val;
  for(int i = n - 2;i >= 0;i--){
    if(a[i].l >= a[i + 1].r) reach[i] = val;
    else{
      val = i;
      reach[i] = val;
    }
  }
  while(q--){
    int s,e;
    cin >>s>>e;
    auto x = og[s - 1],y = og[e - 1];
    int ans = 0;
    int i = lower_bound(a,a + n,x) - a;
    int j = lower_bound(a,a + n,y) - a;
    if(j - i < 0 && reach[i] >= j) cout<<"impossible\n";
    else cout<<j - i<<'\n';
    continue;
    if(i > j) ans = -1;
    while(i < j){
      int nxt = -1;
      int lt = -1;
      i++;
      while(i <= j){
        if(a[i].l <= x.r && a[i].r >= x.r && a[i].r <= y.r){
          if(nxt == -1 || a[i].r >= a[nxt].r){
            nxt = i;
          }
          lt = i;
        }
        i++;
      }
      if(nxt == -1){
        ans = -1;
        break;
      }
      x = a[nxt];
      i = lt;
      ans++;
    }
    if(ans != -1) cout<<ans<<'\n';
    else cout<<"impossible\n";
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 3664 KB Output is correct
2 Correct 48 ms 3760 KB Output is correct
3 Correct 47 ms 3664 KB Output is correct
4 Incorrect 48 ms 3668 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -