#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b; cin >> a >> b;
int m; cin >> m;
vector<set<int>> froma(a+1), fromb(b+1);
map<pair<int, int>, int> id;
for (int i = 0; i < m; ++i){
int x, y; cin >> x >> y;
id[make_pair(x, y)] = i;
froma[x].insert(y);
fromb[y].insert(x);
}
int ans = 0;
vector<int> res(m);
int ca = a, cb = b;
while (ca >= 1 && cb >= 1){
if (froma[ca].empty()) {
ans++; ca--;
continue;
}
if (fromb[cb].empty()){
ans++; cb--;
continue;
}
int mxb = ca;
int mxa = cb;
int pa = ca, pb = cb;
while (ca >= mxa || cb >= mxb) {
if (ca >= mxa) {
if (!froma[ca].empty()){
mxb = min(mxb, *froma[ca].begin());
for (auto x : froma[ca]) fromb[x].erase(ca);
}
ca--;
}
if (cb >= mxb) {
if (!fromb[cb].empty()) {
mxa = min(mxa, *fromb[cb].begin());
if (mxa == *fromb[cb].begin()) res[id[make_pair(mxa, cb)]] = 1;
for (auto x : fromb[cb]) froma[x].erase(cb);
}
cb--;
}
}
ans++;
}
while (ca >= 1) ans++, ca--;
while (cb >= 1) ans++, cb--;
cout << ans << "\n";
for (auto x : res) cout << x << " ";
cout << "\n";
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:32:13: warning: unused variable 'pa' [-Wunused-variable]
32 | int pa = ca, pb = cb;
| ^~
Main.cpp:32:22: warning: unused variable 'pb' [-Wunused-variable]
32 | int pa = ca, pb = cb;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |