This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
//#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
//#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
#define int long long
#define pii pair < int, int >
#define pll pair < long long, long long >
using namespace std;
typedef long long ll;
const int N = 1e6 + 5;
const int M = 305;
const int mod = 1e9 + 7;
int n, m, a[N], L[N], t[4 * N], ans[N];
vector < pair < int, pii > > pos[N];
void update(int v, int l, int r, int pos, int val) {
if(l == r) {
t[v] = max(t[v], val);
return;
}
int md = (l + r) / 2;
if(pos <= md) update(v * 2, l, md, pos, val);
else update(v * 2 + 1, md + 1, r, pos, val);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
int get(int v, int l, int r, int tl, int tr) {
if(tl <= l && r <= tr) {
return t[v];
}
if(r < tl || tr < l) return 0;
int md = (l + r) / 2;
return max(get(v * 2, l, md, tl, tr),
get(v * 2 + 1, md + 1, r, tl, tr));
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//file("pieaters");
cin >> n >> m;
stack < pii > st;
for(int i = 1; i <= n; i++) {
cin >> a[i];
while(st.size() && (st.top()).first <= a[i]) {
st.pop();
}
if(st.size()) L[i] = (st.top()).second;
st.push({a[i], i});
}
for(int i = 1; i <= m; i++) {
int l, r, k;
cin >> l >> r >> k;
pos[r].pb({l, {k, i}});
}
for(int i = 1; i <= n; i++) {
if(L[i] > 0) update(1, 1, n, L[i], a[i] + a[L[i]]);
for(int j = 0; j < pos[i].size(); j++) {
int lef = pos[i][j].first, kk = pos[i][j].second.first, query = pos[i][j].second.second;
if(get(1, 1, n, lef, i) > kk) {
ans[query] = 0;
} else {
ans[query] = 1;
}
}
}
for(int i = 1; i <= m; i++) {
cout << ans[i] << endl;
}
}
Compilation message (stderr)
sortbooks.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
51 | main() {
| ^~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:73:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int j = 0; j < pos[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |