답안 #470662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470662 2021-09-04T18:57:46 Z Sho10 Fountain (eJOI20_fountain) C++17
30 / 100
267 ms 43456 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,q,d[100005],c[100005],par[100005][25],sum[100005][25];
ll query(ll &pos,ll &cnt){
for(ll i=15;i>=0;i--)
{
    if(pos==0){
        break;
    }
   // cout<<sum[pos][i]<<' '<<cnt<<' '<<i<<endl;
    if(sum[pos][i]<cnt){
        cnt-=sum[pos][i];
        pos=par[pos][i];
    }
}
return pos;
}
int32_t main(){
CODE_START;
cin>>n>>q;
for(ll i=1;i<=n;i++)
{
    cin>>d[i]>>c[i];
}
stack<ll>s;
d[0]=LINF;
s.push(0);
for(ll i=n;i>=1;i--){
    while(d[s.top()]<=d[i]){
        s.pop();
    }
    par[i][0]=s.top();
    s.push(i);
}
for(ll j=1;j<=15;j++){
for(ll i=n;i>=1;i--)
    par[i][j]=par[par[i][j-1]][j-1];
}
for(ll i=1;i<=n;i++)
{
    sum[i][0]=c[i];
}
for(ll j=1;j<=15;j++)
{
    for(ll i=n;i>=1;i--)
    {
        sum[i][j]=sum[i][j-1]+sum[par[i][j-1]][j-1];
    }
}
while(q--){
ll x,y;
cin>>x>>y;
cout<<query(x,y)<<endl;
}
}



# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 267 ms 43456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Incorrect 267 ms 43456 KB Output isn't correct
9 Halted 0 ms 0 KB -