結果
問題 | No.2220 Range Insert & Point Mex |
ユーザー | chro_96 |
提出日時 | 2023-02-17 23:25:34 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 385 ms / 2,000 ms |
コード長 | 3,712 bytes |
コンパイル時間 | 907 ms |
コンパイル使用メモリ | 32,640 KB |
実行使用メモリ | 20,180 KB |
最終ジャッジ日時 | 2024-07-21 12:54:26 |
合計ジャッジ時間 | 9,097 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
19,072 KB |
testcase_01 | AC | 6 ms
19,072 KB |
testcase_02 | AC | 7 ms
18,976 KB |
testcase_03 | AC | 8 ms
19,000 KB |
testcase_04 | AC | 8 ms
18,988 KB |
testcase_05 | AC | 7 ms
19,072 KB |
testcase_06 | AC | 7 ms
19,052 KB |
testcase_07 | AC | 6 ms
19,072 KB |
testcase_08 | AC | 7 ms
18,944 KB |
testcase_09 | AC | 8 ms
18,992 KB |
testcase_10 | AC | 6 ms
19,000 KB |
testcase_11 | AC | 7 ms
19,072 KB |
testcase_12 | AC | 8 ms
19,072 KB |
testcase_13 | AC | 382 ms
19,968 KB |
testcase_14 | AC | 375 ms
20,096 KB |
testcase_15 | AC | 374 ms
19,968 KB |
testcase_16 | AC | 374 ms
19,968 KB |
testcase_17 | AC | 385 ms
19,968 KB |
testcase_18 | AC | 384 ms
20,180 KB |
testcase_19 | AC | 380 ms
20,096 KB |
testcase_20 | AC | 312 ms
19,984 KB |
testcase_21 | AC | 306 ms
19,968 KB |
testcase_22 | AC | 310 ms
20,160 KB |
testcase_23 | AC | 171 ms
19,968 KB |
testcase_24 | AC | 145 ms
19,584 KB |
testcase_25 | AC | 122 ms
19,768 KB |
testcase_26 | AC | 144 ms
19,828 KB |
testcase_27 | AC | 55 ms
19,604 KB |
testcase_28 | AC | 61 ms
19,456 KB |
testcase_29 | AC | 63 ms
19,200 KB |
testcase_30 | AC | 65 ms
19,200 KB |
testcase_31 | AC | 142 ms
19,968 KB |
testcase_32 | AC | 112 ms
19,584 KB |
testcase_33 | AC | 117 ms
19,712 KB |
testcase_34 | AC | 199 ms
20,096 KB |
testcase_35 | AC | 216 ms
19,888 KB |
testcase_36 | AC | 165 ms
19,984 KB |
testcase_37 | AC | 176 ms
19,976 KB |
testcase_38 | AC | 161 ms
20,096 KB |
ソースコード
#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[][2], int k, int l, int r) { if (lazy[k][0] <= 0) { return; } t[k] = lazy[k][0]; if (r-l > 1) { if (t[2*k+1] >= lazy[k][1]-1 || lazy[2*k+1][0] >= lazy[k][1]-1) { lazy[2*k+1][0] = lazy[k][0]; if (lazy[2*k+1][1] <= 0) { lazy[2*k+1][1] = lazy[k][1]; } } if (t[2*k+2] >= lazy[k][1]-1 || lazy[2*k+2][0] >= lazy[k][1]-1) { lazy[2*k+2][0] = lazy[k][0]; if (lazy[2*k+2][1] <= 0) { lazy[2*k+2][1] = lazy[k][1]; } } } lazy[k][0] = 0; lazy[k][1] = 0; return; } void set_segt_rec (int *t, int lazy[][2], 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][0] = val; lazy[k][1] = 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[2*k+2]; } return; } void set_segt (int *t, int lazy[][2], 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[][2], 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[][2], 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][2] = {}; 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; }