#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()
vector<pii> v[1000009];
int tab[1000009];
struct SegTree {
const static int T = 1<<20;
vector<pii> t[2*T];
void build(int n) {
for(int i=0;i<n;i++) {
if(sz(v[i])==0) continue;
t[i+T].pb(v[i][0]);
for(int j=1;j<sz(v[i]);j++) {
t[i+T].pb({v[i][j].st, max(v[i][j].nd, t[i+T].back().nd)});
}
cerr << "teraz: " << i+T << "\n";
for(pii x:t[i+T]) {
cerr << x.st << " " << x.nd << "\n";
}
}
for(int i=T-1;i>=1;i--) {
int l = 2*i;
int r = 2*i+1;
int a = 0;
int b = 0;
while(a!=sz(t[l])||b!=sz(t[r])) {
if(a==sz(t[l])) {
t[i].pb({t[r][b].st, max(t[r][b].nd, sz(t[i])?t[i].back().nd:(int)0)});
b++;
} else if(b==sz(t[r])) {
t[i].pb({t[l][a].st, max(t[l][a].nd, sz(t[i])?t[i].back().nd:(int)0)});
a++;
} else if(t[l][a].st<=t[r][b].st) {
t[i].pb({t[l][a].st, max(t[l][a].nd, sz(t[i])?t[i].back().nd:(int)0)});
a++;
} else {
t[i].pb({t[r][b].st, max(t[r][b].nd, sz(t[i])?t[i].back().nd:(int)0)});
b++;
}
}
cerr << "teraz: " << i << "\n";
for(pii x:t[i]) {
cerr << x.st << " " << x.nd << "\n";
}
}
}
int query(int val, int l, int r, int tl=0, int tr=T-1, int v=1) {
cerr << "query: " << val << " "<< l << " " << r << " " << tl << " " << tr << " " << v << "\n";
if(l > r) return 0;
if(tl==l&&tr==r) {
int s = -1;
int e = sz(t[v]);
while(e-s>1) {
int m = (e+s)/2;
if(t[v][m].st<=val) s = m;
else e = m;
}
if(s!=-1) return t[v][s].nd;
return 0;
}
int tm = (tl+tr)/2;
return max(query(val, l, min(r, tm), tl, tm, 2*v), query(val, max(l, tm+1), r, tm+1, tr, 2*v+1));
}
};
SegTree seg;
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)) {
cerr << "dodaje: " << tab[i]+tab[s.back().st] << " do: " << s.back().st << "\n";
v[s.back().st].pb({i, tab[i]+tab[s.back().st]});
}
s.pb({i, tab[i]});
}
cerr << "done\n";
seg.build(n);
for(int i=0;i<q;i++) {
int l, r, k;
cin >> l >> r >> k;
l--;
r--;
cout << (seg.query(r, l, r)<=k) << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3059 ms |
83420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3059 ms |
83420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3068 ms |
108316 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3078 ms |
88580 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3059 ms |
83420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3059 ms |
83420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |