Submission #1252113

#TimeUsernameProblemLanguageResultExecution timeMemory
1252113al95ireyizFountain (eJOI20_fountain)C++20
30 / 100
142 ms29832 KiB
//*** Bismillah ***// #pragma GCC optimize("O3", "fast-math", "unroll-loops", "no-stack-protector") #include <bits/stdc++.h> using namespace std; #if !defined(ONLINE_JUDGE) and !defined(EVAL) #include "template/debug.h" #else #define d(x...) #endif #define fr first #define er erase #define sc second #define in insert #define ll long long #define pb push_back #define vll vector<ll> #define pll pair<ll,ll> #define ull unsigned ll #define vpll vector<pll> #define len(x) (ll) x.size() #define all(x) x.begin(),x.end() const ll INF = 1e9; const ll INFL = 1e18; const ll MOD = 1e9+7; // const ll MOD = 998244353; const ll maxn = 1e5+5; ll n,m,k=0; ll a[maxn], b[maxn], to[20][maxn], up[20][maxn]; void _(ll &tt){ cin >> n >> m; for(ll i = 1; i <= n; i ++){ cin >> a[i] >> b[i]; } memset(to, -1, sizeof(to)); stack<pll>st; for(ll i = 1; i <= n; i ++){ while(!st.empty() and st.top().fr <= a[i]){ to[0][st.top().sc] = i; st.pop(); } st.push({a[i], i}); up[0][i] = b[i]; } while(!st.empty()){ to[0][st.top().sc] = 0; st.pop(); } for(ll i = 1; i < 20; i ++){ for(ll j = 0; j <= n; j ++){ if(to[i - 1][j] == -1) continue; if(to[i - 1][to[i - 1][j]] == -1) continue; to[i][j] = to[i - 1][to[i - 1][j]]; up[i][j] = up[i - 1][j] + up[i - 1][to[i - 1][j]]; } } for(ll i = 1, a, b; i <= m; i ++){ cin >> a >> b; ll cv = a; for(ll i = 19; i >= 0; i --){ if(to[i][a] == -1) continue; if(up[i][a] < b){ b -= up[i][a]; a = to[i][a]; } } cout << a << '\n'; } } signed main() { ll tm = clock(); cin.tie(0)->sync_with_stdio(0); ll t = 1; // cin >> t; for(ll tt = 1; tt <= t; tt ++) { _(tt); } cerr << "\n\033[1;31mTime: \033[1;30m" \ << (double)(clock()-tm)/1000000 << "\033[1;32m seconds\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...