# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1039354 | 2024-07-30T18:52:08 Z | Shadxwed | Fountain (eJOI20_fountain) | C++ | 1500 ms | 4684 KB |
#include <cstdio> #include <cstdlib> typedef struct { int volume; int parent; int i; } treeStruct; typedef struct { int size; int i; } stackStruct; int main() { int n, q; scanf("%d %d", &n, &q); int *v = (int*)calloc(n, sizeof(int)); int *d = (int*)calloc(n, sizeof(int)); for(int i = 0; i < n; i++) { scanf("%d %d", d+i, v+i); } stackStruct *stk = (stackStruct*)calloc(n+1, sizeof(stackStruct)); int lenStk = 1; treeStruct *tree = (treeStruct*)calloc(n+1, sizeof(treeStruct)); stk[0] = (stackStruct){1000000001, 0}; tree[0] = (treeStruct){0, 0, 0}; for(int i = n-1; i >= 0; i--) { int curr = d[i]; if(curr < stk[lenStk - 1].size) { stk[lenStk++] = (stackStruct){curr, i+1}; } else { while(stk[(--lenStk)-1].size < curr); stk[lenStk++] = (stackStruct){curr, i+1}; } tree[i+1].parent = stk[lenStk-2].i; tree[i+1].volume = tree[tree[i+1].parent].volume + v[i]; tree[i+1].i = i+1; } int r, vol; for(int p = 0; p < q; p++) { scanf("%d %d", &r, &vol); treeStruct node = tree[r]; if(node.volume < vol) { printf("0\n"); continue; } while(true) { treeStruct parent = tree[node.parent]; vol -= v[node.i-1]; if(vol < 0) { printf("%d\n", node.i); break; } node = parent; } } free(v); free(d); free(stk); free(tree); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1570 ms | 348 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1566 ms | 4684 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1570 ms | 348 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |