# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
485887 | gavgav | Fountain (eJOI20_fountain) | C++17 | 107 ms | 9540 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 <stdio.h>
#define MAX_N 100000
#define MAX_M 200000
#define MAX_D 1000000000
#define MAX_S 100000000000000
struct rezervor {
int d, v;
};
struct query {
int s, v, rasp;
};
int stiva[MAX_N + 1], next[MAX_M + 1], liste[MAX_N + 1];
long long sumaNec[MAX_N + 1];
struct rezervor rez[MAX_N + 1];
struct query q[MAX_M + 1];
int main() {
int n, m, top, st, dr, mij, i, j;
long long sumaV;
scanf( "%d%d", &n, &m );
rez[0].d = MAX_D + 1;
rez[0].v = 0;
for ( i = 1; i <= n; i++ )
scanf( "%d%d", &rez[i].d, &rez[i].v );
for ( i = 1; i <= m; i++ ) {
scanf( "%d%d", &q[i].s, &q[i].v );
next[i] = liste[q[i].s];
liste[q[i].s] = i;
}
stiva[0] = 0;
sumaNec[0] = -MAX_S - 1;
top = 0;
sumaV = 0;
for ( i = n; i >= 1; i-- ) {
while ( rez[i].d >= rez[stiva[top]].d ) {
sumaV -= rez[stiva[top]].v;
top--;
}
top++;
stiva[top] = i;
sumaNec[top] = sumaV;
sumaV += rez[i].v;
j = liste[i];
while ( j != 0 ) {
st = top + 1;
dr = 0;
while ( st - dr > 1 ) {
mij = (st + dr) / 2;
if ( sumaV - sumaNec[mij] >= q[j].v )
dr = mij;
else
st = mij;
}
q[j].rasp = stiva[dr];
j = next[j];
}
}
for ( i = 1; i <= m; i++ )
printf( "%d\n", q[i].rasp );
}
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... |