Submission #544784

#TimeUsernameProblemLanguageResultExecution timeMemory
544784rainboyHotel (CEOI11_hot)C11
100 / 100
646 ms37220 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...