답안 #580254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580254 2022-06-20T20:36:58 Z penguinhacker Event Hopping (BOI22_events) C++17
25 / 100
1500 ms 6544 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
const int mxN=1e5;
int n, q, ls[mxN], rs[mxN], ans[mxN];
ar<int, 2> segs[mxN];
vector<int> d;
vector<ar<int, 3>> qry[mxN];
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q;
	for (int i=0; i<n; ++i) {
		cin >> segs[i][0] >> segs[i][1];
		d.push_back(segs[i][1]);
	}
	sort(d.begin(), d.end());
	d.resize(unique(d.begin(), d.end())-d.begin());
	memset(ls, -1, sizeof(ls));
	for (int i=0; i<n; ++i) {
		segs[i][0]=lower_bound(d.begin(), d.end(), segs[i][0])-d.begin();
		segs[i][1]=lower_bound(d.begin(), d.end(), segs[i][1])-d.begin();
		//cout << "seg  " <<  segs[i][0] << " " << segs[i][1] << endl;
		if (ls[segs[i][1]]==-1||segs[i][0]<ls[segs[i][1]])
			ls[segs[i][1]]=segs[i][0];
	}
	for (int i=0; i<q; ++i) {
		int a, b;
		cin >> a >> b, --a, --b;
		ans[i]=-1;
		if (segs[a][1]<segs[b][1])
			qry[segs[b][1]].push_back({segs[a][1], segs[b][0], i});
		if (segs[a][1]==segs[b][1])
			ans[i]=a!=b;
	}
	iota(rs, rs+d.size(), 0);
	for (int i=0; i<d.size(); ++i) {
		if (ls[i]!=-1)
			for (int j=ls[i]; j<=i; ++j)
				rs[j]=i;
		//for (int j=0; j<=i; ++j)
		//	cout << rs[j] << " ";
		//cout << endl;
		for (auto [s, bound, ind] : qry[i]) {
			int cur=0;
			while(rs[s]<i&&rs[s]!=s)
				++cur, s=rs[s];
			if (rs[s]!=i)
				continue;
			++cur;
			cur+=s<bound;
			ans[ind]=cur;
		}
	}
	for (int i=0; i<q; ++i) {
		if (ans[i]==-1)
			cout << "impossible\n";
		else
			cout << ans[i] << "\n";
	}
	return 0;
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i=0; i<d.size(); ++i) {
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Execution timed out 1573 ms 6544 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 4 ms 3028 KB Output is correct
7 Correct 3 ms 3028 KB Output is correct
8 Correct 3 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 4 ms 3028 KB Output is correct
7 Correct 3 ms 3028 KB Output is correct
8 Correct 3 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 2 ms 3028 KB Output is correct
12 Correct 3 ms 3028 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
14 Correct 3 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 406 ms 5588 KB Output is correct
20 Correct 1104 ms 5592 KB Output is correct
21 Correct 210 ms 5276 KB Output is correct
22 Correct 37 ms 5260 KB Output is correct
23 Correct 33 ms 5136 KB Output is correct
24 Correct 42 ms 5200 KB Output is correct
25 Correct 51 ms 5508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 4 ms 3028 KB Output is correct
7 Correct 3 ms 3028 KB Output is correct
8 Correct 3 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3152 KB Output is correct
11 Correct 2 ms 3028 KB Output is correct
12 Correct 3 ms 3028 KB Output is correct
13 Correct 4 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 82 ms 6156 KB Output is correct
20 Correct 55 ms 4828 KB Output is correct
21 Correct 206 ms 4488 KB Output is correct
22 Correct 53 ms 4684 KB Output is correct
23 Execution timed out 1583 ms 5132 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1591 ms 6484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Execution timed out 1573 ms 6544 KB Time limit exceeded
3 Halted 0 ms 0 KB -