結果
問題 | No.2809 Sort Query |
ユーザー | chro_96 |
提出日時 | 2024-07-12 22:55:51 |
言語 | C (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,423 bytes |
コンパイル時間 | 286 ms |
コンパイル使用メモリ | 32,896 KB |
実行使用メモリ | 28,812 KB |
最終ジャッジ日時 | 2024-07-12 22:56:58 |
合計ジャッジ時間 | 58,055 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
24,044 KB |
testcase_01 | AC | 1,027 ms
28,812 KB |
testcase_02 | AC | 949 ms
28,696 KB |
testcase_03 | AC | 910 ms
28,580 KB |
testcase_04 | AC | 877 ms
28,616 KB |
testcase_05 | WA | - |
testcase_06 | AC | 628 ms
27,832 KB |
testcase_07 | AC | 577 ms
27,904 KB |
testcase_08 | WA | - |
testcase_09 | AC | 649 ms
28,032 KB |
testcase_10 | AC | 623 ms
27,904 KB |
testcase_11 | AC | 319 ms
28,544 KB |
testcase_12 | AC | 298 ms
28,544 KB |
testcase_13 | AC | 315 ms
28,672 KB |
testcase_14 | AC | 315 ms
28,672 KB |
testcase_15 | AC | 306 ms
28,800 KB |
testcase_16 | AC | 314 ms
28,544 KB |
testcase_17 | AC | 319 ms
28,672 KB |
testcase_18 | AC | 316 ms
28,456 KB |
testcase_19 | AC | 331 ms
28,544 KB |
testcase_20 | AC | 300 ms
28,540 KB |
testcase_21 | AC | 1,023 ms
28,544 KB |
testcase_22 | AC | 1,061 ms
28,544 KB |
testcase_23 | AC | 1,022 ms
28,604 KB |
testcase_24 | AC | 1,044 ms
28,512 KB |
testcase_25 | AC | 1,028 ms
28,612 KB |
testcase_26 | AC | 1,102 ms
28,632 KB |
testcase_27 | AC | 1,113 ms
28,544 KB |
testcase_28 | AC | 1,160 ms
28,544 KB |
testcase_29 | AC | 1,144 ms
28,544 KB |
testcase_30 | AC | 1,146 ms
28,544 KB |
testcase_31 | AC | 229 ms
27,392 KB |
testcase_32 | AC | 235 ms
27,392 KB |
testcase_33 | AC | 225 ms
27,392 KB |
testcase_34 | AC | 230 ms
27,520 KB |
testcase_35 | AC | 262 ms
27,648 KB |
testcase_36 | AC | 218 ms
26,272 KB |
testcase_37 | AC | 215 ms
26,368 KB |
testcase_38 | AC | 215 ms
26,400 KB |
testcase_39 | AC | 216 ms
26,892 KB |
testcase_40 | AC | 240 ms
26,368 KB |
testcase_41 | AC | 1,187 ms
28,584 KB |
testcase_42 | AC | 1,240 ms
28,588 KB |
testcase_43 | AC | 1,271 ms
28,632 KB |
testcase_44 | AC | 1,225 ms
28,512 KB |
testcase_45 | AC | 1,233 ms
28,544 KB |
testcase_46 | AC | 1,251 ms
28,576 KB |
testcase_47 | AC | 1,159 ms
28,592 KB |
testcase_48 | AC | 1,110 ms
28,552 KB |
testcase_49 | AC | 1,158 ms
28,680 KB |
testcase_50 | AC | 1,172 ms
28,604 KB |
testcase_51 | AC | 343 ms
28,752 KB |
testcase_52 | AC | 324 ms
28,612 KB |
testcase_53 | AC | 283 ms
28,672 KB |
testcase_54 | AC | 257 ms
28,632 KB |
testcase_55 | AC | 275 ms
28,524 KB |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | AC | 690 ms
26,788 KB |
testcase_60 | AC | 474 ms
26,752 KB |
testcase_61 | AC | 696 ms
27,556 KB |
testcase_62 | AC | 611 ms
26,752 KB |
testcase_63 | AC | 800 ms
27,392 KB |
testcase_64 | AC | 795 ms
28,056 KB |
testcase_65 | AC | 382 ms
26,240 KB |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | AC | 9 ms
23,936 KB |
testcase_69 | WA | - |
testcase_70 | AC | 9 ms
23,936 KB |
ソースコード
#include <stdio.h> #include <stdlib.h> int cmp_ll (const void *ap, const void *bp) { long long a = *(long long *)ap; long long b = *(long long *)bp; if (a < b) { return -1; } if (a > b) { return 1; } return 0; } void add_segt (int *t, int idx, int val, int size) { idx = idx+size-1; t[idx] += val; while (idx > 0) { idx = (idx-1)/2; t[idx] += val; } return; } int sum_segt_rec (int *t, int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return 0; } if (a <= l && r <= b) { return t[k]; } return sum_segt_rec(t, a, b, 2*k+1, l, (l+r)/2)+sum_segt_rec(t, a, b, 2*k+2, (l+r)/2, r); } int sum_segt (int *t, int a, int b, int size) { return sum_segt_rec(t, a, b, 0, 0, size); } int main () { int n = 0; int q = 0; long long a[300000] = {}; int t[300000] = {}; int k[300000] = {}; long long x[300000] = {}; int res = 0; long long val[600000] = {}; int val_cnt = 1; int w[300000] = {}; int prev = 0; int segt[2097151] = {}; int size = 1; int tmp[300000] = {}; res = scanf("%d", &n); res = scanf("%d", &q); for (int i = 0; i < n; i++) { res = scanf("%lld", a+i); val[i] = a[i]; } for (int i = 0; i < q; i++) { res = scanf("%d", t+i); if (t[i] != 2) { res = scanf("%d", k+i); if (t[i] == 1) { res = scanf("%lld", x+i); val[i+n] = x[i]; } } } qsort(val, n+q, sizeof(long long), cmp_ll); for (int i = 1; i < n+q; i++) { if (val[i-1] != val[i]) { val[val_cnt] = val[i]; val_cnt++; } } for (int i = 0; i < n; i++) { int idx[2] = { 0, val_cnt }; while (idx[1]-idx[0] > 1) { int nxt = (idx[0]+idx[1])/2; if (val[nxt] > a[i]) { idx[1] = nxt; } else { idx[0] = nxt; } } a[i] = (long long)idx[0]; } for (int i = 0; i < q; i++) { int idx[2] = { 0, val_cnt }; while (idx[1]-idx[0] > 1) { int nxt = (idx[0]+idx[1])/2; if (val[nxt] > x[i]) { idx[1] = nxt; } else { idx[0] = nxt; } } x[i] = (long long)idx[0]; } while (size <= val_cnt) { size <<= 1; } for (int i = 0; i < n; i++) { add_segt(segt, (int)a[i], 1, size); } for (int i = 0; i < q; i++) { if (t[i] == 1) { a[k[i]-1] = x[i]; w[k[i]-1] = i; } else if (t[i] == 2) { for (int j = prev; j < i; j++) { if (t[j] == 1 && w[k[j]-1] == j) { int idx[2] = { -1, val_cnt-1 }; while (idx[1]-idx[0] > 1) { int nxt = (idx[0]+idx[1])/2; if (sum_segt(segt, 0, nxt+1, size) < k[j]) { idx[0] = nxt; } else { idx[1] = nxt; } } tmp[j] = idx[1]; } } for (int j = prev; j < i; j++) { if (t[j] == 1 && w[k[j]-1] == j) { add_segt(segt, tmp[j], -1, size); add_segt(segt, (int)x[j], 1, size); } } prev = i+1; } else if (w[k[i]-1] >= prev) { printf("%lld\n", val[a[k[i]-1]]); } else { int idx[2] = { -1, val_cnt-1 }; while (idx[1]-idx[0] > 1) { int nxt = (idx[0]+idx[1])/2; if (sum_segt(segt, 0, nxt+1, size) < k[i]) { idx[0] = nxt; } else { idx[1] = nxt; } } printf("%lld\n", val[idx[1]]); } } return 0; }