#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 1000010
int N, M, a[MAXN], rez[MAXN], bit[MAXN];
stack<int> st;
vector<pii> p;
struct Query{
int l, r, k, idx;
Query() { l = r = k = idx = 0; }
Query(int _l, int _r, int _k, int _idx) { l = _l; r = _r; k = _k; idx = _idx; }
}q[MAXN];
void update(int idx, int val) {
for( ; idx < MAXN; idx += idx&-idx) bit[idx] = max(bit[idx], val);
}
int query(int idx) {
int rez = 0;
for( ; idx > 0; idx -= idx&-idx) rez = max(rez, bit[idx]);
return rez;
}
bool cmp1(Query a, Query b) {
return a.l > b.l;
}
bool cmp2(pii a, pii b) {
return a.fi > b.fi;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin >> N >> M;
a[0] = INF+1;
st.push(0);
for(int i = 1; i <= N; i++) {
cin >> a[i];
while(a[i] > a[st.top()]) st.pop();
p.pb({st.top(), i});
st.push(i);
}
for(int i = 1; i <= M; i++) {
cin >> q[i].l >> q[i].r >> q[i].k;
q[i].idx = i;
}
sort(q+1, q+1+M, cmp1);
sort(all(p), cmp2);
int id = 0;
for(int i = 1; i <= M; i++) {
int l = q[i].l, r = q[i].r, k = q[i].k, idx = q[i].idx;
while(id < N && l <= p[id].fi) {
update(p[id].se, a[p[id].fi]+a[p[id].se]);
id++;
}
rez[idx] = (query(r) <= k);
}
for(int i = 1; i <= M; i++) cout << rez[i] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
15992 KB |
Output is correct |
2 |
Correct |
16 ms |
15992 KB |
Output is correct |
3 |
Correct |
16 ms |
16120 KB |
Output is correct |
4 |
Correct |
16 ms |
15992 KB |
Output is correct |
5 |
Correct |
16 ms |
16092 KB |
Output is correct |
6 |
Correct |
16 ms |
16120 KB |
Output is correct |
7 |
Correct |
16 ms |
16120 KB |
Output is correct |
8 |
Correct |
16 ms |
16120 KB |
Output is correct |
9 |
Correct |
16 ms |
16092 KB |
Output is correct |
10 |
Incorrect |
16 ms |
16120 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
15992 KB |
Output is correct |
2 |
Correct |
16 ms |
15992 KB |
Output is correct |
3 |
Correct |
16 ms |
16120 KB |
Output is correct |
4 |
Correct |
16 ms |
15992 KB |
Output is correct |
5 |
Correct |
16 ms |
16092 KB |
Output is correct |
6 |
Correct |
16 ms |
16120 KB |
Output is correct |
7 |
Correct |
16 ms |
16120 KB |
Output is correct |
8 |
Correct |
16 ms |
16120 KB |
Output is correct |
9 |
Correct |
16 ms |
16092 KB |
Output is correct |
10 |
Incorrect |
16 ms |
16120 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
978 ms |
61744 KB |
Output is correct |
2 |
Correct |
1006 ms |
70716 KB |
Output is correct |
3 |
Correct |
950 ms |
70548 KB |
Output is correct |
4 |
Correct |
959 ms |
70620 KB |
Output is correct |
5 |
Incorrect |
867 ms |
70756 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
91 ms |
20336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
15992 KB |
Output is correct |
2 |
Correct |
16 ms |
15992 KB |
Output is correct |
3 |
Correct |
16 ms |
16120 KB |
Output is correct |
4 |
Correct |
16 ms |
15992 KB |
Output is correct |
5 |
Correct |
16 ms |
16092 KB |
Output is correct |
6 |
Correct |
16 ms |
16120 KB |
Output is correct |
7 |
Correct |
16 ms |
16120 KB |
Output is correct |
8 |
Correct |
16 ms |
16120 KB |
Output is correct |
9 |
Correct |
16 ms |
16092 KB |
Output is correct |
10 |
Incorrect |
16 ms |
16120 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
15992 KB |
Output is correct |
2 |
Correct |
16 ms |
15992 KB |
Output is correct |
3 |
Correct |
16 ms |
16120 KB |
Output is correct |
4 |
Correct |
16 ms |
15992 KB |
Output is correct |
5 |
Correct |
16 ms |
16092 KB |
Output is correct |
6 |
Correct |
16 ms |
16120 KB |
Output is correct |
7 |
Correct |
16 ms |
16120 KB |
Output is correct |
8 |
Correct |
16 ms |
16120 KB |
Output is correct |
9 |
Correct |
16 ms |
16092 KB |
Output is correct |
10 |
Incorrect |
16 ms |
16120 KB |
Output isn't correct |