Submission #63918852
Source Code Expand
Copy
#include <stdio.h>#include <stdlib.h>#define INF 1010101010struct node_s {int value;struct node_s* next[2];};int array_get(const struct node_s* node, int idx) {if (node == NULL) return INF;if (idx == 0) return node->value;return array_get(node->next[idx & 1], idx >> 1);}struct node_s* array_set(const struct node_s* node, int idx, int value) {struct node_s* res = malloc(sizeof(*res));if (res == NULL) exit(2);if (node != NULL) {*res = *node;
#include <stdio.h> #include <stdlib.h> #define INF 1010101010 struct node_s { int value; struct node_s* next[2]; }; int array_get(const struct node_s* node, int idx) { if (node == NULL) return INF; if (idx == 0) return node->value; return array_get(node->next[idx & 1], idx >> 1); } struct node_s* array_set(const struct node_s* node, int idx, int value) { struct node_s* res = malloc(sizeof(*res)); if (res == NULL) exit(2); if (node != NULL) { *res = *node; } else { res->value = INF; res->next[0] = NULL; res->next[1] = NULL; } if (idx == 0) { res->value = value; } else { res->next[idx & 1] = array_set(res->next[idx & 1], idx >> 1, value); } return res; } int N, Q; int A[212345]; int R[212345], X[212345]; int lis_num[212345]; struct node_s* lis[212345]; int main(void) { int i; if (scanf("%d%d", &N, &Q) != 2) return 1; for (i = 1; i <= N; i++) { if (scanf("%d", &A[i]) != 1) return 1; } for (i = 0; i < Q; i++) { if (scanf("%d%d", &R[i], &X[i]) != 2) return 1; } for (i = 1; i <= N; i++) { int l = -1, ge = lis_num[i - 1]; while (l + 1 < ge) { int m = l + (ge - l) / 2; if (array_get(lis[i - 1], m) >= A[i]) ge = m; else l = m; } lis[i] = array_set(lis[i - 1], ge, A[i]); lis_num[i] = lis_num[i - 1] + (ge >= lis_num[i - 1]); } for (i = 0; i < Q; i++) { int le = -1, g = lis_num[R[i]]; while (le + 1 < g) { int m = le + (g - le) / 2; if (array_get(lis[R[i]], m) <= X[i]) le = m; else g = m; } printf("%d\n", le + 1); } return 0; } /* それぞれの A_i ごとに、よくあるLISのやつをやる 永続配列?を使う → 連想配列でやる 配列の中身 → その長さにできる、一番大きいやつの最小 */
Submission Info
Submission Time | |
---|---|
Task | F - Prefix LIS Query |
User | mikecat |
Language | C (gcc 12.2.0) |
Score | 500 |
Code Size | 1806 Byte |
Status | AC |
Exec Time | 1720 ms |
Memory | 117108 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 03_random3_05.txt, 03_random3_06.txt, 03_random3_07.txt, 03_random3_08.txt, 03_random3_09.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 1 ms | 1628 KB |
00_sample_01.txt | AC | 1 ms | 1652 KB |
01_random_00.txt | AC | 0 ms | 1624 KB |
01_random_01.txt | AC | 35 ms | 3292 KB |
01_random_02.txt | AC | 95 ms | 66096 KB |
01_random_03.txt | AC | 89 ms | 43612 KB |
01_random_04.txt | AC | 137 ms | 25352 KB |
01_random_05.txt | AC | 130 ms | 17968 KB |
01_random_06.txt | AC | 489 ms | 67828 KB |
01_random_07.txt | AC | 474 ms | 67868 KB |
01_random_08.txt | AC | 477 ms | 67880 KB |
01_random_09.txt | AC | 485 ms | 67896 KB |
01_random_10.txt | AC | 492 ms | 67924 KB |
01_random_11.txt | AC | 488 ms | 67844 KB |
01_random_12.txt | AC | 485 ms | 67800 KB |
01_random_13.txt | AC | 491 ms | 67756 KB |
01_random_14.txt | AC | 491 ms | 67808 KB |
02_random2_00.txt | AC | 160 ms | 67684 KB |
02_random2_01.txt | AC | 165 ms | 67916 KB |
02_random2_02.txt | AC | 170 ms | 67748 KB |
02_random2_03.txt | AC | 206 ms | 67732 KB |
02_random2_04.txt | AC | 489 ms | 67796 KB |
03_random3_00.txt | AC | 1715 ms | 117012 KB |
03_random3_01.txt | AC | 93 ms | 15312 KB |
03_random3_02.txt | AC | 1717 ms | 117004 KB |
03_random3_03.txt | AC | 109 ms | 22888 KB |
03_random3_04.txt | AC | 1720 ms | 117004 KB |
03_random3_05.txt | AC | 131 ms | 35636 KB |
03_random3_06.txt | AC | 1715 ms | 116912 KB |
03_random3_07.txt | AC | 157 ms | 46312 KB |
03_random3_08.txt | AC | 1703 ms | 115692 KB |
03_random3_09.txt | AC | 225 ms | 56408 KB |
04_handmade_00.txt | AC | 86 ms | 12596 KB |
04_handmade_01.txt | AC | 1186 ms | 117008 KB |
04_handmade_02.txt | AC | 85 ms | 12616 KB |
04_handmade_03.txt | AC | 49 ms | 12536 KB |
04_handmade_04.txt | AC | 304 ms | 117108 KB |