#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
struct segtree {
int ptwo;
vector<ll> seg;
segtree(){}
ll& operator[](int i) {
return seg[i+ptwo];
}
segtree(int nn) {
ptwo=1;
while(ptwo<nn)
ptwo*=2;
seg.assign(ptwo*2,0);
}
auto query(int l, int r) {
assert(l>=0 and l<ptwo and r >=0 and r<ptwo);
l+=ptwo; r+=ptwo;
ll res = -oo;
while(l and l<=r) {
if(l%2==1) res = max(res,seg[l++]);
if(r%2==0) res = max(res,seg[r--]);
l/=2; r/=2;
}
return res;
}
void update(int i, ll val) {
assert(i>=0 and i<ptwo);
i+=ptwo;
seg[i] += val;
for(i/=2;i>=1;i/=2) {
seg[i] = max(seg[2*i],seg[2*i+1]);
}
}
void build() {
for(int i=ptwo-1;i>=1;--i) seg[i] = max(seg[2*i],seg[2*i+1]);
}
};
int main() {
int n,m; cin >> n >> m;
struct query {
int l,k,id;
};
vector<vector<query>> queries(n);
segtree seg(n);
vi w(n);
for(int i=0;i<n;++i) cin >> seg[i], w[i]=seg[i];
seg.build();
for(int i=0;i<m;++i) {
int l,r,k; cin >> l >> r >> k,--l,--r;
queries[r].push_back({l,k,i});
}
vi prv(n,-1), from(n,0),ans(m,-1);
int active=-1;
for(int i=0;i<n;++i) {
prv[i]=i-1;
while(prv[i]!=-1 and w[prv[i]]<=w[i]) prv[i] = prv[prv[i]];
while(active<prv[i]) {
++active;
}
if(prv[i]!=-1) {
int& before = from[prv[i]];
if(w[i]>before) {
seg.update(prv[i], w[i]-before);
before=w[i];
}
}
for(auto& q : queries[i]) {
ans[q.id]=active<0?1:(seg.query(q.l, active)<=q.k);
}
}
for(auto i : ans) {
cout << i << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
600 KB |
Output is correct |
12 |
Correct |
8 ms |
728 KB |
Output is correct |
13 |
Correct |
8 ms |
852 KB |
Output is correct |
14 |
Correct |
11 ms |
884 KB |
Output is correct |
15 |
Correct |
9 ms |
796 KB |
Output is correct |
16 |
Correct |
8 ms |
716 KB |
Output is correct |
17 |
Correct |
7 ms |
664 KB |
Output is correct |
18 |
Correct |
7 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2360 ms |
79848 KB |
Output is correct |
2 |
Correct |
2342 ms |
80212 KB |
Output is correct |
3 |
Correct |
2372 ms |
80056 KB |
Output is correct |
4 |
Correct |
2339 ms |
80172 KB |
Output is correct |
5 |
Correct |
2024 ms |
80280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
10564 KB |
Output is correct |
2 |
Correct |
158 ms |
10180 KB |
Output is correct |
3 |
Correct |
140 ms |
10436 KB |
Output is correct |
4 |
Correct |
139 ms |
10472 KB |
Output is correct |
5 |
Correct |
140 ms |
10564 KB |
Output is correct |
6 |
Correct |
133 ms |
9940 KB |
Output is correct |
7 |
Correct |
133 ms |
9924 KB |
Output is correct |
8 |
Correct |
136 ms |
9980 KB |
Output is correct |
9 |
Correct |
95 ms |
3708 KB |
Output is correct |
10 |
Correct |
137 ms |
9992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
600 KB |
Output is correct |
12 |
Correct |
8 ms |
728 KB |
Output is correct |
13 |
Correct |
8 ms |
852 KB |
Output is correct |
14 |
Correct |
11 ms |
884 KB |
Output is correct |
15 |
Correct |
9 ms |
796 KB |
Output is correct |
16 |
Correct |
8 ms |
716 KB |
Output is correct |
17 |
Correct |
7 ms |
664 KB |
Output is correct |
18 |
Correct |
7 ms |
716 KB |
Output is correct |
19 |
Correct |
439 ms |
22860 KB |
Output is correct |
20 |
Correct |
448 ms |
22964 KB |
Output is correct |
21 |
Correct |
381 ms |
22340 KB |
Output is correct |
22 |
Correct |
386 ms |
22536 KB |
Output is correct |
23 |
Correct |
401 ms |
22380 KB |
Output is correct |
24 |
Correct |
348 ms |
22312 KB |
Output is correct |
25 |
Correct |
342 ms |
22468 KB |
Output is correct |
26 |
Correct |
374 ms |
22420 KB |
Output is correct |
27 |
Correct |
360 ms |
22452 KB |
Output is correct |
28 |
Correct |
375 ms |
22540 KB |
Output is correct |
29 |
Correct |
374 ms |
22980 KB |
Output is correct |
30 |
Correct |
379 ms |
22852 KB |
Output is correct |
31 |
Correct |
373 ms |
22808 KB |
Output is correct |
32 |
Correct |
373 ms |
22852 KB |
Output is correct |
33 |
Correct |
372 ms |
22852 KB |
Output is correct |
34 |
Correct |
344 ms |
22008 KB |
Output is correct |
35 |
Correct |
345 ms |
22036 KB |
Output is correct |
36 |
Correct |
340 ms |
22016 KB |
Output is correct |
37 |
Correct |
346 ms |
22024 KB |
Output is correct |
38 |
Correct |
346 ms |
22212 KB |
Output is correct |
39 |
Correct |
351 ms |
21700 KB |
Output is correct |
40 |
Correct |
293 ms |
16148 KB |
Output is correct |
41 |
Correct |
328 ms |
21312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
600 KB |
Output is correct |
12 |
Correct |
8 ms |
728 KB |
Output is correct |
13 |
Correct |
8 ms |
852 KB |
Output is correct |
14 |
Correct |
11 ms |
884 KB |
Output is correct |
15 |
Correct |
9 ms |
796 KB |
Output is correct |
16 |
Correct |
8 ms |
716 KB |
Output is correct |
17 |
Correct |
7 ms |
664 KB |
Output is correct |
18 |
Correct |
7 ms |
716 KB |
Output is correct |
19 |
Correct |
2360 ms |
79848 KB |
Output is correct |
20 |
Correct |
2342 ms |
80212 KB |
Output is correct |
21 |
Correct |
2372 ms |
80056 KB |
Output is correct |
22 |
Correct |
2339 ms |
80172 KB |
Output is correct |
23 |
Correct |
2024 ms |
80280 KB |
Output is correct |
24 |
Correct |
178 ms |
10564 KB |
Output is correct |
25 |
Correct |
158 ms |
10180 KB |
Output is correct |
26 |
Correct |
140 ms |
10436 KB |
Output is correct |
27 |
Correct |
139 ms |
10472 KB |
Output is correct |
28 |
Correct |
140 ms |
10564 KB |
Output is correct |
29 |
Correct |
133 ms |
9940 KB |
Output is correct |
30 |
Correct |
133 ms |
9924 KB |
Output is correct |
31 |
Correct |
136 ms |
9980 KB |
Output is correct |
32 |
Correct |
95 ms |
3708 KB |
Output is correct |
33 |
Correct |
137 ms |
9992 KB |
Output is correct |
34 |
Correct |
439 ms |
22860 KB |
Output is correct |
35 |
Correct |
448 ms |
22964 KB |
Output is correct |
36 |
Correct |
381 ms |
22340 KB |
Output is correct |
37 |
Correct |
386 ms |
22536 KB |
Output is correct |
38 |
Correct |
401 ms |
22380 KB |
Output is correct |
39 |
Correct |
348 ms |
22312 KB |
Output is correct |
40 |
Correct |
342 ms |
22468 KB |
Output is correct |
41 |
Correct |
374 ms |
22420 KB |
Output is correct |
42 |
Correct |
360 ms |
22452 KB |
Output is correct |
43 |
Correct |
375 ms |
22540 KB |
Output is correct |
44 |
Correct |
374 ms |
22980 KB |
Output is correct |
45 |
Correct |
379 ms |
22852 KB |
Output is correct |
46 |
Correct |
373 ms |
22808 KB |
Output is correct |
47 |
Correct |
373 ms |
22852 KB |
Output is correct |
48 |
Correct |
372 ms |
22852 KB |
Output is correct |
49 |
Correct |
344 ms |
22008 KB |
Output is correct |
50 |
Correct |
345 ms |
22036 KB |
Output is correct |
51 |
Correct |
340 ms |
22016 KB |
Output is correct |
52 |
Correct |
346 ms |
22024 KB |
Output is correct |
53 |
Correct |
346 ms |
22212 KB |
Output is correct |
54 |
Correct |
351 ms |
21700 KB |
Output is correct |
55 |
Correct |
293 ms |
16148 KB |
Output is correct |
56 |
Correct |
328 ms |
21312 KB |
Output is correct |
57 |
Correct |
2378 ms |
88248 KB |
Output is correct |
58 |
Correct |
2341 ms |
80136 KB |
Output is correct |
59 |
Correct |
2277 ms |
78964 KB |
Output is correct |
60 |
Correct |
2233 ms |
78720 KB |
Output is correct |
61 |
Correct |
2275 ms |
78736 KB |
Output is correct |
62 |
Correct |
2233 ms |
78720 KB |
Output is correct |
63 |
Correct |
1699 ms |
77184 KB |
Output is correct |
64 |
Correct |
1692 ms |
77028 KB |
Output is correct |
65 |
Correct |
2049 ms |
80136 KB |
Output is correct |
66 |
Correct |
2035 ms |
78872 KB |
Output is correct |
67 |
Correct |
2024 ms |
78940 KB |
Output is correct |
68 |
Correct |
2083 ms |
80500 KB |
Output is correct |
69 |
Correct |
2035 ms |
89640 KB |
Output is correct |
70 |
Correct |
2033 ms |
89040 KB |
Output is correct |
71 |
Correct |
2067 ms |
88880 KB |
Output is correct |
72 |
Correct |
2040 ms |
88908 KB |
Output is correct |
73 |
Correct |
1677 ms |
74624 KB |
Output is correct |
74 |
Correct |
1718 ms |
74236 KB |
Output is correct |
75 |
Correct |
1672 ms |
74540 KB |
Output is correct |
76 |
Correct |
1691 ms |
74540 KB |
Output is correct |
77 |
Correct |
1681 ms |
74592 KB |
Output is correct |
78 |
Correct |
1908 ms |
78104 KB |
Output is correct |
79 |
Correct |
1533 ms |
50800 KB |
Output is correct |
80 |
Correct |
1733 ms |
77896 KB |
Output is correct |