Submission #1039354

#TimeUsernameProblemLanguageResultExecution timeMemory
1039354ShadxwedFountain (eJOI20_fountain)C++98
0 / 100
1570 ms4684 KiB
#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 (stderr)

fountain.cpp: In function 'int main()':
fountain.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
fountain.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d %d", d+i, v+i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
fountain.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d %d", &r, &vol);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...