結果
問題 | No.2220 Range Insert & Point Mex |
ユーザー | chro_96 |
提出日時 | 2023-02-17 22:42:47 |
言語 | C (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,447 bytes |
コンパイル時間 | 1,080 ms |
コンパイル使用メモリ | 31,360 KB |
実行使用メモリ | 15,616 KB |
最終ジャッジ日時 | 2024-07-19 13:53:17 |
合計ジャッジ時間 | 7,731 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
14,336 KB |
testcase_01 | AC | 5 ms
14,296 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 5 ms
14,344 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 268 ms
15,296 KB |
testcase_21 | AC | 268 ms
15,232 KB |
testcase_22 | AC | 260 ms
15,360 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 53 ms
14,784 KB |
testcase_28 | AC | 56 ms
14,528 KB |
testcase_29 | AC | 57 ms
14,464 KB |
testcase_30 | AC | 56 ms
14,412 KB |
testcase_31 | AC | 135 ms
15,360 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
ソースコード
#include <stdio.h> #include <stdlib.h> int cmp_int (const void *ap, const void *bp) { int a = *(int *)ap; int b = *(int *)bp; if (a < b) { return -1; } if (a > b) { return 1; } return 0; } void eval (int *t, int *lazy, int k, int l, int r) { if (lazy[k] <= 0) { return; } t[k] = lazy[k]; if (r-l > 1) { if (t[2*k+1] >= lazy[k]-1 || lazy[2*k+1] >= lazy[k]-1) { lazy[2*k+1] = lazy[k]; } if (t[2*k+2] >= lazy[k]-1 || lazy[2*k+2] >= lazy[k]-1) { lazy[2*k+2] = lazy[k]; } } lazy[k] = 0; return; } void set_segt_rec (int *t, int *lazy, int a, int b, int val, int k, int l, int r) { eval(t, lazy, k, l, r); if (r <= a || b <= l) { return; } if (a <= l && r <= b) { if (t[k] >= val-1) { lazy[k] = val; eval(t, lazy, k, l, r); } return; } set_segt_rec(t, lazy, a, b, val, 2*k+1, l, (l+r)/2); set_segt_rec(t, lazy, a, b, val, 2*k+2, (l+r)/2, r); t[k] = t[2*k+1]; if (t[k] < t[2*k+2]) { t[k] = t[k+2]; } return; } void set_segt (int *t, int *lazy, int a, int b, int val, int size) { set_segt_rec(t, lazy, a, b, val, 0, 0, size); return; } int max_segt_rec (int *t, int *lazy, int a, int b, int k, int l, int r) { int ans = 0; int tmp = 0; if (r <= a || b <= l) { return 0; } eval(t, lazy, k, l, r); if (a <= l && r <= b) { return t[k]; } ans = max_segt_rec(t, lazy, a, b, 2*k+1, l, (l+r)/2); tmp = max_segt_rec(t, lazy, a, b, 2*k+2, (l+r)/2, r); if (ans < tmp) { ans = tmp; } return ans; } int max_segt (int *t, int *lazy, int a, int b, int size) { return max_segt_rec(t, lazy, a, b, 0, 0, size); } int main () { int n = 0; int l[100000] = {}; int r[100000] = {}; int a[100000][2] = {}; int q = 0; int x[100000] = {}; int res = 0; int map[300000] = {}; int cnt = 0; int uniq_cnt = 1; int t[1200000] = {}; int lazy[1200000] = {}; int size = 1; res = scanf("%d", &n); for (int i = 0; i < n; i++) { res = scanf("%d", l+i); res = scanf("%d", r+i); res = scanf("%d", a[i]); map[cnt] = l[i]; cnt++; map[cnt] = r[i]; cnt++; a[i][1] = i; } res = scanf("%d", &q); for (int i = 0; i < q; i++) { res = scanf("%d", x+i); map[cnt] = x[i]; cnt++; } qsort(map, cnt, sizeof(int), cmp_int); for (int i = 1; i < cnt; i++) { if (map[i-1] != map[i]) { map[uniq_cnt] = map[i]; uniq_cnt++; } } while (size <= uniq_cnt) { size <<= 1; } qsort(a, n, sizeof(int)*2, cmp_int); for (int i = 0; i < n; i++) { int lidx[2] = { 0, uniq_cnt }; int ridx[2] = { 0, uniq_cnt }; while (lidx[1]-lidx[0] > 1) { int nxt = (lidx[0]+lidx[1])/2; if (map[nxt] <= l[a[i][1]]) { lidx[0] = nxt; } else { lidx[1] = nxt; } } while (ridx[1]-ridx[0] > 1) { int nxt = (ridx[0]+ridx[1])/2; if (map[nxt] <= r[a[i][1]]) { ridx[0] = nxt; } else { ridx[1] = nxt; } } set_segt(t, lazy, lidx[0], ridx[1], a[i][0]+1, size); } for (int i = 0; i < q; i++) { int idx[2] = { 0, uniq_cnt }; while (idx[1]-idx[0] > 1) { int nxt = (idx[0]+idx[1])/2; if (map[nxt] <= x[i]) { idx[0] = nxt; } else { idx[1] = nxt; } } printf("%d\n", max_segt(t, lazy, idx[0], idx[1], size)); } return 0; }