답안 #1111613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111613 2024-11-12T10:00:08 Z hmm789 Fire (BOI24_fire) C++14
100 / 100
923 ms 228132 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 

struct node {
	int s, e, m, v, lz;
	node *l, *r;
	node(int _s, int _e) {
		s = _s, e = _e, m = (s+e)/2, v = 0, lz = -1;
		if(s != e) {
			l = new node(s, m);
			r = new node(m+1, e);
		}
	}
	void prop() {
		if(lz == -1) return;
		v = lz;
		if(s != e) {
			l->lz = lz;
			r->lz = lz;
		}
		lz = -1;
	}
	void update(int x, int y, int val) {
		prop();
		if(x <= s && e <= y) {lz = val; return;}
		else if(x > m) r->update(x, y, val);
		else if(y <= m) l->update(x, y, val);
		else l->update(x, y, val), r->update(x, y, val);
		l->prop(); r->prop();
		v = max(l->v, r->v);
	}
	int get(int x) {
		prop();
		if(s == e) return v;
		else if(x > m) return r->get(x);
		else return l->get(x);
	}
} *root, *root2;

vector<int> adj[800000];
int p[800000][20], depth[800000];
bool v[800000];

void dfs(int x, int pa, int d) {
	v[x] = 1;
	depth[x] = d;
	p[x][0] = pa;
	for(int i = 1; i < 20; i++) {
		if(p[x][i-1] == -1) break;
		p[x][i] = p[p[x][i-1]][i-1];
	}
	for(int i : adj[x]) if(!v[i]) dfs(i, x, d+1);
}

