Submission #908946

# Submission time Handle Problem Language Result Execution time Memory
908946 2024-01-17T03:14:34 Z PlayVoltz Fountain (eJOI20_fountain) C++17
100 / 100
909 ms 46332 KB
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <iostream>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
using namespace std;

#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back

int32_t main(){
	int n, q, a, b;
	cin>>n>>q;
	stack<pii> st;
	vector<int> vect(n+1, LLONG_MAX/2);
	vector<vector<int> > twok(n+1, vector<int>(20, 0)), val(n+1, vector<int>(20, INT_MAX));
	twok.resize(n+1, vector<int>(20, 0));
	for (int i=1; i<=n; ++i){
		cin>>a>>vect[i];
		while (!st.empty()&&st.top().first<a)twok[st.top().second][0]=i, val[st.top().second][0]=vect[i], st.pop();
		st.push(mp(a, i));
	}
	for (int j=1; j<20; ++j)for (int i=1; i<=n; ++i)twok[i][j]=twok[twok[i][j-1]][j-1], val[i][j]=val[i][j-1]+val[twok[i][j-1]][j-1];
	while (q--){
		cin>>a>>b;b-=vect[a];
		for (int i=19; i>=0; --i)if (val[a][i]<=b)b-=val[a][i], a=twok[a][i];
		if (b>0)a=twok[a][0];
		cout<<a<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 4 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 587 ms 40192 KB Output is correct
2 Correct 621 ms 39052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 4 ms 600 KB Output is correct
8 Correct 587 ms 40192 KB Output is correct
9 Correct 621 ms 39052 KB Output is correct
10 Correct 4 ms 856 KB Output is correct
11 Correct 266 ms 24916 KB Output is correct
12 Correct 909 ms 45624 KB Output is correct
13 Correct 638 ms 45140 KB Output is correct
14 Correct 612 ms 44472 KB Output is correct
15 Correct 535 ms 46332 KB Output is correct