제출 #1316705

#제출 시각아이디문제언어결과실행 시간메모리
1316705blackscreen1Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
0 / 100
405 ms49172 KiB
#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;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll n, m, a[1000005];
pair<pll, pll> b[1000005];
ll ans[1000005], cptr = 0;
vector<pll> checks;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	iloop(0, n) cin >> a[i];
	iloop(0, m) {cin >> b[i].first.second >> b[i].first.first >> b[i].second.first; b[i].second.second = i;}
	sort(b, b+m);
	vector<ll> st;
	iloop(0, n) {
		while (st.size() && a[st.back()] <= a[i]) st.pop_back();
		if (st.size()) {
			pll tm = {a[st.back()] + a[i], st.back()};
			while (checks.size() && checks.back().first <= tm.first) checks.pop_back();
			checks.push_back(tm);
		}
		while (cptr < m && b[cptr].first.first == i) {
			pll tm = {b[cptr].first.second, -1};
			auto it = lower_bound(checks.begin(), checks.end(), tm);
			ans[b[cptr].second.second] = !(it != checks.end() && (*it).first > b[cptr].second.first);
			cptr++;
		}
		st.push_back(i);
	}
	iloop(0, m) cout << ans[i] << "\n";
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...