답안 #709938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709938 2023-03-14T21:31:16 Z WonderfulWhale Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
909 ms 146112 KB
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
struct SegTree {
	const static int T = 1<<20;
	int t[2*T];
	void update(int x, int val) {
		x+=T;
		t[x] = max(t[x], val);
		x/=2;
		while(x) {
			t[x] = max(t[2*x], t[2*x+1]);
			x/=2;
		}
	}
	int query(int l, int r) {
		l+=T;
		r+=T;
		int ret = max(t[l], t[r]);
		while(l/2!=r/2) {
			if(l%2==0) ret = max(ret, t[l+1]);
			if(r%2==1) ret = max(ret, t[r-1]);
			l/=2;
			r/=2;
		}
		return ret;
	}
};
SegTree seg;
vector<pii> v[1000009];
int tab[1000009]; bool vis[1000009];
int ans[1000009];
vector<tuple<int, int, int, int>> Q;
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, q;
	cin >> n >> q;
	for(int i=0;i<n;i++) {
		cin >> tab[i];
	}
	vector<pii> s;
	for(int i=0;i<n;i++) {
		while(sz(s)&&s.back().nd<=tab[i]) {
			s.pop_back();
		}
		if(sz(s)) {
			v[s.back().st].pb({i, tab[i]+tab[s.back().st]});
		}
		s.pb({i, tab[i]});
	}
	for(int i=0;i<q;i++) {
		int l, r, k;
		cin >> l >> r >> k;
		l--;
		r--;
		Q.pb({-l, r, k, i});
	}
	sort(all(Q));
	for(auto [l, r, k, id]:Q) {
		l = -l;
		if(!vis[l]) {
			for(pii x:v[l]) {
				seg.update(x.st, x.nd);
			}
		}
		ans[id] = (k>=seg.query(0, r));
	}
	for(int i=0;i<q;i++) {
		cout << ans[i] << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23892 KB Output is correct
2 Correct 16 ms 23816 KB Output is correct
3 Incorrect 15 ms 23872 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23892 KB Output is correct
2 Correct 16 ms 23816 KB Output is correct
3 Incorrect 15 ms 23872 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 909 ms 146112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 87 ms 35012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23892 KB Output is correct
2 Correct 16 ms 23816 KB Output is correct
3 Incorrect 15 ms 23872 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23892 KB Output is correct
2 Correct 16 ms 23816 KB Output is correct
3 Incorrect 15 ms 23872 KB Output isn't correct
4 Halted 0 ms 0 KB -