#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
struct node{
ll mx = 0;
node(ll a):mx(a){}
};
class pointseg{
private:
int n;
vector<node>t;
vector<ll>a;
void upd(int v,int tl,int tr,int pos,node val){
if(tl == tr){
t[v] = val;
return;
}
int tm = (tl+tr)/2;
if(pos <= tm){
upd(2*v,tl,tm,pos,val);
}else{
upd(2*v+1,tm+1,tr,pos,val);
}
t[v] = merge(t[2*v],t[2*v+1]);
}
node query(int v,int l,int r,int tl,int tr){
if(l > r)return node(0);
if(l == tl && r == tr){
return t[v];
}
int tm = (tl+tr)/2;
return merge(query(2*v,l,min(r,tm),tl,tm),
query(2*v+1,max(l,tm+1),r,tm+1,tr));
}
void build(int v,int tl,int tr){
if(tl == tr){
t[v] = a[tl];
return;
}
int tm = (tl+tr)/2;
build(2*v,tl,tm);
build(2*v+1,tm+1,tr);
t[v] = merge(t[2*v],t[2*v+1]);
}
public:
node merge(node a,node b){
return node(max(a.mx,b.mx));
}
void upd(int pos,node val){
upd(1,1,n,pos,val);
}
node query(int l,int r){
return query(1,l,r,1,n);
}
void build(){
build(1,1,n);
}
pointseg(int _n,vector<ll>_a ={}){
n = _n;
t.assign(4*n,node(0));
a = _a;
}
pointseg(){}
void reset(int _n,vector<ll>_a = {}){
n = _n;
t.clear();
t.assign(4*_n,node(0));
a = _a;
}
};
struct q{
int l,idx,x;
q(){}
q(int a,int b,int c){l=a;idx=b;x=c;}
};
int main()
{
owo
int n,m;
cin>>n>>m;
vector<int>a(n+1),lf(n+1,0);
for(int i=1;i<=n;i++)cin>>a[i];
stack<int>stk;
for(int i=1;i<=n;i++){
while(!stk.empty() && a[i] >= a[stk.top()])stk.pop();
if(!stk.empty())lf[i] = stk.top();
stk.push(i);
}
vector<bool>ans(m);
vector<vector<q>>qu(n+1);
for(int i=0;i<m;i++){
int l,r,x;
cin>>l>>r>>x;
qu[r].pb(q(l,i,x));
}
//for(int i=1;i<=n;i++)cout<<lf[i]<<" ";
//cout<<'\n';
pointseg s(n);
for(int i=1;i<=n;i++){
if(lf[i])s.upd(lf[i],a[i]+a[lf[i]]);
for(auto y:qu[i]){
ans[y.idx] = (s.query(y.l,i).mx <= y.x);
}
}
for(int i=0;i<m;i++)cout<<ans[i]<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
14 |
Correct |
6 ms |
848 KB |
Output is correct |
15 |
Correct |
6 ms |
844 KB |
Output is correct |
16 |
Correct |
4 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
708 KB |
Output is correct |
18 |
Correct |
4 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1573 ms |
86732 KB |
Output is correct |
2 |
Correct |
1665 ms |
119532 KB |
Output is correct |
3 |
Correct |
1627 ms |
119452 KB |
Output is correct |
4 |
Correct |
1638 ms |
119572 KB |
Output is correct |
5 |
Correct |
1495 ms |
119608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
8892 KB |
Output is correct |
2 |
Correct |
113 ms |
10560 KB |
Output is correct |
3 |
Correct |
124 ms |
10760 KB |
Output is correct |
4 |
Correct |
98 ms |
10784 KB |
Output is correct |
5 |
Correct |
97 ms |
10816 KB |
Output is correct |
6 |
Correct |
83 ms |
10256 KB |
Output is correct |
7 |
Correct |
81 ms |
10248 KB |
Output is correct |
8 |
Correct |
88 ms |
10324 KB |
Output is correct |
9 |
Correct |
46 ms |
3280 KB |
Output is correct |
10 |
Correct |
90 ms |
10288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
14 |
Correct |
6 ms |
848 KB |
Output is correct |
15 |
Correct |
6 ms |
844 KB |
Output is correct |
16 |
Correct |
4 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
708 KB |
Output is correct |
18 |
Correct |
4 ms |
716 KB |
Output is correct |
19 |
Correct |
283 ms |
24012 KB |
Output is correct |
20 |
Correct |
271 ms |
24140 KB |
Output is correct |
21 |
Correct |
220 ms |
23388 KB |
Output is correct |
22 |
Correct |
223 ms |
23376 KB |
Output is correct |
23 |
Correct |
233 ms |
23364 KB |
Output is correct |
24 |
Correct |
189 ms |
23236 KB |
Output is correct |
25 |
Correct |
214 ms |
23248 KB |
Output is correct |
26 |
Correct |
219 ms |
23616 KB |
Output is correct |
27 |
Correct |
207 ms |
23712 KB |
Output is correct |
28 |
Correct |
215 ms |
23624 KB |
Output is correct |
29 |
Correct |
225 ms |
24020 KB |
Output is correct |
30 |
Correct |
245 ms |
24020 KB |
Output is correct |
31 |
Correct |
230 ms |
24004 KB |
Output is correct |
32 |
Correct |
243 ms |
23976 KB |
Output is correct |
33 |
Correct |
223 ms |
24040 KB |
Output is correct |
34 |
Correct |
186 ms |
22760 KB |
Output is correct |
35 |
Correct |
186 ms |
22736 KB |
Output is correct |
36 |
Correct |
179 ms |
22520 KB |
Output is correct |
37 |
Correct |
180 ms |
22604 KB |
Output is correct |
38 |
Correct |
195 ms |
22796 KB |
Output is correct |
39 |
Correct |
207 ms |
22280 KB |
Output is correct |
40 |
Correct |
177 ms |
16880 KB |
Output is correct |
41 |
Correct |
194 ms |
21760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
14 |
Correct |
6 ms |
848 KB |
Output is correct |
15 |
Correct |
6 ms |
844 KB |
Output is correct |
16 |
Correct |
4 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
708 KB |
Output is correct |
18 |
Correct |
4 ms |
716 KB |
Output is correct |
19 |
Correct |
1573 ms |
86732 KB |
Output is correct |
20 |
Correct |
1665 ms |
119532 KB |
Output is correct |
21 |
Correct |
1627 ms |
119452 KB |
Output is correct |
22 |
Correct |
1638 ms |
119572 KB |
Output is correct |
23 |
Correct |
1495 ms |
119608 KB |
Output is correct |
24 |
Correct |
106 ms |
8892 KB |
Output is correct |
25 |
Correct |
113 ms |
10560 KB |
Output is correct |
26 |
Correct |
124 ms |
10760 KB |
Output is correct |
27 |
Correct |
98 ms |
10784 KB |
Output is correct |
28 |
Correct |
97 ms |
10816 KB |
Output is correct |
29 |
Correct |
83 ms |
10256 KB |
Output is correct |
30 |
Correct |
81 ms |
10248 KB |
Output is correct |
31 |
Correct |
88 ms |
10324 KB |
Output is correct |
32 |
Correct |
46 ms |
3280 KB |
Output is correct |
33 |
Correct |
90 ms |
10288 KB |
Output is correct |
34 |
Correct |
283 ms |
24012 KB |
Output is correct |
35 |
Correct |
271 ms |
24140 KB |
Output is correct |
36 |
Correct |
220 ms |
23388 KB |
Output is correct |
37 |
Correct |
223 ms |
23376 KB |
Output is correct |
38 |
Correct |
233 ms |
23364 KB |
Output is correct |
39 |
Correct |
189 ms |
23236 KB |
Output is correct |
40 |
Correct |
214 ms |
23248 KB |
Output is correct |
41 |
Correct |
219 ms |
23616 KB |
Output is correct |
42 |
Correct |
207 ms |
23712 KB |
Output is correct |
43 |
Correct |
215 ms |
23624 KB |
Output is correct |
44 |
Correct |
225 ms |
24020 KB |
Output is correct |
45 |
Correct |
245 ms |
24020 KB |
Output is correct |
46 |
Correct |
230 ms |
24004 KB |
Output is correct |
47 |
Correct |
243 ms |
23976 KB |
Output is correct |
48 |
Correct |
223 ms |
24040 KB |
Output is correct |
49 |
Correct |
186 ms |
22760 KB |
Output is correct |
50 |
Correct |
186 ms |
22736 KB |
Output is correct |
51 |
Correct |
179 ms |
22520 KB |
Output is correct |
52 |
Correct |
180 ms |
22604 KB |
Output is correct |
53 |
Correct |
195 ms |
22796 KB |
Output is correct |
54 |
Correct |
207 ms |
22280 KB |
Output is correct |
55 |
Correct |
177 ms |
16880 KB |
Output is correct |
56 |
Correct |
194 ms |
21760 KB |
Output is correct |
57 |
Correct |
1576 ms |
119908 KB |
Output is correct |
58 |
Correct |
1544 ms |
119764 KB |
Output is correct |
59 |
Correct |
1439 ms |
118168 KB |
Output is correct |
60 |
Correct |
1449 ms |
118236 KB |
Output is correct |
61 |
Correct |
1451 ms |
118208 KB |
Output is correct |
62 |
Correct |
1507 ms |
118196 KB |
Output is correct |
63 |
Correct |
989 ms |
115052 KB |
Output is correct |
64 |
Correct |
992 ms |
114924 KB |
Output is correct |
65 |
Correct |
1319 ms |
118036 KB |
Output is correct |
66 |
Correct |
1310 ms |
118080 KB |
Output is correct |
67 |
Correct |
1319 ms |
118084 KB |
Output is correct |
68 |
Correct |
1451 ms |
119700 KB |
Output is correct |
69 |
Correct |
1437 ms |
119712 KB |
Output is correct |
70 |
Correct |
1435 ms |
119536 KB |
Output is correct |
71 |
Correct |
1421 ms |
119496 KB |
Output is correct |
72 |
Correct |
1433 ms |
119492 KB |
Output is correct |
73 |
Correct |
939 ms |
110920 KB |
Output is correct |
74 |
Correct |
978 ms |
111772 KB |
Output is correct |
75 |
Correct |
947 ms |
110888 KB |
Output is correct |
76 |
Correct |
953 ms |
111172 KB |
Output is correct |
77 |
Correct |
990 ms |
110536 KB |
Output is correct |
78 |
Correct |
1252 ms |
111912 KB |
Output is correct |
79 |
Correct |
928 ms |
75000 KB |
Output is correct |
80 |
Correct |
1267 ms |
108932 KB |
Output is correct |