#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
#define X first
#define Y second
using namespace std;
const int MAXN = 500100;
vector <pair <int, int> > ve[2];
map <pair <int, int>, int> ind;
int sol[MAXN];
int main() {
ios_base::sync_with_stdio(false);
int A, B, m;
cin >> A >> B >> m;
REP(i, m) {
int x, y;
cin >> x >> y;
ve[0].push_back({x, y});
ve[1].push_back({y, x});
ind[{x, y}] = i;
}
sort(ve[0].begin(), ve[0].end());
sort(ve[1].begin(), ve[1].end());
int x = 0, y = 0;
int out = A + B;
while (x < ve[0].size() && y < ve[1].size()) {
int X = ve[0][x].first, Y = ve[1][y].first;
int u = ve[1][y].second;
int d = ve[0][x].second;
sol[ind[ve[0][x]]] = 1;
bool flag = true;
while (flag) {
flag = false;
if (x < ve[0].size() && ve[0][x].first <= u) {
if (d < ve[0][x].second) sol[ind[ve[0][x]]] = 1;
d = max(d, ve[0][x].second);
x++;
flag = true;
}
if (y < ve[1].size() && ve[1][y].first <= d) {
u = max(u, ve[1][y].second);
y++;
flag = true;
}
}
if (u == X && d == Y) continue;
if (u == X) sol[ind[{X, Y}]] = 0;
if (d == Y) sol[ind[{X, Y}]] = 1;
out -= (u - X + 1) + (d - Y + 1) - 1;
/*cout << X << " " << u << endl;
cout << Y << " " << d << endl;
cout << "------\n";*/
}
cout << out << "\n";
REP(i, m) cout << sol[i] << " ";
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:37:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | while (x < ve[0].size() && y < ve[1].size()) {
| ~~^~~~~~~~~~~~~~
Main.cpp:37:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | while (x < ve[0].size() && y < ve[1].size()) {
| ~~^~~~~~~~~~~~~~
Main.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | if (x < ve[0].size() && ve[0][x].first <= u) {
| ~~^~~~~~~~~~~~~~
Main.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | if (y < ve[1].size() && ve[1][y].first <= d) {
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
472 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
472 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
3 ms |
860 KB |
Output is correct |
20 |
Correct |
2 ms |
604 KB |
Output is correct |
21 |
Correct |
7 ms |
1372 KB |
Output is correct |
22 |
Correct |
41 ms |
6680 KB |
Output is correct |
23 |
Correct |
69 ms |
8600 KB |
Output is correct |
24 |
Correct |
96 ms |
13404 KB |
Output is correct |
25 |
Correct |
57 ms |
8228 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
472 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
3 ms |
860 KB |
Output is correct |
20 |
Correct |
2 ms |
604 KB |
Output is correct |
21 |
Correct |
7 ms |
1372 KB |
Output is correct |
22 |
Correct |
41 ms |
6680 KB |
Output is correct |
23 |
Correct |
69 ms |
8600 KB |
Output is correct |
24 |
Correct |
96 ms |
13404 KB |
Output is correct |
25 |
Correct |
57 ms |
8228 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
7 ms |
1116 KB |
Output is correct |
42 |
Correct |
4 ms |
860 KB |
Output is correct |
43 |
Correct |
7 ms |
1372 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
94 ms |
12436 KB |
Output is correct |
46 |
Correct |
19 ms |
3920 KB |
Output is correct |
47 |
Correct |
126 ms |
15292 KB |
Output is correct |
48 |
Correct |
43 ms |
5952 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
127 ms |
16936 KB |
Output is correct |
52 |
Correct |
138 ms |
14928 KB |
Output is correct |
53 |
Correct |
150 ms |
18992 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
68 ms |
10160 KB |
Output is correct |
57 |
Correct |
165 ms |
19616 KB |
Output is correct |
58 |
Correct |
11 ms |
2400 KB |
Output is correct |
59 |
Correct |
13 ms |
2328 KB |
Output is correct |
60 |
Correct |
12 ms |
2252 KB |
Output is correct |
61 |
Correct |
12 ms |
2388 KB |
Output is correct |
62 |
Correct |
122 ms |
19132 KB |
Output is correct |