Submission #833887

#TimeUsernameProblemLanguageResultExecution timeMemory
833887rainboyArcade (NOI20_arcade)C11
100 / 100
305 ms14516 KiB
#include <stdio.h> #define N 500000 int max(int a, int b) { return a > b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int xx[N], yy[N]; int compare_y(int i, int j) { return yy[i] == yy[j] ? 0 : (yy[i] < yy[j] ? -1 : 1); } int compare_xy(int i, int j) { return xx[i] != xx[j] ? (xx[i] > xx[j] ? -1 : 1) : (yy[i] == yy[j] ? 0 : (yy[i] > yy[j] ? -1 : 1)); } int (*compare)(int, int); 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 = compare(ii[j], 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 ft[N]; void update(int i, int n, int x) { while (i < n) { ft[i] = max(ft[i], x); i |= i + 1; } } int query(int i) { int x = 0; while (i >= 0) { x = max(x, ft[i]); i &= i + 1, i--; } return x; } int main() { static int ii[N]; int n, h, i, x, y; scanf("%*d%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++) { x = xx[i] + yy[i], y = xx[i] - yy[i]; xx[i] = x, yy[i] = y; } for (i = 0; i < n; i++) ii[i] = i; compare = compare_y, sort(ii, 0, n); for (h = 0, y = 0; h < n; h++) yy[ii[h]] = h + 1 == n || yy[ii[h + 1]] != yy[ii[h]] ? y++ : y; compare = compare_xy, sort(ii, 0, n); for (h = 0; h < n; h++) { i = ii[h]; update(yy[i], n, query(yy[i] - 1) + 1); } printf("%d\n", query(n - 1)); return 0; }

Compilation message (stderr)

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