Submission #467757

# Submission time Handle Problem Language Result Execution time Memory
467757 2021-08-24T11:02:52 Z Lumos Fountain (eJOI20_fountain) C++17
60 / 100
422 ms 6288 KB
//amira
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define f first
#define s second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair <ll,ll>
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int M = 1e9+7;
const int N = 2e5 + 111;
const ll INF = 1e10 + 1;
const int K = 205;

ll n,q,d[N],w[N],nxt[N],p[N];

int main() {
	#ifdef MM 
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	stack <ll> st;
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> d[i] >> w[i];
		p[i] = p[i - 1] + w[i];
	}
	if (n <= 1000 && q <= 2000) {
		for (int i = n; i >= 1; i--) {
			while (!st.empty() && d[st.top()] <= d[i]) {
				st.pop();
			}
			if (st.empty()) nxt[i] = n + 1;
			else nxt[i] = st.top();
			st.push(i);
		}
		for (int i = 1; i <= q; i++) {
			ll id,l;
			cin >> id >> l;
			ll final = id, cur = id; //cout << "case " << i << endl;
			while (cur < n + 1 && w[cur] < l) {
				l -= w[cur];
				cur = nxt[cur];
				//cout << l << ' ' << cur << endl;
			}
			if (cur == n + 1) cout << 0 << endl;
			else cout << cur << endl;
		}
		return 0;
	}
	for (int i = 1; i <= q; i++) {
		ll id,l;
		cin >> id >> l;
		ll pos = lower_bound(p+1,p+1+n, l + p[id - 1]) - p;
		if (pos == n + 1) cout << 0 << endl;
		else cout << pos << endl;
	}

    return 0;
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:44:7: warning: unused variable 'final' [-Wunused-variable]
   44 |    ll final = id, cur = id; //cout << "case " << i << endl;
      |       ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
5 Correct 7 ms 308 KB Output is correct
6 Correct 6 ms 324 KB Output is correct
7 Correct 6 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 384 ms 6144 KB Output is correct
2 Correct 422 ms 6288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
5 Correct 7 ms 308 KB Output is correct
6 Correct 6 ms 324 KB Output is correct
7 Correct 6 ms 332 KB Output is correct
8 Correct 384 ms 6144 KB Output is correct
9 Correct 422 ms 6288 KB Output is correct
10 Incorrect 5 ms 332 KB Output isn't correct
11 Halted 0 ms 0 KB -