#include <bits/stdc++.h>
#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 2e5;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
template <typename T> void vout(T s){cout << s << endl;exit(0);}
vector<pair<ll, ll> > v;
pair<pair<ll, ll>, ll> b[N];
vector<ll> q;
ll t[4 * N],a[N],n,Q,limit,l,r,x,k,ans[N];
void upd(ll v,ll tl,ll tr,ll pos,ll val)
{
if(tl == tr)
{
t[v] = val + a[tl];
return;
}
ll 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] = max(t[2 * v], t[2 * v + 1]);
}
ll get(ll v,ll tl,ll tr,ll l,ll r)
{
if(l > r) return 0;
if(tl == l && tr == r) return t[v];
ll tm = (tl + tr) / 2;
return max(get(2 * v, tl, tm, l, min(r, tm)), get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
void make(ll l,ll r)
{
for(int i = r; i >= l; i--)
{
ll x = a[i],pos;
while(!v.empty() && x > v.back().fi)
{
pos = v.back().se;
upd(1, 1, n, pos, x);
v.pop_back();
}
v.push_back({x, i});
}
}
bool comp(ll i,ll j)
{
return b[i].fi.fi > b[j].fi.fi;
}
int main()
{
cin>>n>>Q;
for(int i = 1; i <= n; i++) cin>>a[i];
limit = n;
for(int i = 1; i <= Q; i++)
{
cin>>l>>r>>x;
b[i] = {{l, r}, x};
q.push_back(i);
}
sort(all(q), comp);
for(auto i : q)
{
l = b[i].fi.fi;
r = b[i].fi.se;
k = b[i].se;
if(limit >= l)
{
make(l, limit);
limit = l - 1;
}
x = get(1, 1, n, l, r);
ans[i] = (x <= k);
}
for(int i = 1; i <= Q; i++) cout<<ans[i]<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
452 KB |
Output is correct |
11 |
Correct |
17 ms |
632 KB |
Output is correct |
12 |
Correct |
19 ms |
736 KB |
Output is correct |
13 |
Correct |
21 ms |
760 KB |
Output is correct |
14 |
Correct |
30 ms |
892 KB |
Output is correct |
15 |
Correct |
30 ms |
888 KB |
Output is correct |
16 |
Correct |
27 ms |
1016 KB |
Output is correct |
17 |
Correct |
25 ms |
760 KB |
Output is correct |
18 |
Correct |
25 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1134 ms |
43740 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
538 ms |
9492 KB |
Output is correct |
2 |
Correct |
514 ms |
9404 KB |
Output is correct |
3 |
Correct |
513 ms |
9404 KB |
Output is correct |
4 |
Correct |
515 ms |
9276 KB |
Output is correct |
5 |
Correct |
509 ms |
9296 KB |
Output is correct |
6 |
Correct |
490 ms |
8888 KB |
Output is correct |
7 |
Correct |
489 ms |
9008 KB |
Output is correct |
8 |
Correct |
490 ms |
9268 KB |
Output is correct |
9 |
Correct |
410 ms |
5972 KB |
Output is correct |
10 |
Correct |
480 ms |
9064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
452 KB |
Output is correct |
11 |
Correct |
17 ms |
632 KB |
Output is correct |
12 |
Correct |
19 ms |
736 KB |
Output is correct |
13 |
Correct |
21 ms |
760 KB |
Output is correct |
14 |
Correct |
30 ms |
892 KB |
Output is correct |
15 |
Correct |
30 ms |
888 KB |
Output is correct |
16 |
Correct |
27 ms |
1016 KB |
Output is correct |
17 |
Correct |
25 ms |
760 KB |
Output is correct |
18 |
Correct |
25 ms |
856 KB |
Output is correct |
19 |
Runtime error |
586 ms |
23264 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
452 KB |
Output is correct |
11 |
Correct |
17 ms |
632 KB |
Output is correct |
12 |
Correct |
19 ms |
736 KB |
Output is correct |
13 |
Correct |
21 ms |
760 KB |
Output is correct |
14 |
Correct |
30 ms |
892 KB |
Output is correct |
15 |
Correct |
30 ms |
888 KB |
Output is correct |
16 |
Correct |
27 ms |
1016 KB |
Output is correct |
17 |
Correct |
25 ms |
760 KB |
Output is correct |
18 |
Correct |
25 ms |
856 KB |
Output is correct |
19 |
Runtime error |
1134 ms |
43740 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Halted |
0 ms |
0 KB |
- |