Submission #950585

# Submission time Handle Problem Language Result Execution time Memory
950585 2024-03-20T12:56:30 Z esomer Towers (NOI22_towers) C++17
100 / 100
897 ms 191272 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int maxX = 1e6;
 
vector<int> cols[maxX + 1], rows[maxX + 1];
vector<bool> chosen[maxX + 1];
pair<int, int> indRow[maxX + 1], indCol[maxX + 1];
queue<pair<int, int>> q;
 
bool choose(int X, int Y){
	int lo = 0;
	int hi = (int)cols[X].size() - 1;
	int bst = -1;
	while(lo <= hi){
		int mid = (lo + hi) / 2;
		if(cols[X][mid] >= Y){
			bst = mid;
			hi = mid - 1;
		}else lo = mid + 1;
	}
	if(chosen[X][bst]) return true;
	// cout << "Chose " << X << " " << cols[X][bst] << " bst " << bst << " indCol " << indCol[X].first << " " << indCol[X].second << "\n";
	chosen[X][bst] = true;
	if(indCol[X].first == -1){
		indCol[X] = {bst, bst};
	}else if(indCol[X].first == indCol[X].second){
		indCol[X] = {min(bst, indCol[X].first), max(bst, indCol[X].second)};
	}else if(indCol[X].first > bst){
		// cout << "Add " << X << " " << indCol[X].first << "\n";
		q.push({X, indCol[X].first});
		indCol[X].first = bst;
	}else if(indCol[X].second < bst){
		q.push({X, indCol[X].second});
		// cout << "Add " << X << " " << indCol[X].second << "\n";
		indCol[X].second = bst;
	}else{
		q.push({X, bst});
	}
	// cout << "After indCol " << indCol[X].first << " " << indCol[X].second << "\n";
	return false;
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	int N; cin >> N;
	vector<pair<int, int>> A(N);
	for(int i = 0; i < N; i++){
		int X, Y; cin >> X >> Y;
		A[i] = {X, Y};
		cols[X].push_back(Y);
		rows[Y].push_back(X);
	}
	for(int i = 1; i <= maxX; i++){
		sort(rows[i].begin(), rows[i].end());
		sort(cols[i].begin(), cols[i].end());
		indRow[i] = {0, (int)rows[i].size() - 1};
		indCol[i] = {-1, -1};
		chosen[i].assign((int)cols[i].size(), false);
	}
	for(int i = 1; i <= maxX; i++){
		if((int)rows[i].size() > 0){
			choose(rows[i][0], i);
			choose(rows[i].back(), i);
		}
	}
	while(!q.empty()){
		int X = q.front().first; int i = q.front().second; q.pop();
		// cout << "Erased: " << X << " " << cols[X][i] << "\n";
		chosen[X][i] = false;
		int row = cols[X][i];
		if(rows[row][indRow[row].second] == X){
			indRow[row].second--;
			if(indRow[row].second > indRow[row].first) choose(rows[row][indRow[row].second], row);
		}
		if(rows[row][indRow[row].first] == X){
			indRow[row].first++;
			if(indRow[row].first < indRow[row].second) choose(rows[row][indRow[row].first], row);
		}
	}
	// cout << "-----\n";
	for(int i = 0; i < N; i++){
		if(choose(A[i].first, A[i].second)) cout << 1;
		else cout << 0;
	}
	cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 101944 KB Output is correct
2 Correct 31 ms 101976 KB Output is correct
3 Correct 29 ms 101972 KB Output is correct
4 Correct 30 ms 101968 KB Output is correct
5 Correct 29 ms 102144 KB Output is correct
6 Correct 31 ms 102492 KB Output is correct
7 Correct 28 ms 101984 KB Output is correct
8 Correct 29 ms 101980 KB Output is correct
9 Correct 29 ms 102232 KB Output is correct
10 Correct 29 ms 102220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 101944 KB Output is correct
2 Correct 31 ms 101976 KB Output is correct
3 Correct 29 ms 101972 KB Output is correct
4 Correct 30 ms 101968 KB Output is correct
5 Correct 29 ms 102144 KB Output is correct
6 Correct 31 ms 102492 KB Output is correct
7 Correct 28 ms 101984 KB Output is correct
8 Correct 29 ms 101980 KB Output is correct
9 Correct 29 ms 102232 KB Output is correct
10 Correct 29 ms 102220 KB Output is correct
11 Correct 28 ms 101980 KB Output is correct
12 Correct 29 ms 101976 KB Output is correct
13 Correct 28 ms 101976 KB Output is correct
14 Correct 28 ms 101980 KB Output is correct
15 Correct 29 ms 101972 KB Output is correct
16 Correct 28 ms 101980 KB Output is correct
17 Correct 29 ms 101980 KB Output is correct
18 Correct 33 ms 101972 KB Output is correct
19 Correct 29 ms 101980 KB Output is correct
20 Correct 29 ms 101980 KB Output is correct
21 Correct 28 ms 101976 KB Output is correct
22 Correct 29 ms 101948 KB Output is correct
23 Correct 28 ms 101980 KB Output is correct
24 Correct 29 ms 101980 KB Output is correct
25 Correct 29 ms 101972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 105608 KB Output is correct
2 Correct 57 ms 106064 KB Output is correct
3 Correct 99 ms 113952 KB Output is correct
4 Correct 171 ms 125564 KB Output is correct
5 Correct 51 ms 106580 KB Output is correct
6 Correct 34 ms 103004 KB Output is correct
7 Correct 185 ms 124312 KB Output is correct
8 Correct 113 ms 117788 KB Output is correct
9 Correct 302 ms 136036 KB Output is correct
10 Correct 222 ms 129112 KB Output is correct
11 Correct 249 ms 134876 KB Output is correct
12 Correct 254 ms 134880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 460 ms 177372 KB Output is correct
2 Correct 440 ms 177264 KB Output is correct
3 Correct 442 ms 177488 KB Output is correct
4 Correct 452 ms 177492 KB Output is correct
5 Correct 441 ms 177232 KB Output is correct
6 Correct 888 ms 191244 KB Output is correct
7 Correct 835 ms 191164 KB Output is correct
8 Correct 897 ms 191144 KB Output is correct
9 Correct 867 ms 191060 KB Output is correct
10 Correct 836 ms 191272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 101944 KB Output is correct
2 Correct 31 ms 101976 KB Output is correct
3 Correct 29 ms 101972 KB Output is correct
4 Correct 30 ms 101968 KB Output is correct
5 Correct 29 ms 102144 KB Output is correct
6 Correct 31 ms 102492 KB Output is correct
7 Correct 28 ms 101984 KB Output is correct
8 Correct 29 ms 101980 KB Output is correct
9 Correct 29 ms 102232 KB Output is correct
10 Correct 29 ms 102220 KB Output is correct
11 Correct 28 ms 101980 KB Output is correct
12 Correct 29 ms 101976 KB Output is correct
13 Correct 28 ms 101976 KB Output is correct
14 Correct 28 ms 101980 KB Output is correct
15 Correct 29 ms 101972 KB Output is correct
16 Correct 28 ms 101980 KB Output is correct
17 Correct 29 ms 101980 KB Output is correct
18 Correct 33 ms 101972 KB Output is correct
19 Correct 29 ms 101980 KB Output is correct
20 Correct 29 ms 101980 KB Output is correct
21 Correct 28 ms 101976 KB Output is correct
22 Correct 29 ms 101948 KB Output is correct
23 Correct 28 ms 101980 KB Output is correct
24 Correct 29 ms 101980 KB Output is correct
25 Correct 29 ms 101972 KB Output is correct
26 Correct 35 ms 102736 KB Output is correct
27 Correct 33 ms 102744 KB Output is correct
28 Correct 32 ms 102444 KB Output is correct
29 Correct 34 ms 102224 KB Output is correct
30 Correct 33 ms 102228 KB Output is correct
31 Correct 38 ms 102548 KB Output is correct
32 Correct 32 ms 102428 KB Output is correct
33 Correct 30 ms 102236 KB Output is correct
34 Correct 30 ms 102232 KB Output is correct
35 Correct 31 ms 102404 KB Output is correct
36 Correct 30 ms 102236 KB Output is correct
37 Correct 31 ms 102380 KB Output is correct
38 Correct 30 ms 102224 KB Output is correct
39 Correct 30 ms 102224 KB Output is correct
40 Correct 31 ms 102232 KB Output is correct
41 Correct 30 ms 102236 KB Output is correct
42 Correct 30 ms 102236 KB Output is correct
43 Correct 30 ms 102384 KB Output is correct
44 Correct 31 ms 102380 KB Output is correct
45 Correct 30 ms 102416 KB Output is correct
46 Correct 29 ms 102224 KB Output is correct
47 Correct 30 ms 102236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 101944 KB Output is correct
2 Correct 31 ms 101976 KB Output is correct
3 Correct 29 ms 101972 KB Output is correct
4 Correct 30 ms 101968 KB Output is correct
5 Correct 29 ms 102144 KB Output is correct
6 Correct 31 ms 102492 KB Output is correct
7 Correct 28 ms 101984 KB Output is correct
8 Correct 29 ms 101980 KB Output is correct
9 Correct 29 ms 102232 KB Output is correct
10 Correct 29 ms 102220 KB Output is correct
11 Correct 28 ms 101980 KB Output is correct
12 Correct 29 ms 101976 KB Output is correct
13 Correct 28 ms 101976 KB Output is correct
14 Correct 28 ms 101980 KB Output is correct
15 Correct 29 ms 101972 KB Output is correct
16 Correct 28 ms 101980 KB Output is correct
17 Correct 29 ms 101980 KB Output is correct
18 Correct 33 ms 101972 KB Output is correct
19 Correct 29 ms 101980 KB Output is correct
20 Correct 29 ms 101980 KB Output is correct
21 Correct 28 ms 101976 KB Output is correct
22 Correct 29 ms 101948 KB Output is correct
23 Correct 28 ms 101980 KB Output is correct
24 Correct 29 ms 101980 KB Output is correct
25 Correct 29 ms 101972 KB Output is correct
26 Correct 35 ms 102736 KB Output is correct
27 Correct 33 ms 102744 KB Output is correct
28 Correct 32 ms 102444 KB Output is correct
29 Correct 34 ms 102224 KB Output is correct
30 Correct 33 ms 102228 KB Output is correct
31 Correct 38 ms 102548 KB Output is correct
32 Correct 32 ms 102428 KB Output is correct
33 Correct 30 ms 102236 KB Output is correct
34 Correct 30 ms 102232 KB Output is correct
35 Correct 31 ms 102404 KB Output is correct
36 Correct 30 ms 102236 KB Output is correct
37 Correct 31 ms 102380 KB Output is correct
38 Correct 30 ms 102224 KB Output is correct
39 Correct 30 ms 102224 KB Output is correct
40 Correct 31 ms 102232 KB Output is correct
41 Correct 30 ms 102236 KB Output is correct
42 Correct 30 ms 102236 KB Output is correct
43 Correct 30 ms 102384 KB Output is correct
44 Correct 31 ms 102380 KB Output is correct
45 Correct 30 ms 102416 KB Output is correct
46 Correct 29 ms 102224 KB Output is correct
47 Correct 30 ms 102236 KB Output is correct
48 Correct 121 ms 113400 KB Output is correct
49 Correct 121 ms 113236 KB Output is correct
50 Correct 121 ms 110244 KB Output is correct
51 Correct 123 ms 110316 KB Output is correct
52 Correct 77 ms 106640 KB Output is correct
53 Correct 79 ms 106836 KB Output is correct
54 Correct 73 ms 106836 KB Output is correct
55 Correct 67 ms 106580 KB Output is correct
56 Correct 77 ms 106496 KB Output is correct
57 Correct 67 ms 106544 KB Output is correct
58 Correct 63 ms 106656 KB Output is correct
59 Correct 63 ms 106580 KB Output is correct
60 Correct 63 ms 106580 KB Output is correct
61 Correct 63 ms 106580 KB Output is correct
62 Correct 63 ms 106612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 101944 KB Output is correct
2 Correct 31 ms 101976 KB Output is correct
3 Correct 29 ms 101972 KB Output is correct
4 Correct 30 ms 101968 KB Output is correct
5 Correct 29 ms 102144 KB Output is correct
6 Correct 31 ms 102492 KB Output is correct
7 Correct 28 ms 101984 KB Output is correct
8 Correct 29 ms 101980 KB Output is correct
9 Correct 29 ms 102232 KB Output is correct
10 Correct 29 ms 102220 KB Output is correct
11 Correct 28 ms 101980 KB Output is correct
12 Correct 29 ms 101976 KB Output is correct
13 Correct 28 ms 101976 KB Output is correct
14 Correct 28 ms 101980 KB Output is correct
15 Correct 29 ms 101972 KB Output is correct
16 Correct 28 ms 101980 KB Output is correct
17 Correct 29 ms 101980 KB Output is correct
18 Correct 33 ms 101972 KB Output is correct
19 Correct 29 ms 101980 KB Output is correct
20 Correct 29 ms 101980 KB Output is correct
21 Correct 28 ms 101976 KB Output is correct
22 Correct 29 ms 101948 KB Output is correct
23 Correct 28 ms 101980 KB Output is correct
24 Correct 29 ms 101980 KB Output is correct
25 Correct 29 ms 101972 KB Output is correct
26 Correct 52 ms 105608 KB Output is correct
27 Correct 57 ms 106064 KB Output is correct
28 Correct 99 ms 113952 KB Output is correct
29 Correct 171 ms 125564 KB Output is correct
30 Correct 51 ms 106580 KB Output is correct
31 Correct 34 ms 103004 KB Output is correct
32 Correct 185 ms 124312 KB Output is correct
33 Correct 113 ms 117788 KB Output is correct
34 Correct 302 ms 136036 KB Output is correct
35 Correct 222 ms 129112 KB Output is correct
36 Correct 249 ms 134876 KB Output is correct
37 Correct 254 ms 134880 KB Output is correct
38 Correct 460 ms 177372 KB Output is correct
39 Correct 440 ms 177264 KB Output is correct
40 Correct 442 ms 177488 KB Output is correct
41 Correct 452 ms 177492 KB Output is correct
42 Correct 441 ms 177232 KB Output is correct
43 Correct 888 ms 191244 KB Output is correct
44 Correct 835 ms 191164 KB Output is correct
45 Correct 897 ms 191144 KB Output is correct
46 Correct 867 ms 191060 KB Output is correct
47 Correct 836 ms 191272 KB Output is correct
48 Correct 35 ms 102736 KB Output is correct
49 Correct 33 ms 102744 KB Output is correct
50 Correct 32 ms 102444 KB Output is correct
51 Correct 34 ms 102224 KB Output is correct
52 Correct 33 ms 102228 KB Output is correct
53 Correct 38 ms 102548 KB Output is correct
54 Correct 32 ms 102428 KB Output is correct
55 Correct 30 ms 102236 KB Output is correct
56 Correct 30 ms 102232 KB Output is correct
57 Correct 31 ms 102404 KB Output is correct
58 Correct 30 ms 102236 KB Output is correct
59 Correct 31 ms 102380 KB Output is correct
60 Correct 30 ms 102224 KB Output is correct
61 Correct 30 ms 102224 KB Output is correct
62 Correct 31 ms 102232 KB Output is correct
63 Correct 30 ms 102236 KB Output is correct
64 Correct 30 ms 102236 KB Output is correct
65 Correct 30 ms 102384 KB Output is correct
66 Correct 31 ms 102380 KB Output is correct
67 Correct 30 ms 102416 KB Output is correct
68 Correct 29 ms 102224 KB Output is correct
69 Correct 30 ms 102236 KB Output is correct
70 Correct 121 ms 113400 KB Output is correct
71 Correct 121 ms 113236 KB Output is correct
72 Correct 121 ms 110244 KB Output is correct
73 Correct 123 ms 110316 KB Output is correct
74 Correct 77 ms 106640 KB Output is correct
75 Correct 79 ms 106836 KB Output is correct
76 Correct 73 ms 106836 KB Output is correct
77 Correct 67 ms 106580 KB Output is correct
78 Correct 77 ms 106496 KB Output is correct
79 Correct 67 ms 106544 KB Output is correct
80 Correct 63 ms 106656 KB Output is correct
81 Correct 63 ms 106580 KB Output is correct
82 Correct 63 ms 106580 KB Output is correct
83 Correct 63 ms 106580 KB Output is correct
84 Correct 63 ms 106612 KB Output is correct
85 Correct 29 ms 102196 KB Output is correct
86 Correct 28 ms 101976 KB Output is correct
87 Correct 29 ms 102448 KB Output is correct
88 Correct 823 ms 185068 KB Output is correct
89 Correct 832 ms 184852 KB Output is correct
90 Correct 804 ms 184728 KB Output is correct
91 Correct 689 ms 148224 KB Output is correct
92 Correct 666 ms 148444 KB Output is correct
93 Correct 676 ms 148304 KB Output is correct
94 Correct 580 ms 146528 KB Output is correct
95 Correct 651 ms 146484 KB Output is correct
96 Correct 618 ms 146512 KB Output is correct
97 Correct 527 ms 146348 KB Output is correct
98 Correct 517 ms 146196 KB Output is correct
99 Correct 606 ms 146260 KB Output is correct
100 Correct 452 ms 143788 KB Output is correct
101 Correct 441 ms 143736 KB Output is correct
102 Correct 463 ms 142976 KB Output is correct
103 Correct 435 ms 143212 KB Output is correct
104 Correct 423 ms 143072 KB Output is correct
105 Correct 414 ms 142852 KB Output is correct
106 Correct 388 ms 140768 KB Output is correct
107 Correct 409 ms 140920 KB Output is correct