제출 #1149299

#제출 시각아이디문제언어결과실행 시간메모리
1149299ReLiceFountain (eJOI20_fountain)C++20
100 / 100
138 ms38980 KiB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class _T>
bool chmin(_T &x, const _T &y){
    if (x>y)x=y;
    return x>y;
}
template <class _T>
bool chmax(_T &x, const _T &y){
    if (x<y)x=y;
    return x<y;
}
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e18+7;
const ll mod=1e9+7;
const ll N=2e5+5;
const ld eps=1e-9;
ll p[N][20],up[N][20];
void solve(){
	ll i,j;
	ll a,b;
	ll n,q;
	cin>>n>>q;
	set<pair<ll,ll>> st;
	for(i=1;i<=n;i++){
        cin>>a>>b;
        up[i][0]=b;
        while(st.sz && st.begin()->fr<a){
            p[st.begin()->sc][0]=i;
            st.erase(st.begin());
        }
        st.ins({a,i});
	}
	for(i=n;i>0;i--){
        for(j=1;j<20;j++){
            up[i][j]=up[p[i][j-1]][j-1]+up[i][j-1];
            p[i][j]=p[p[i][j-1]][j-1];
        }
	}
	for(i=0;i<q;i++){
        cin>>a>>b;
        for(j=19;j>=0;j--){
            if(up[a][j]<b){
                b-=up[a][j];
                a=p[a][j];
            }
        }
        cout<<a<<endl;
	}
}
signed main(){
	start();
    ll t=1;
	//cin>>t;
    while(t--) solve();
    return 0;
}
/*





*/

컴파일 시 표준 에러 (stderr) 메시지

fountain.cpp: In function 'void fre(std::string)':
fountain.cpp:36:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:36:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...