# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
468481 | 2021-08-28T13:32:08 Z | gavgav | Fountain (eJOI20_fountain) | C++17 | 108 ms | 2912 KB |
#include <iostream> #include <vector> #include <stack> using namespace std; int main(){ /* * Get dates about fountain * Creating array in witch every number denotes index of the nearest number witch greater than this reservoir. * Indexes in this array means number of reservoir. */ int height, queries; scanf("%d%d", &height, &queries); int diameters[height], next_grater[height + 1], capacities[height + 1]; capacities[height] = 0; fill(next_grater, next_grater + height + 1, -1); stack <int> meowmeow; for (int i = 0; i < height; i++){ scanf("%d%d", &diameters[i], &capacities[i]); while (!meowmeow.empty() && diameters[i] > diameters[meowmeow.top()]){ next_grater[meowmeow.top()] = i; meowmeow.pop(); } meowmeow.push(i); } while (!meowmeow.empty()){ next_grater[meowmeow.top()] = height; meowmeow.pop(); } /* * Creating of any possible water path. */ int indexes[height + 1], last = 0; fill(indexes, indexes + height, -1); vector <int> lengths; vector <vector <int>> ways; for (int i = 0; i < height;){ ways.push_back(vector <int> {}); lengths.push_back(-1); for (int j = i; j + 1;){ ways[last].push_back(j); lengths[last]++; indexes[j] = last; if (j + 1 == next_grater[j]){ i++; } j = next_grater[j]; } i++; while (i < height && indexes[i] != - 1){ i++; } last++; } /* * Creating postfix sums array. */ for (int i = height; i > -1; i--){ if (next_grater[i] != -1){ capacities[i] += capacities[next_grater[i]]; } } /* * Get queries and by binary search print answer. */ int volume, level, left, right, middle, answer; while (queries--){ scanf("%d %d", &level, &volume); level--; left = 0, right = lengths[indexes[level]]; while (left - right < 1){ middle = (left + right) / 2; if (volume > capacities[level] - capacities[ways[indexes[level]][middle]]){ answer = ways[indexes[level]][middle] + 1; left = middle + 1; } else { right = middle - 1; } } printf("%d\n", answer % (height + 1)); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 396 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 104 ms | 2912 KB | Output is correct |
2 | Correct | 108 ms | 2888 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 396 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |