結果
問題 | No.2988 Min-Plus Convolution Query |
ユーザー | ygussany |
提出日時 | 2024-12-14 20:33:56 |
言語 | C (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,798 bytes |
コンパイル時間 | 328 ms |
コンパイル使用メモリ | 33,536 KB |
実行使用メモリ | 8,832 KB |
最終ジャッジ日時 | 2024-12-14 20:34:47 |
合計ジャッジ時間 | 40,830 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | TLE | - |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | AC | 29 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 43 ms
5,248 KB |
testcase_10 | WA | - |
testcase_11 | AC | 6 ms
5,248 KB |
testcase_12 | AC | 13 ms
5,248 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 171 ms
5,248 KB |
testcase_18 | WA | - |
testcase_19 | AC | 117 ms
5,248 KB |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | AC | 1 ms
5,248 KB |
testcase_33 | AC | 1 ms
5,248 KB |
testcase_34 | AC | 2 ms
5,248 KB |
testcase_35 | AC | 1 ms
5,248 KB |
testcase_36 | AC | 1 ms
5,248 KB |
testcase_37 | AC | 1 ms
5,248 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 1 ms
5,248 KB |
testcase_41 | WA | - |
ソースコード
#include <stdio.h> const int sup = 2000000001, inf = -sup; void chmin(int *a, int b) { if (*a > b) *a = b; } void chmax(int *a, int b) { if (*a < b) *a = b; } // B should convex // min[l3-r3] will be min-plus convolution of (A[l1-r1], B[l2-r2]) void min_plus_convolution(int l1, int r1, int l2, int r2, int l3, int r3, int A[], int B[], int argmin[]) { if (l3 > r3) return; chmax(&l2, l3 - r1); chmin(&r2, r3 - l1); int i, j, k = (l3 + r3) / 2, min = sup; for (i = l1, j = k - i; i <= r1 && j >= l2; i++, j--) { if (j > r2) continue; if (min > A[i] + B[j]) { min = A[i] + B[j]; argmin[k] = i; } } min_plus_convolution(l1, argmin[k], l2, r2, l3, k - 1, A, B, argmin); min_plus_convolution(argmin[k], r1, l2, r2, k + 1, r3, A, B, argmin); } void solve(int N, int A[], int B[], int Q, int p[], int x[], int k[], int ans[]) { static int argmin[400001]; min_plus_convolution(1, N, 1, N, 2, N * 2, A, B, argmin); int h, i, j, NN = N * 2 + 1, head, tail; static int appear[200001], q[2501]; for (i = 1; i <= N; i++) appear[i] = 0; for (h = 1, tail = 0; h <= Q; h++) { A[p[h]] = x[h]; if (appear[p[h]] == 0) { appear[p[h]] = 1; q[tail++] = p[h]; } ans[h] = A[argmin[k[h]]] + B[k[h] - argmin[k[h]]]; for (head = 0; head < tail; head++) { i = q[head]; j = k[h] - i; if (1 <= j && j <= N) chmin(&(ans[h]), A[i] + B[j]); } if (tail == 2250) { for (head = 0; head < tail; head++) appear[q[head]] = 0; tail = 0; min_plus_convolution(1, N, 1, N, 2, N * 2, A, B, argmin); } } } void naive(int N, int A[], int B[], int Q, int p[], int x[], int k[], int ans[]) { int q; static int min[400001], argmin[400001]; for (q = 1; q <= Q; q++) { A[p[q]] = x[q]; min_plus_convolution(1, N, 1, N, 2, N * 2, A, B, argmin); ans[q] = min[k[q]]; } } #define MT_N 624 #define MT_M 397 #define MT_MATRIX_A 0x9908b0dfUL #define MT_UPPER_MASK 0x80000000UL #define MT_LOWER_MASK 0x7fffffffUL static unsigned int mt[MT_N]; static int mti = MT_N + 1; void init_genrand(unsigned int s) { mt[0] = s & 0xffffffffUL; for (mti = 1; mti < MT_N; mti++) { mt[mti] = (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); mt[mti] &= 0xffffffffUL; } } unsigned int genrand() { unsigned int y; static unsigned int mag01[2] = {0x0UL, MT_MATRIX_A}; if (mti >= MT_N) { int kk; if (mti == MT_N + 1) init_genrand(5489UL); for (kk = 0; kk < MT_N - MT_M; kk++) { y = (mt[kk] & MT_UPPER_MASK) | (mt[kk+1] & MT_LOWER_MASK); mt[kk] = mt[kk+MT_M] ^ (y >> 1) ^ mag01[y&0x1UL]; } for (; kk < MT_N - 1; kk++) { y = (mt[kk] & MT_UPPER_MASK) | (mt[kk+1] & MT_LOWER_MASK); mt[kk] = mt[kk+(MT_M-MT_N)] ^ (y >> 1) ^ mag01[y&0x1UL]; } y = (mt[MT_N-1] & MT_UPPER_MASK) | (mt[0] & MT_LOWER_MASK); mt[MT_N-1] = mt[MT_M-1] ^ (y >> 1) ^ mag01[y&0x1UL]; mti = 0; } y = mt[mti++]; y ^= (y >> 11); y ^= (y << 7) & 0x9d2c5680UL; y ^= (y << 15) & 0xefc60000UL; y ^= (y >> 18); return y; } int main() { int i, N, Q; static int A[200001], B[200001], p[200001], x[200001], k[200001], ans[200001]; scanf("%d %d", &N, &Q); for (i = 1; i <= N; i++) scanf("%d", &(A[i])); for (i = 1; i <= N; i++) scanf("%d", &(B[i])); for (i = 1; i <= Q; i++) scanf("%d %d %d", &(p[i]), &(x[i]), &(k[i])); solve(N, A, B, Q, p, x, k, ans); for (i = 1; i <= Q; i++) printf("%d\n", ans[i]); /* for (i = 1; i <= N; i++) A[i] = genrand() % 10; for (i = 1; i <= N; i++) B[i] = 0; for (i = 1; i <= Q; i++) { p[i] = genrand() % N + 1; x[i] = genrand() % 10; k[i] = genrand() % (N * 2 - 1) + 2; } solve(N, A, B, Q, p, x, k, ans); for (i = 1; i <= Q; i++) printf("%d\n", ans[i]); */ /* static int AA[200001], BB[200001], anss[200001]; while (1) { for (i = 1; i <= N; i++) AA[i] = genrand() % 10; for (i = 1; i <= N; i++) BB[i] = (i - (N + 1) / 2) * (i - (N + 1) / 2); for (i = 1; i <= Q; i++) { p[i] = genrand() % N + 1; x[i] = genrand() % 10; k[i] = genrand() % (N * 2 - 1) + 2; } for (i = 1; i <= N; i++) { A[i] = AA[i]; B[i] = BB[i]; } solve(N, A, B, Q, p, x, k, ans); for (i = 1; i <= N; i++) { A[i] = AA[i]; B[i] = BB[i]; } naive(N, A, B, Q, p, x, k, anss); for (i = 1; i <= Q; i++) if (ans[i] != anss[i]) break; if (i <= Q) { for (i = 1; i <= N; i++) printf("%d ", AA[i]); printf("\n"); for (i = 1; i <= N; i++) printf("%d ", BB[i]); printf("\n"); for (i = 1; i <= Q; i++) printf("%d %d %d\n", p[i], x[i], k[i]); printf("\n"); for (i = 1; i <= Q; i++) printf("%d ", ans[i]); printf("\n"); for (i = 1; i <= Q; i++) printf("%d ", anss[i]); printf("\n"); break; } } */ fflush(stdout); return 0; }