/*
Code written by Talant I.D.
*/
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
inline bool isvowel(char ch){
ch = tolower(ch);
return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
inline bool isprime(int n){
if(n < 2 || (n%2 == 0 && n != 2)) return false;
for(int i = 3; i*i <= n; i++)
if(n%i == 0) return false;
return true;
}
class Union{
private:
vector <int> saizu, link;
public:
Union(int n){
saizu.assign(n, 1); link.resize(n);
iota(all(link), 0);
}
int find(int n){
if(link[n] == n) return n;
return link[n] = find(link[n]);
}
int same(int a, int b){
return find(a) == find(b);
}
void unite(int a, int b){
if(same(a, b)) return;
a = find(a); b = find(b);
if(saizu[a] < saizu[b]) swap(a, b);
saizu[a] += saizu[b];
link[b] = a;
}
int getsize(int a){
return saizu[find(a)];
}
};
const int mod = 1e9+7;
ll mode(ll a){
a %= mod;
if(a < 0) a += mod;
return a;
}
ll subt(ll a, ll b){
return mode(mode(a)-mode(b));
}
ll add(ll a, ll b){
return mode(mode(a)+mode(b));
}
ll mult(ll a, ll b){
return mode(mode(a)*mode(b));
}
ll binpow(ll a, ll b){
ll res = 1;
while(b){
if(b&1) res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
const int N = 1e6+7;
ll tree[N*4];
int order[N];
struct query{
int l, ind;
ll mood;
};
vector <query> queries[N];
ll get(int v, int l, int r, int ql, int qr){
if(l > qr || ql > r) return 0;
if(ql <= l && r <= qr) return tree[v];
int mid = (l+r) >> 1;
return max(get(v*2, l, mid, ql, qr), get(v*2+1, mid+1, r, ql, qr));
}
void update(int v, int l, int r, int pos, ll val){
if(l == r){
tree[v] = val;
return ;
}
int mid = (l+r) >> 1;
if(pos <= mid) update(v*2, l, mid, pos, val);
else update(v*2+1, mid+1, r, pos, val);
tree[v] = max(tree[v*2], tree[v*2+1]);
}
int main(){
do_not_disturb
int n, q;
cin >> n >> q;
vector <ll> v(n+1), ans(q);
for(int i = 1; i <= n; i++){
cin >> v[i];
}
for(int i = 0; i < q; i++){
int l, r;
ll mood;
cin >> l >> r >> mood;
queries[r].pb({l, i, mood});
}
int ind = 0;
for(int i = 1; i <= n; i++){
while(ind && v[order[ind]] <= v[i]) ind--;
if(ind){
update(1, 1, n, order[ind], v[order[ind]]+v[i]);
}
order[++ind] = i;
for(auto to : queries[i]){
if(get(1, 1, n, to.l, i) > to.mood){
ans[to.ind] = 0;
}
else{
ans[to.ind] = 1;
}
}
}
for(auto to : ans) cout << to << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
18 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
18 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
11 |
Correct |
17 ms |
24044 KB |
Output is correct |
12 |
Correct |
18 ms |
24044 KB |
Output is correct |
13 |
Correct |
19 ms |
24172 KB |
Output is correct |
14 |
Correct |
22 ms |
24172 KB |
Output is correct |
15 |
Correct |
21 ms |
24172 KB |
Output is correct |
16 |
Correct |
20 ms |
24172 KB |
Output is correct |
17 |
Correct |
19 ms |
24044 KB |
Output is correct |
18 |
Correct |
19 ms |
24044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1872 ms |
114028 KB |
Output is correct |
2 |
Correct |
1801 ms |
88456 KB |
Output is correct |
3 |
Correct |
1836 ms |
117156 KB |
Output is correct |
4 |
Correct |
1797 ms |
117224 KB |
Output is correct |
5 |
Correct |
1399 ms |
82924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
31596 KB |
Output is correct |
2 |
Correct |
122 ms |
32108 KB |
Output is correct |
3 |
Correct |
122 ms |
30060 KB |
Output is correct |
4 |
Correct |
113 ms |
30188 KB |
Output is correct |
5 |
Correct |
116 ms |
30188 KB |
Output is correct |
6 |
Correct |
92 ms |
29804 KB |
Output is correct |
7 |
Correct |
91 ms |
29824 KB |
Output is correct |
8 |
Correct |
106 ms |
29924 KB |
Output is correct |
9 |
Correct |
61 ms |
28128 KB |
Output is correct |
10 |
Correct |
103 ms |
29924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
18 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
11 |
Correct |
17 ms |
24044 KB |
Output is correct |
12 |
Correct |
18 ms |
24044 KB |
Output is correct |
13 |
Correct |
19 ms |
24172 KB |
Output is correct |
14 |
Correct |
22 ms |
24172 KB |
Output is correct |
15 |
Correct |
21 ms |
24172 KB |
Output is correct |
16 |
Correct |
20 ms |
24172 KB |
Output is correct |
17 |
Correct |
19 ms |
24044 KB |
Output is correct |
18 |
Correct |
19 ms |
24044 KB |
Output is correct |
19 |
Correct |
315 ms |
43244 KB |
Output is correct |
20 |
Correct |
312 ms |
43392 KB |
Output is correct |
21 |
Correct |
256 ms |
42860 KB |
Output is correct |
22 |
Correct |
258 ms |
42732 KB |
Output is correct |
23 |
Correct |
263 ms |
42860 KB |
Output is correct |
24 |
Correct |
211 ms |
38508 KB |
Output is correct |
25 |
Correct |
216 ms |
38636 KB |
Output is correct |
26 |
Correct |
237 ms |
38764 KB |
Output is correct |
27 |
Correct |
238 ms |
38892 KB |
Output is correct |
28 |
Correct |
278 ms |
39148 KB |
Output is correct |
29 |
Correct |
252 ms |
39148 KB |
Output is correct |
30 |
Correct |
253 ms |
39148 KB |
Output is correct |
31 |
Correct |
250 ms |
39148 KB |
Output is correct |
32 |
Correct |
256 ms |
39148 KB |
Output is correct |
33 |
Correct |
261 ms |
39148 KB |
Output is correct |
34 |
Correct |
199 ms |
38124 KB |
Output is correct |
35 |
Correct |
198 ms |
38124 KB |
Output is correct |
36 |
Correct |
186 ms |
37996 KB |
Output is correct |
37 |
Correct |
194 ms |
37868 KB |
Output is correct |
38 |
Correct |
192 ms |
38124 KB |
Output is correct |
39 |
Correct |
231 ms |
38624 KB |
Output is correct |
40 |
Correct |
176 ms |
35676 KB |
Output is correct |
41 |
Correct |
222 ms |
37344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
18 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
11 |
Correct |
17 ms |
24044 KB |
Output is correct |
12 |
Correct |
18 ms |
24044 KB |
Output is correct |
13 |
Correct |
19 ms |
24172 KB |
Output is correct |
14 |
Correct |
22 ms |
24172 KB |
Output is correct |
15 |
Correct |
21 ms |
24172 KB |
Output is correct |
16 |
Correct |
20 ms |
24172 KB |
Output is correct |
17 |
Correct |
19 ms |
24044 KB |
Output is correct |
18 |
Correct |
19 ms |
24044 KB |
Output is correct |
19 |
Correct |
1872 ms |
114028 KB |
Output is correct |
20 |
Correct |
1801 ms |
88456 KB |
Output is correct |
21 |
Correct |
1836 ms |
117156 KB |
Output is correct |
22 |
Correct |
1797 ms |
117224 KB |
Output is correct |
23 |
Correct |
1399 ms |
82924 KB |
Output is correct |
24 |
Correct |
137 ms |
31596 KB |
Output is correct |
25 |
Correct |
122 ms |
32108 KB |
Output is correct |
26 |
Correct |
122 ms |
30060 KB |
Output is correct |
27 |
Correct |
113 ms |
30188 KB |
Output is correct |
28 |
Correct |
116 ms |
30188 KB |
Output is correct |
29 |
Correct |
92 ms |
29804 KB |
Output is correct |
30 |
Correct |
91 ms |
29824 KB |
Output is correct |
31 |
Correct |
106 ms |
29924 KB |
Output is correct |
32 |
Correct |
61 ms |
28128 KB |
Output is correct |
33 |
Correct |
103 ms |
29924 KB |
Output is correct |
34 |
Correct |
315 ms |
43244 KB |
Output is correct |
35 |
Correct |
312 ms |
43392 KB |
Output is correct |
36 |
Correct |
256 ms |
42860 KB |
Output is correct |
37 |
Correct |
258 ms |
42732 KB |
Output is correct |
38 |
Correct |
263 ms |
42860 KB |
Output is correct |
39 |
Correct |
211 ms |
38508 KB |
Output is correct |
40 |
Correct |
216 ms |
38636 KB |
Output is correct |
41 |
Correct |
237 ms |
38764 KB |
Output is correct |
42 |
Correct |
238 ms |
38892 KB |
Output is correct |
43 |
Correct |
278 ms |
39148 KB |
Output is correct |
44 |
Correct |
252 ms |
39148 KB |
Output is correct |
45 |
Correct |
253 ms |
39148 KB |
Output is correct |
46 |
Correct |
250 ms |
39148 KB |
Output is correct |
47 |
Correct |
256 ms |
39148 KB |
Output is correct |
48 |
Correct |
261 ms |
39148 KB |
Output is correct |
49 |
Correct |
199 ms |
38124 KB |
Output is correct |
50 |
Correct |
198 ms |
38124 KB |
Output is correct |
51 |
Correct |
186 ms |
37996 KB |
Output is correct |
52 |
Correct |
194 ms |
37868 KB |
Output is correct |
53 |
Correct |
192 ms |
38124 KB |
Output is correct |
54 |
Correct |
231 ms |
38624 KB |
Output is correct |
55 |
Correct |
176 ms |
35676 KB |
Output is correct |
56 |
Correct |
222 ms |
37344 KB |
Output is correct |
57 |
Correct |
1818 ms |
117228 KB |
Output is correct |
58 |
Correct |
1821 ms |
117224 KB |
Output is correct |
59 |
Correct |
1741 ms |
116332 KB |
Output is correct |
60 |
Correct |
1747 ms |
116452 KB |
Output is correct |
61 |
Correct |
1735 ms |
116468 KB |
Output is correct |
62 |
Correct |
1760 ms |
116204 KB |
Output is correct |
63 |
Correct |
1097 ms |
80620 KB |
Output is correct |
64 |
Correct |
1101 ms |
80748 KB |
Output is correct |
65 |
Correct |
1412 ms |
99936 KB |
Output is correct |
66 |
Correct |
1403 ms |
99848 KB |
Output is correct |
67 |
Correct |
1412 ms |
99952 KB |
Output is correct |
68 |
Correct |
1475 ms |
100832 KB |
Output is correct |
69 |
Correct |
1423 ms |
100740 KB |
Output is correct |
70 |
Correct |
1454 ms |
100556 KB |
Output is correct |
71 |
Correct |
1420 ms |
79820 KB |
Output is correct |
72 |
Correct |
1445 ms |
100700 KB |
Output is correct |
73 |
Correct |
981 ms |
89076 KB |
Output is correct |
74 |
Correct |
983 ms |
77096 KB |
Output is correct |
75 |
Correct |
993 ms |
89008 KB |
Output is correct |
76 |
Correct |
982 ms |
89140 KB |
Output is correct |
77 |
Correct |
974 ms |
89060 KB |
Output is correct |
78 |
Correct |
1276 ms |
89908 KB |
Output is correct |
79 |
Correct |
911 ms |
64456 KB |
Output is correct |
80 |
Correct |
1219 ms |
70360 KB |
Output is correct |