Submission #543495

# Submission time Handle Problem Language Result Execution time Memory
543495 2022-03-30T18:21:32 Z fuad27 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
163 ms 9904 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
#define ff first
#define ss second
ll fen[N];
ll arr[N];
void upd(int at, ll val) {
	at++;
	while(at < N) {
		fen[at] = max(fen[at], val);
		at+=at&(-at);
	}
}
ll get(int r) {
	r++;
	ll mx = 0;
	while(r > 0) {
		mx = max(mx, fen[r]);
		r-=r&(-r);
	}
	return mx;
}
int main () {
	int n, m;
	cin >> n >> m;
	for(int i = 0;i<N;i++)fen[i] = 0;
	for(int i = 0;i<n;i++)cin >> arr[i];
	vector<pair<pair<ll,ll>, ll>> que[n];
	for(int i = 0;i<m;i++){
		ll l, r, v;
		cin >> l >> r >> v;
		l--,r--;
		que[r].push_back(make_pair(make_pair(l, v), i));
	}
	ll ans[N];
	vector<ll> stk;
	for(int i = 0;i<n;i++) {
		while(stk.size() and arr[stk.back()] <= arr[i])stk.pop_back();
		if(stk.size())upd(stk.back(), arr[i] + arr[stk.back()]);
		stk.push_back(i);
		for(auto q:que[i]) {
			ans[q.ss] = (get(q.ff.ff) <= q.ff.ss);
		}
	}
	for(int i = 0;i<m;i++) {
		cout << ans[i] << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Incorrect 2 ms 3412 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Incorrect 2 ms 3412 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 156 ms 9864 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 163 ms 9904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Incorrect 2 ms 3412 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Incorrect 2 ms 3412 KB Output isn't correct
4 Halted 0 ms 0 KB -