# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
544784 |
2022-04-02T16:44:53 Z |
rainboy |
Hotel (CEOI11_hot) |
C |
|
646 ms |
37220 KB |
#include <stdio.h>
#define N 500000
#define M 500000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int *xx, *yy;
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = xx[ii[j]] != xx[i_] ? xx[ii[j]] - xx[i_] : yy[ii[j]] - yy[i_];
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
int dd[M], iq[1 + M], pq[M], cnt;
int lt(int i, int j) {
return dd[i] > dd[j];
}
int p2(int p) {
return (p *= 2) > cnt ? 0 : (lt(iq[p + 1], iq[p]) ? p + 1 : p);
}
void pq_up(int i) {
int p, q, j;
for (p = pq[i]; (q = p / 2) && lt(i, j = iq[q]); p = q)
iq[pq[j] = p] = j;
iq[pq[i] = p] = i;
}
void pq_dn(int i) {
int p, q, j;
for (p = pq[i]; (q = p2(p)) && lt(j = iq[q], i); p = q)
iq[pq[j] = p] = j;
iq[pq[i] = p] = i;
}
void pq_add(int i) {
pq[i] = ++cnt, pq_up(i);
}
int pq_remove_first() {
int i = iq[1], j = iq[cnt--];
if (j != i)
pq[j] = 1, pq_dn(j);
pq[i] = 0;
return i;
}
int main() {
static int aa[N], bb[N], cc[M], ee[N], hh[N], ii[N], jj[M];
int n, m, k_, k, h, i, j;
long long ans;
scanf("%d%d%d", &n, &m, &k);
for (i = 0; i < n; i++) {
scanf("%d%d", &bb[i], &aa[i]);
ii[i] = i;
}
xx = aa, yy = bb, sort(ii, 0, n);
for (j = 0; j < m; j++) {
scanf("%d%d", &dd[j], &cc[j]);
jj[j] = j;
}
xx = cc, yy = dd, sort(jj, 0, m);
k_ = 0;
for (i = 0, j = 0; i < n; i++) {
while (j < m && cc[jj[j]] <= aa[ii[i]])
pq_add(jj[j++]);
if (cnt)
ee[k_++] = dd[pq_remove_first()] - bb[ii[i]];
}
for (h = 0; h < k_; h++)
hh[h] = h;
xx = ee, yy = ee, sort(hh, 0, k_);
ans = 0;
for (h = k_ - 1; h >= 0 && ee[hh[h]] > 0 && h >= k_ - k; h--)
ans += ee[hh[h]];
printf("%lld\n", ans);
return 0;
}
Compilation message
hot.c: In function 'main':
hot.c:80:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | scanf("%d%d%d", &n, &m, &k);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
hot.c:82:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | scanf("%d%d", &bb[i], &aa[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hot.c:87:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | scanf("%d%d", &dd[j], &cc[j]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
3352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
5484 KB |
Output is correct |
2 |
Correct |
54 ms |
3692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
221 ms |
15008 KB |
Output is correct |
2 |
Correct |
179 ms |
9008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
489 ms |
29760 KB |
Output is correct |
2 |
Correct |
470 ms |
29796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
635 ms |
33988 KB |
Output is correct |
2 |
Correct |
646 ms |
37220 KB |
Output is correct |
3 |
Correct |
604 ms |
34368 KB |
Output is correct |