답안 #849504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849504 2023-09-14T18:57:19 Z vjudge1 Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 12008 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 7;
const int N = 1e5 + 15;
const ll inf = 1e18;
int n,q;
int dis[N];
struct segtree{
	static const int off = (1<<17);
	int t[off*2];
	int unit;
	void init(){
		memset(t, 0x3f, sizeof(t));
		unit = t[0];
	}
	void update(int i,int u){
		i+=off;
		if (u >= t[i]) return;
		t[i] = u;
		while (i/=2){
			t[i] = min(t[i*2],t[i*2+1]);
		}
	}
	int get(int l, int r, int idx=1, int lo=0, int hi=off){
		if (lo>=r||hi<=l) return unit;
		if (lo>=l&&hi<=r) return t[idx];
		int mi = (lo+hi)/2;
		return min(get(l,r,idx*2,lo,mi),get(l,r,idx*2+1,mi,hi));
	}
} seg;
vector<array<int, 3>> a;
bool cmp(array<int, 3> A, array<int, 3> B){
	if (A[1]!=B[1]) return A[1] < B[1];
	return A[0] < B[0];
}
pii b[N];
int solve(int root, int to){
	dis[root] = 0;
	seg.update(b[root].S, 0);
	for (int i=0;i<n;i++){
		if (a[i][2]==root) continue;
		int u = 1+seg.get(a[i][0], a[i][1]+1);
		dis[a[i][2]] = u;
		seg.update(a[i][1], u);
	}
	return dis[to];
}

int32_t main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> q;
	a.resize(n);
	map<int,int> mp;
	for (int i=0;i<n;i++){
		int s, e; cin >> s >> e;
		mp[s]; mp[e];
		b[i] = {s, e};
	}
	int cnt = 0;
	for (auto &it : mp) {
		it.S = cnt++;
	}
	for (int i=0;i<n;i++){
		b[i] = {mp[b[i].F], mp[b[i].S]};
		a[i] = {b[i].F, b[i].S, i};
	}
	sort(all(a),cmp);
	while (q--){
		int s, e;
		cin >> s >> e;
		s--;e--;
		memset(dis, 0x3f, sizeof(dis));
		seg.init();
		int ans = solve(s, e);
		if (ans>n) cout << "impossible\n";
		else cout << ans << endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Execution timed out 1585 ms 9772 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2084 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 16 ms 1884 KB Output is correct
4 Correct 13 ms 1972 KB Output is correct
5 Correct 14 ms 1884 KB Output is correct
6 Correct 12 ms 1940 KB Output is correct
7 Correct 20 ms 1884 KB Output is correct
8 Correct 18 ms 1884 KB Output is correct
9 Correct 8 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2084 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 16 ms 1884 KB Output is correct
4 Correct 13 ms 1972 KB Output is correct
5 Correct 14 ms 1884 KB Output is correct
6 Correct 12 ms 1940 KB Output is correct
7 Correct 20 ms 1884 KB Output is correct
8 Correct 18 ms 1884 KB Output is correct
9 Correct 8 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 16 ms 1884 KB Output is correct
13 Correct 14 ms 1972 KB Output is correct
14 Correct 14 ms 1884 KB Output is correct
15 Correct 12 ms 1884 KB Output is correct
16 Correct 21 ms 2012 KB Output is correct
17 Correct 20 ms 1880 KB Output is correct
18 Correct 8 ms 1884 KB Output is correct
19 Execution timed out 1583 ms 2516 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2084 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 16 ms 1884 KB Output is correct
4 Correct 13 ms 1972 KB Output is correct
5 Correct 14 ms 1884 KB Output is correct
6 Correct 12 ms 1940 KB Output is correct
7 Correct 20 ms 1884 KB Output is correct
8 Correct 18 ms 1884 KB Output is correct
9 Correct 8 ms 1884 KB Output is correct
10 Correct 1 ms 1624 KB Output is correct
11 Correct 1 ms 1624 KB Output is correct
12 Correct 17 ms 1884 KB Output is correct
13 Correct 13 ms 1884 KB Output is correct
14 Correct 16 ms 1884 KB Output is correct
15 Correct 12 ms 2216 KB Output is correct
16 Correct 20 ms 2136 KB Output is correct
17 Correct 18 ms 1884 KB Output is correct
18 Correct 9 ms 1880 KB Output is correct
19 Correct 1398 ms 9672 KB Output is correct
20 Correct 1178 ms 9496 KB Output is correct
21 Correct 1262 ms 10248 KB Output is correct
22 Incorrect 1065 ms 12008 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1516 ms 9764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Execution timed out 1585 ms 9772 KB Time limit exceeded
3 Halted 0 ms 0 KB -