답안 #653628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653628 2022-10-27T13:02:45 Z cadmiumsky Event Hopping (BOI22_events) C++14
10 / 100
469 ms 29048 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()
#define l first
#define r second
#define boo bool

using namespace std;
using pii = pair<int,int>;
using tii = tuple<int,int,int>;

int n, q;

vector<pii> highway;
vector<pii> segm;
vector<int> rez;
vector<pii> bruteqs;

const int nmax = 2e5 + 5;

int occ[nmax];
boo intersect(pii a, pii b) {
  return !(a.r < b.l || b.r < a.l);
}
boo intersecc(pii a, pii b) {
  return a.l <= b.r && b.r <= a.r;
}
 
#define ends adsjkhajksdhjkakjcss
vector<tii> qs[nmax];
vector<int> ends[nmax];

int main() {
  cin >> n >> q;
  
  segm.resize(n);
  vector<int> ind(n);
  iota(all(ind), 0);
  map<int,int> nrm;
  for(auto &[a, b] : segm) cin >> a >> b, nrm[a], nrm[b];
  int cnt = 1; for(auto &[a, b] : nrm) b = cnt++;
  for(auto &[a, b] : segm) tie(a, b) = pii{nrm[a], nrm[b]}, ends[b].push_back(a);
  
  bruteqs.resize(q);
  for(auto &[a, b] : bruteqs) {
    cin >> a >> b;
    --a;
    --b;
    if(segm[a].r > segm[b].r)
      rez.push_back(0);
    else if(segm[a] == segm[b])
      rez.push_back(-1);
    else if(intersect(segm[a], segm[b]))
      rez.push_back(1);
    else {
      rez.push_back(0);   
      qs[segm[b].r].emplace_back(segm[a].r, segm[b].l, rez.size() - 1);
    }
  }
  
  vector<pii> st;
  vector<int> sum;
  st.emplace_back(-1, -1);
  sum.emplace_back(0);
  
  for(int i = 1; i < cnt; i++) {
    int mn = i;
    for(auto x : ends[i]) mn = min(x, mn);
    //cerr << '\n';
    //cerr << mn << '\n';
    //cerr << '\n';
    while(!st.empty() && (mn <= st.back().l || (st.size() >= 2 && st.rbegin()[1].r >= mn)))
      sum.pop_back(),
      st.pop_back();
    if(mn > st.back().r)
      sum.emplace_back(sum.back() + 1);
    else
      sum.emplace_back(sum.back());
    st.emplace_back(mn, i);
    for(auto [a, b, id] : qs[i]) {
      int lim = 0;
      for(int i = 16; i >= 0; i--) {
	if(lim + (1 << i) >= st.size()) continue;
	if(st[lim + (1 << i)].l <= a)
	  lim += (1 << i);
      }
      if(sum.back() - sum[lim]) {
	//for(auto [a, b] : st) cerr << a << ' ' << b << '\n';
	//cerr << a << ' ' << b << ' ' << id << '\n';
	//cerr << sum.back() << ' ' << sum[lim] << '\n' << lim << '\n';
	rez[id] = 0;
      }
      else {
	rez[id] = st.size() - lim + (b > st.rbegin()[1].r);
      }
    }
  }
  
  for(auto x : rez) {
    if(x == 0) cout << "impossible\n";
    else if(x == -1) cout << "0\n";
    else cout << x << '\n';
  }
}


Compilation message

events.cpp: In function 'int main()':
events.cpp:40:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |   for(auto &[a, b] : segm) cin >> a >> b, nrm[a], nrm[b];
      |             ^
events.cpp:41:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |   int cnt = 1; for(auto &[a, b] : nrm) b = cnt++;
      |                          ^
events.cpp:42:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |   for(auto &[a, b] : segm) tie(a, b) = pii{nrm[a], nrm[b]}, ends[b].push_back(a);
      |             ^
events.cpp:45:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |   for(auto &[a, b] : bruteqs) {
      |             ^
events.cpp:80:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   80 |     for(auto [a, b, id] : qs[i]) {
      |              ^
events.cpp:83:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |  if(lim + (1 << i) >= st.size()) continue;
      |     ~~~~~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 299 ms 23704 KB Output is correct
3 Correct 311 ms 23628 KB Output is correct
4 Correct 292 ms 23632 KB Output is correct
5 Correct 271 ms 24140 KB Output is correct
6 Correct 276 ms 24380 KB Output is correct
7 Correct 265 ms 24724 KB Output is correct
8 Correct 340 ms 29048 KB Output is correct
9 Correct 301 ms 28864 KB Output is correct
10 Correct 280 ms 23584 KB Output is correct
11 Correct 330 ms 25176 KB Output is correct
12 Correct 173 ms 21728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 7 ms 9812 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 5 ms 9812 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Incorrect 6 ms 9812 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 7 ms 9812 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 5 ms 9812 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Incorrect 6 ms 9812 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 7 ms 9812 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 5 ms 9812 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Incorrect 6 ms 9812 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 278 ms 23768 KB Output is correct
2 Correct 313 ms 23684 KB Output is correct
3 Correct 300 ms 23540 KB Output is correct
4 Correct 320 ms 28892 KB Output is correct
5 Correct 343 ms 23568 KB Output is correct
6 Incorrect 469 ms 26464 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 299 ms 23704 KB Output is correct
3 Correct 311 ms 23628 KB Output is correct
4 Correct 292 ms 23632 KB Output is correct
5 Correct 271 ms 24140 KB Output is correct
6 Correct 276 ms 24380 KB Output is correct
7 Correct 265 ms 24724 KB Output is correct
8 Correct 340 ms 29048 KB Output is correct
9 Correct 301 ms 28864 KB Output is correct
10 Correct 280 ms 23584 KB Output is correct
11 Correct 330 ms 25176 KB Output is correct
12 Correct 173 ms 21728 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 7 ms 9812 KB Output is correct
16 Correct 7 ms 9812 KB Output is correct
17 Correct 5 ms 9812 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Incorrect 6 ms 9812 KB Output isn't correct
20 Halted 0 ms 0 KB -