# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
485904 | 2021-11-09T16:13:42 Z | gavgav | Fountain (eJOI20_fountain) | C++17 | 105 ms | 7748 KB |
#include <stdio.h> #define MAX_N 100000 #define MAX_M 200000 #define MAX_S 100000000000000 struct reservoir { long long diameters, capacity; }; struct query { int level, volume, rasp; }; int next[MAX_M + 1], liste[MAX_N + 1]; long long sumaNec[MAX_N + 1]; int main() { long long height, queries_number, top, i, j; long long sumaV; scanf( "%lld%lld", &height, &queries_number); long long stack[height + 1]; struct reservoir reservoirs[height + 1]; struct query queries[queries_number + 1]; reservoirs[0].diameters = 1000000001; reservoirs[0].capacity = 0; for (i = 1; i <= height; ++i) scanf( "%lld%lld", &reservoirs[i].diameters, &reservoirs[i].capacity); for (i = 1; i <= queries_number; ++i) { scanf( "%d%d", &queries[i].level, &queries[i].volume); next[i] = liste[queries[i].level]; liste[queries[i].level] = i; } stack[0] = 0; sumaNec[0] = -MAX_S - 1; top = 0; sumaV = 0; long long left, middle, right; for (i = height; i >= 1; --i) { while ( reservoirs[i].diameters >= reservoirs[stack[top]].diameters ) { sumaV -= reservoirs[stack[top]].capacity; --top; } ++top; stack[top] = i; sumaNec[top] = sumaV; sumaV += reservoirs[i].capacity; j = liste[i]; while (j != 0) { right = top + 1; left = 0; while (right - left > 1 ) { middle = (right + left) / 2; if (sumaV - sumaNec[middle] >= queries[j].volume) left = middle; else right = middle; } queries[j].rasp = stack[left]; j = next[j]; } } for (i = 1; i <= queries_number; ++i) printf("%d\n", queries[i].rasp); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 5936 KB | Output is correct |
2 | Correct | 78 ms | 6204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 70 ms | 5936 KB | Output is correct |
9 | Correct | 78 ms | 6204 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 43 ms | 3792 KB | Output is correct |
12 | Correct | 105 ms | 7748 KB | Output is correct |
13 | Correct | 101 ms | 7448 KB | Output is correct |
14 | Correct | 76 ms | 7256 KB | Output is correct |
15 | Correct | 72 ms | 7236 KB | Output is correct |