int getp(int x, int k) {
	for(int i = 0; i < 20; i++) {
		if(k&(1<<i)) x = p[x][i];
	}
	return x;
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, x, y;
	cin >> n >> m;
	pair<int, int> a[n];
	vector<int> dis, dis2, act;
	for(int i = 0; i < n; i++) {
		cin >> x >> y;
		if(y < x) y = y+m;
		a[i] = {y, x};
		dis.push_back(x);
		dis.push_back(y);
	}
	sort(dis.begin(), dis.end());
	dis.erase(unique(dis.begin(), dis.end()), dis.end());
	for(int i : dis) act.push_back(i);
	root = new node(0, dis.size());
	
	for(int i = 0; i < n; i++) {
		a[i].first = lower_bound(dis.begin(), dis.end(), a[i].first)-dis.begin();
		a[i].second = lower_bound(dis.begin(), dis.end(), a[i].second)-dis.begin();
	}
	
	sort(a, a+n);
	for(int i = 0; i < n; i++) {
		root->update(a[i].second, a[i].first, a[i].first);
	}
	int par[dis.size()];
	for(int i = 0; i < dis.size(); i++) {
		if(root->get(i) != i) adj[root->get(i)].push_back(i);
		par[i] = root->get(i);
	}
	memset(p, -1, sizeof(p));
	for(int i = dis.size()-1; i >= 0; i--) if(!v[i]) {
		dfs(i, -1, 0);
	}
	int l = 0, r = n+1, md;
	while(l < r) {
		md = (l+r)/2;
		bool ok = false;
		for(int i = 0; i < dis.size()-1; i++) {
			if(act[getp(i, min(md, depth[i]))]-act[i] >= m) ok = true;
		}
		if(ok) r = md;
		else l = md+1;
	}
	if(l == n+1) cout << -1 << '\n';
	else cout << l << '\n';
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:92:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |  for(int i = 0; i < dis.size(); i++) {
      |                 ~~^~~~~~~~~~~~
Main.cpp:104:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |   for(int i = 0; i < dis.size()-1; i++) {
      |                  ~~^~~~~~~~~~~~~~
Main.cpp:91:6: warning: variable 'par' set but not used [-Wunused-but-set-variable]
   91 |  int par[dis.size()];
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 147024 KB Output is correct
2 Correct 20 ms 147024 KB Output is correct
3 Correct 22 ms 147024 KB Output is correct
4 Correct 25 ms 147024 KB Output is correct
5 Correct 23 ms 147024 KB Output is correct
6 Correct 21 ms 147024 KB Output is correct
7 Correct 26 ms 147280 KB Output is correct
8 Correct 23 ms 147244 KB Output is correct
9 Correct 21 ms 147024 KB Output is correct
10 Correct 22 ms 147280 KB Output is correct
11 Correct 21 ms 147040 KB Output is correct
12 Correct 22 ms 147260 KB Output is correct
13 Correct 20 ms 145104 KB Output is correct
14 Correct 23 ms 147024 KB Output is correct
15 Correct 30 ms 144976 KB Output is correct
16 Correct 40 ms 145124 KB Output is correct
17 Correct 30 ms 145232 KB Output is correct
18 Correct 30 ms 145224 KB Output is correct
19 Correct 21 ms 147024 KB Output is correct
20 Correct 23 ms 147024 KB Output is correct
21 Correct 30 ms 147016 KB Output is correct
22 Correct 34 ms 144976 KB Output is correct
23 Correct 28 ms 145232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 147024 KB Output is correct
2 Correct 20 ms 147024 KB Output is correct
3 Correct 22 ms 147024 KB Output is correct
4 Correct 25 ms 147024 KB Output is correct
5 Correct 23 ms 147024 KB Output is correct
6 Correct 21 ms 147024 KB Output is correct
7 Correct 26 ms 147280 KB Output is correct
8 Correct 23 ms 147244 KB Output is correct
9 Correct 21 ms 147024 KB Output is correct
10 Correct 22 ms 147280 KB Output is correct
11 Correct 21 ms 147040 KB Output is correct
12 Correct 22 ms 147260 KB Output is correct
13 Correct 20 ms 145104 KB Output is correct
14 Correct 23 ms 147024 KB Output is correct
15 Correct 30 ms 144976 KB Output is correct
16 Correct 40 ms 145124 KB Output is correct
17 Correct 30 ms 145232 KB Output is correct
18 Correct 30 ms 145224 KB Output is correct
19 Correct 21 ms 147024 KB Output is correct
20 Correct 23 ms 147024 KB Output is correct
21 Correct 30 ms 147016 KB Output is correct
22 Correct 34 ms 144976 KB Output is correct
23 Correct 28 ms 145232 KB Output is correct
24 Correct 29 ms 145400 KB Output is correct
25 Correct 40 ms 145216 KB Output is correct
26 Correct 35 ms 145232 KB Output is correct
27 Correct 40 ms 145272 KB Output is correct
28 Correct 33 ms 145228 KB Output is correct
29 Correct 42 ms 145224 KB Output is correct
30 Correct 42 ms 145232 KB Output is correct
31 Correct 41 ms 145224 KB Output is correct
32 Correct 49 ms 145164 KB Output is correct
33 Correct 42 ms 145232 KB Output is correct
34 Correct 41 ms 145160 KB Output is correct
35 Correct 47 ms 145224 KB Output is correct
36 Correct 48 ms 145240 KB Output is correct
37 Correct 54 ms 145228 KB Output is correct
38 Correct 47 ms 145224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 147024 KB Output is correct
2 Correct 20 ms 147024 KB Output is correct
3 Correct 22 ms 147024 KB Output is correct
4 Correct 25 ms 147024 KB Output is correct
5 Correct 23 ms 147024 KB Output is correct
6 Correct 21 ms 147024 KB Output is correct
7 Correct 26 ms 147280 KB Output is correct
8 Correct 23 ms 147244 KB Output is correct
9 Correct 21 ms 147024 KB Output is correct
10 Correct 22 ms 147280 KB Output is correct
11 Correct 21 ms 147040 KB Output is correct
12 Correct 22 ms 147260 KB Output is correct
13 Correct 20 ms 145104 KB Output is correct
14 Correct 23 ms 147024 KB Output is correct
15 Correct 30 ms 144976 KB Output is correct
16 Correct 40 ms 145124 KB Output is correct
17 Correct 30 ms 145232 KB Output is correct
18 Correct 30 ms 145224 KB Output is correct
19 Correct 21 ms 147024 KB Output is correct
20 Correct 23 ms 147024 KB Output is correct
21 Correct 30 ms 147016 KB Output is correct
22 Correct 34 ms 144976 KB Output is correct
23 Correct 28 ms 145232 KB Output is correct
24 Correct 29 ms 145400 KB Output is correct
25 Correct 40 ms 145216 KB Output is correct
26 Correct 35 ms 145232 KB Output is correct
27 Correct 40 ms 145272 KB Output is correct
28 Correct 33 ms 145228 KB Output is correct
29 Correct 42 ms 145224 KB Output is correct
30 Correct 42 ms 145232 KB Output is correct
31 Correct 41 ms 145224 KB Output is correct
32 Correct 49 ms 145164 KB Output is correct
33 Correct 42 ms 145232 KB Output is correct
34 Correct 41 ms 145160 KB Output is correct
35 Correct 47 ms 145224 KB Output is correct
36 Correct 48 ms 145240 KB Output is correct
37 Correct 54 ms 145228 KB Output is correct
38 Correct 47 ms 145224 KB Output is correct
39 Correct 51 ms 146928 KB Output is correct
40 Correct 52 ms 147016 KB Output is correct
41 Correct 53 ms 146812 KB Output is correct
42 Correct 46 ms 146504 KB Output is correct
43 Correct 43 ms 146000 KB Output is correct
44 Correct 46 ms 146504 KB Output is correct
45 Correct 47 ms 146360 KB Output is correct
46 Correct 53 ms 146340 KB Output is correct
47 Correct 57 ms 146760 KB Output is correct
48 Correct 52 ms 146900 KB Output is correct
49 Correct 57 ms 147020 KB Output is correct
50 Correct 44 ms 146248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 145136 KB Output is correct
2 Correct 41 ms 145080 KB Output is correct
3 Correct 40 ms 145232 KB Output is correct
4 Correct 39 ms 144980 KB Output is correct
5 Correct 39 ms 144976 KB Output is correct
6 Correct 41 ms 145304 KB Output is correct
7 Correct 40 ms 145232 KB Output is correct
8 Correct 37 ms 144968 KB Output is correct
9 Correct 42 ms 145224 KB Output is correct
10 Correct 46 ms 145224 KB Output is correct
11 Correct 41 ms 145224 KB Output is correct
12 Correct 40 ms 145224 KB Output is correct
13 Correct 45 ms 145232 KB Output is correct
14 Correct 41 ms 145224 KB Output is correct
15 Correct 47 ms 147040 KB Output is correct
16 Correct 51 ms 146504 KB Output is correct
17 Correct 46 ms 145848 KB Output is correct
18 Correct 48 ms 146320 KB Output is correct
19 Correct 51 ms 146760 KB Output is correct
20 Correct 76 ms 152504 KB Output is correct
21 Correct 712 ms 217992 KB Output is correct
22 Correct 710 ms 217908 KB Output is correct
23 Correct 511 ms 197816 KB Output is correct
24 Correct 861 ms 223808 KB Output is correct
25 Correct 345 ms 179724 KB Output is correct
26 Correct 513 ms 189116 KB Output is correct
27 Correct 546 ms 199812 KB Output is correct
28 Correct 657 ms 216888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 147264 KB Output is correct
2 Correct 22 ms 147256 KB Output is correct
3 Correct 23 ms 145232 KB Output is correct
4 Correct 30 ms 145132 KB Output is correct
5 Correct 25 ms 145232 KB Output is correct
6 Correct 32 ms 145232 KB Output is correct
7 Correct 29 ms 145284 KB Output is correct
8 Correct 27 ms 145232 KB Output is correct
9 Correct 35 ms 145176 KB Output is correct
10 Correct 35 ms 145224 KB Output is correct
11 Correct 31 ms 145224 KB Output is correct
12 Correct 39 ms 147024 KB Output is correct
13 Correct 37 ms 146524 KB Output is correct
14 Correct 36 ms 146256 KB Output is correct
15 Correct 82 ms 152332 KB Output is correct
16 Correct 559 ms 198000 KB Output is correct
17 Correct 777 ms 220724 KB Output is correct
18 Correct 675 ms 220968 KB Output is correct
19 Correct 923 ms 226696 KB Output is correct
20 Correct 423 ms 191820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 147024 KB Output is correct
2 Correct 20 ms 147024 KB Output is correct
3 Correct 22 ms 147024 KB Output is correct
4 Correct 25 ms 147024 KB Output is correct
5 Correct 23 ms 147024 KB Output is correct
6 Correct 21 ms 147024 KB Output is correct
7 Correct 26 ms 147280 KB Output is correct
8 Correct 23 ms 147244 KB Output is correct
9 Correct 21 ms 147024 KB Output is correct
10 Correct 22 ms 147280 KB Output is correct
11 Correct 21 ms 147040 KB Output is correct
12 Correct 22 ms 147260 KB Output is correct
13 Correct 20 ms 145104 KB Output is correct
14 Correct 23 ms 147024 KB Output is correct
15 Correct 30 ms 144976 KB Output is correct
16 Correct 40 ms 145124 KB Output is correct
17 Correct 30 ms 145232 KB Output is correct
18 Correct 30 ms 145224 KB Output is correct
19 Correct 21 ms 147024 KB Output is correct
20 Correct 23 ms 147024 KB Output is correct
21 Correct 30 ms 147016 KB Output is correct
22 Correct 34 ms 144976 KB Output is correct
23 Correct 28 ms 145232 KB Output is correct
24 Correct 29 ms 145400 KB Output is correct
25 Correct 40 ms 145216 KB Output is correct
26 Correct 35 ms 145232 KB Output is correct
27 Correct 40 ms 145272 KB Output is correct
28 Correct 33 ms 145228 KB Output is correct
29 Correct 42 ms 145224 KB Output is correct
30 Correct 42 ms 145232 KB Output is correct
31 Correct 41 ms 145224 KB Output is correct
32 Correct 49 ms 145164 KB Output is correct
33 Correct 42 ms 145232 KB Output is correct
34 Correct 41 ms 145160 KB Output is correct
35 Correct 47 ms 145224 KB Output is correct
36 Correct 48 ms 145240 KB Output is correct
37 Correct 54 ms 145228 KB Output is correct
38 Correct 47 ms 145224 KB Output is correct
39 Correct 51 ms 146928 KB Output is correct
40 Correct 52 ms 147016 KB Output is correct
41 Correct 53 ms 146812 KB Output is correct
42 Correct 46 ms 146504 KB Output is correct
43 Correct 43 ms 146000 KB Output is correct
44 Correct 46 ms 146504 KB Output is correct
45 Correct 47 ms 146360 KB Output is correct
46 Correct 53 ms 146340 KB Output is correct
47 Correct 57 ms 146760 KB Output is correct
48 Correct 52 ms 146900 KB Output is correct
49 Correct 57 ms 147020 KB Output is correct
50 Correct 44 ms 146248 KB Output is correct
51 Correct 39 ms 145136 KB Output is correct
52 Correct 41 ms 145080 KB Output is correct
53 Correct 40 ms 145232 KB Output is correct
54 Correct 39 ms 144980 KB Output is correct
55 Correct 39 ms 144976 KB Output is correct
56 Correct 41 ms 145304 KB Output is correct
57 Correct 40 ms 145232 KB Output is correct
58 Correct 37 ms 144968 KB Output is correct
59 Correct 42 ms 145224 KB Output is correct
60 Correct 46 ms 145224 KB Output is correct
61 Correct 41 ms 145224 KB Output is correct
62 Correct 40 ms 145224 KB Output is correct
63 Correct 45 ms 145232 KB Output is correct
64 Correct 41 ms 145224 KB Output is correct
65 Correct 47 ms 147040 KB Output is correct
66 Correct 51 ms 146504 KB Output is correct
67 Correct 46 ms 145848 KB Output is correct
68 Correct 48 ms 146320 KB Output is correct
69 Correct 51 ms 146760 KB Output is correct
70 Correct 76 ms 152504 KB Output is correct
71 Correct 712 ms 217992 KB Output is correct
72 Correct 710 ms 217908 KB Output is correct
73 Correct 511 ms 197816 KB Output is correct
74 Correct 861 ms 223808 KB Output is correct
75 Correct 345 ms 179724 KB Output is correct
76 Correct 513 ms 189116 KB Output is correct
77 Correct 546 ms 199812 KB Output is correct
78 Correct 657 ms 216888 KB Output is correct
79 Correct 21 ms 147264 KB Output is correct
80 Correct 22 ms 147256 KB Output is correct
81 Correct 23 ms 145232 KB Output is correct
82 Correct 30 ms 145132 KB Output is correct
83 Correct 25 ms 145232 KB Output is correct
84 Correct 32 ms 145232 KB Output is correct
85 Correct 29 ms 145284 KB Output is correct
86 Correct 27 ms 145232 KB Output is correct
87 Correct 35 ms 145176 KB Output is correct
88 Correct 35 ms 145224 KB Output is correct
89 Correct 31 ms 145224 KB Output is correct
90 Correct 39 ms 147024 KB Output is correct
91 Correct 37 ms 146524 KB Output is correct
92 Correct 36 ms 146256 KB Output is correct
93 Correct 82 ms 152332 KB Output is correct
94 Correct 559 ms 198000 KB Output is correct
95 Correct 777 ms 220724 KB Output is correct
96 Correct 675 ms 220968 KB Output is correct
97 Correct 923 ms 226696 KB Output is correct
98 Correct 423 ms 191820 KB Output is correct
99 Correct 586 ms 218940 KB Output is correct
100 Correct 677 ms 218164 KB Output is correct
101 Correct 843 ms 228132 KB Output is correct
102 Correct 824 ms 227672 KB Output is correct
103 Correct 528 ms 202168 KB Output is correct
104 Correct 610 ms 218696 KB Output is correct
105 Correct 872 ms 223036 KB Output is correct