답안 #909837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909837 2024-01-17T13:13:45 Z kachu Fountain (eJOI20_fountain) C++17
60 / 100
750 ms 524288 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> 
#define ofind find_by_order
#define okey order_of_key

#define int long long
#define double long double
#define pque priority_queue
#define dque deque
#define que queue
#define umap unordered_map
#define uset unordered_set
#define pipii pair<int, pair<int,int>>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define iter iterator
#define endl '\n'
#define MOD 1000000007
#define INF 1e18 

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int N, Q;
	cin >> N >> Q;
	int D[N + 1], C[N + 1];
	
	for (int i = 1; i <= N; i++)
		cin >> D[i] >> C[i];
	
	int next[N + 1];
	stack<int> st;
	
	for (int i = N; i >= 1; i--){
		while (!st.empty() && D[st.top()] <= D[i])
			st.pop();
		
		if (!st.empty())
			next[i] = st.top();
		else
			next[i] = 0;
		
		st.push(i);
	}
	
	bool visited[N + 1];
	map<int, int> v[N + 1];
	int root[N + 1], prev[N + 1];
	
	memset(visited, 0, sizeof visited);
	
	for (int i = 1; i <= N; i++){
		if (visited[i]) continue;
		
		int ptr = i;
		while (ptr != 0){
			visited[ptr] = 1;
			root[ptr] = i;
			
			if (v[i].empty()){
				prev[ptr] = 0;
				v[i][C[ptr]] = ptr;
			}
			else{
				prev[ptr] = (--v[i].end())->first;
				v[i][prev[ptr] + C[ptr]] = ptr;
			}
			
			ptr = next[ptr];
		}
	}

	while (Q--){
		int a, x;
		cin >> a >> x;
		
		x = x + prev[a];
		a = root[a];
		
		auto ans = v[a].lower_bound(x);

		if (ans == v[a].end())
			cout << 0 << endl;
		else
			cout << (*ans).second << endl;
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 6 ms 3824 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 16208 KB Output is correct
2 Correct 99 ms 14928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 6 ms 3824 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 93 ms 16208 KB Output is correct
9 Correct 99 ms 14928 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Runtime error 750 ms 524288 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -