#include <stdio.h>
#define N1 200000
#define N2 200000
#define M 200000
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int uu[M], vv[M];
void sort(int *hh, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = uu[hh[j]] != uu[h] ? uu[h] - uu[hh[j]] : vv[hh[j]] - vv[h];
if (c == 0)
j++;
else if (c < 0) {
tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
i++, j++;
} else {
k--;
tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
}
}
sort(hh, l, i);
l = k;
}
}
int main() {
static int hh[M], uul[M], uur[M], vvl[M], vvr[M];
static char tt[M];
int n1, n2, m, h, cnt, ans;
scanf("%d%d%d", &n1, &n2, &m);
for (h = 0; h < m; h++) {
scanf("%d%d", &uu[h], &vv[h]);
hh[h] = h;
}
sort(hh, 0, m);
cnt = 0;
for (h = 0; h < m; h++) {
int h_ = hh[h];
uul[h_] = uur[h_] = uu[h_], vvl[h_] = vvr[h_] = vv[h_];
if (cnt && vvl[hh[cnt - 1]] <= vv[h_]) {
while (cnt && vvl[hh[cnt - 1]] <= vv[h_]) {
uul[h_] = min(uul[h_], uul[hh[cnt - 1]]), uur[h_] = max(uur[h_], uur[hh[cnt - 1]]);
vvl[h_] = min(vvl[h_], vvl[hh[cnt - 1]]), vvr[h_] = max(vvr[h_], vvr[hh[cnt - 1]]);
cnt--;
}
tt[h_] = 1, hh[cnt++] = h_;
} else
tt[h_] = 0, hh[cnt++] = h_;
}
ans = n1 + n2;
for (h = 0; h < cnt; h++)
if (tt[hh[h]] == 1)
ans -= (uur[hh[h]] - uul[hh[h]] + 1) + (vvr[hh[h]] - vvl[hh[h]] + 1) - 1;
printf("%d\n", ans);
for (h = 0; h < m; h++)
printf("%d ", tt[h]);
printf("\n");
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:45:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%d%d%d", &n1, &n2, &m);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:47:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d%d", &uu[h], &vv[h]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |