Submission #787976

#TimeUsernameProblemLanguageResultExecution timeMemory
787976rainboyGym Badges (NOI22_gymbadges)C11
0 / 100
382 ms33568 KiB
#include <stdio.h> #include <string.h> #define N 500000 #define N_ (1 << 19) /* N_ = pow2(ceil(log2(N))) */ #define INF 0x3f3f3f3f3f3f3f3fLL long long min(long long a, long long b) { return a < b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int *vv; 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) if (vv[ii[j]] == vv[i_]) j++; else if (vv[ii[j]] < vv[i_]) { 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; } } long long ss[N_ * 2], dd[N_ * 2]; int n_; void pul(int i) { int l = i << 1, r = l | 1; ss[i] = ss[l] + ss[r]; dd[i] = min(dd[l], dd[r] == INF ? INF : dd[r] - ss[l]); } void build(int n) { int i; n_ = 1; while (n_ < n) n_ <<= 1; memset(dd + n_, 0x3f, n_ * sizeof *dd); for (i = 0; i < n; i++) dd[n_ + i] = INF; for (i = n_ - 1; i > 0; i--) pul(i); } void update(int i, int x, long long y) { i += n_; ss[i] = x, dd[i] = y; while (i > 1) pul(i >>= 1); } int main() { static int xx[N], yy[N], ii[N], idx[N]; int n, h, i, k; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &xx[i]); for (i = 0; i < n; i++) scanf("%d", &yy[i]); for (i = 0; i < n; i++) ii[i] = i; vv = yy, sort(ii, 0, n); for (i = 0; i < n; i++) idx[ii[i]] = i; vv = xx, sort(ii, 0, n); build(n); k = 0; for (h = 0; h < n; h++) { i = ii[h]; update(idx[i], xx[i], yy[i]); if (dd[1] >= 0) k++; else update(idx[i], 0, INF); } printf("%d\n", k); return 0; }

Compilation message (stderr)

Main.c: In function 'main':
Main.c:70:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:72:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |   scanf("%d", &xx[i]);
      |   ^~~~~~~~~~~~~~~~~~~
Main.c:74:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |   scanf("%d", &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...