# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1069241 | raduv | Fountain (eJOI20_fountain) | C++14 | 138 ms | 21076 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pi pair<int, int>
const int MAXN = 100'000;
const int LOG = 18;
using namespace std;
int rmq[LOG + 1][MAXN + 1];
int cap[LOG + 1][MAXN + 1];
pi stiva[MAXN + 1];
int ns;
priority_queue<pi, vector<pi>, greater<pi>> pq;
int main()
{
int n, q, i, diam, p, a, b;
scanf("%d%d", &n, &q);
for( i = 1; i <= n + 1; i++ ){
if( i <= n )
scanf("%d%d", &diam, &cap[0][i]);
else
diam = 1e9;
while(ns > 0 && diam > stiva[ns].first){
rmq[0][stiva[ns].second] = i;
ns--;
}
stiva[++ns] = {diam, i};
}
// https://infoarena.ro/problema/stramosi
for ( p = 1; p <= LOG; p++ ){
for( i = 1; i <= n; i++ ){
rmq[p][i] = rmq[p - 1][rmq[p - 1][i]];
cap[p][i] = cap[p - 1][i] + cap[p - 1][rmq[p - 1][i]];
}
}
while(q--){
scanf("%d%d", &a, &b);
for( i = LOG; i >= 0; i-- ){
if(cap[i][a] < b){
b -= cap[i][a];
a = rmq[i][a];
}
}
printf("%d\n", a);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |