#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define ll int
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) (x)*(x)
#define PB push_back
using namespace std;
typedef long double ld;
const ll N = 1123456;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
//vector<pair<ll, ll> > v;
vector<ll> of[N],q[N],pisos
;
pair<ll, ll> b[N];
ll ans[N],t[4 * N],a[N],l,r,x,k,limit,n,Q;
void upd(ll v,ll tl,ll tr,ll pos,ll val)
{
if(tl == tr)
{
t[v] = max(t[v], val);
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));
}
int main()
{
ios_base::sync_with_stdio();
cin.tie(0);
cout.tie(0);
cin>>n>>Q;
for(int i = 1; i <= n; i++) cin>>a[i];
vector<pair<ll, ll> > v1;
v1.PB({1e9, 0ll});
for(int i = 1; i <= n; i++)
{
ll x = a[i];
while(x >= v1.back().fi) v1.pop_back();
of[v1.back().se].PB(i);
// cout<<i<<" - "<<v1.back().se<<endl;
v1.PB({x, i});
}
for(int i = 1; i <= Q; i++)
{
cin>>l>>r>>k;
b[i] = {r, k};
q[l].PB(i);
pisos.PB(l);
}
limit = n;
sort(all(pisos));
pisos.erase(unique(all(pisos)), pisos.end());
reverse(all(pisos));
for(auto l : pisos)
{
while(limit >= l)
{
for(auto j : of[limit]) upd(1, 1, n, j, a[j] + a[limit]);
of[limit].clear();
limit--;
}
for(auto i : q[l])
{
r = b[i].fi;
x = get(1, 1, n, l, r);
// cout<<l<<" "<<r<<" = "<<x<<endl;
ans[i] = (x <= b[i].se);
}
}
for(int i = 1; i <= Q; i++)
cout<<ans[i]<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
53112 KB |
Output is correct |
2 |
Correct |
49 ms |
53112 KB |
Output is correct |
3 |
Correct |
51 ms |
53112 KB |
Output is correct |
4 |
Correct |
51 ms |
53064 KB |
Output is correct |
5 |
Correct |
49 ms |
53112 KB |
Output is correct |
6 |
Correct |
53 ms |
53164 KB |
Output is correct |
7 |
Correct |
52 ms |
53112 KB |
Output is correct |
8 |
Correct |
51 ms |
53112 KB |
Output is correct |
9 |
Correct |
51 ms |
53240 KB |
Output is correct |
10 |
Correct |
51 ms |
53144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
53112 KB |
Output is correct |
2 |
Correct |
49 ms |
53112 KB |
Output is correct |
3 |
Correct |
51 ms |
53112 KB |
Output is correct |
4 |
Correct |
51 ms |
53064 KB |
Output is correct |
5 |
Correct |
49 ms |
53112 KB |
Output is correct |
6 |
Correct |
53 ms |
53164 KB |
Output is correct |
7 |
Correct |
52 ms |
53112 KB |
Output is correct |
8 |
Correct |
51 ms |
53112 KB |
Output is correct |
9 |
Correct |
51 ms |
53240 KB |
Output is correct |
10 |
Correct |
51 ms |
53144 KB |
Output is correct |
11 |
Correct |
63 ms |
53180 KB |
Output is correct |
12 |
Correct |
66 ms |
53412 KB |
Output is correct |
13 |
Correct |
68 ms |
53372 KB |
Output is correct |
14 |
Correct |
78 ms |
53496 KB |
Output is correct |
15 |
Correct |
78 ms |
53532 KB |
Output is correct |
16 |
Correct |
73 ms |
53368 KB |
Output is correct |
17 |
Correct |
73 ms |
53308 KB |
Output is correct |
18 |
Correct |
71 ms |
53368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3019 ms |
109876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
582 ms |
60040 KB |
Output is correct |
2 |
Correct |
556 ms |
59108 KB |
Output is correct |
3 |
Correct |
548 ms |
57360 KB |
Output is correct |
4 |
Correct |
554 ms |
57528 KB |
Output is correct |
5 |
Correct |
570 ms |
57772 KB |
Output is correct |
6 |
Correct |
510 ms |
56688 KB |
Output is correct |
7 |
Correct |
507 ms |
56708 KB |
Output is correct |
8 |
Correct |
540 ms |
57836 KB |
Output is correct |
9 |
Correct |
468 ms |
55440 KB |
Output is correct |
10 |
Correct |
521 ms |
57884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
53112 KB |
Output is correct |
2 |
Correct |
49 ms |
53112 KB |
Output is correct |
3 |
Correct |
51 ms |
53112 KB |
Output is correct |
4 |
Correct |
51 ms |
53064 KB |
Output is correct |
5 |
Correct |
49 ms |
53112 KB |
Output is correct |
6 |
Correct |
53 ms |
53164 KB |
Output is correct |
7 |
Correct |
52 ms |
53112 KB |
Output is correct |
8 |
Correct |
51 ms |
53112 KB |
Output is correct |
9 |
Correct |
51 ms |
53240 KB |
Output is correct |
10 |
Correct |
51 ms |
53144 KB |
Output is correct |
11 |
Correct |
63 ms |
53180 KB |
Output is correct |
12 |
Correct |
66 ms |
53412 KB |
Output is correct |
13 |
Correct |
68 ms |
53372 KB |
Output is correct |
14 |
Correct |
78 ms |
53496 KB |
Output is correct |
15 |
Correct |
78 ms |
53532 KB |
Output is correct |
16 |
Correct |
73 ms |
53368 KB |
Output is correct |
17 |
Correct |
73 ms |
53308 KB |
Output is correct |
18 |
Correct |
71 ms |
53368 KB |
Output is correct |
19 |
Correct |
1288 ms |
66836 KB |
Output is correct |
20 |
Correct |
1285 ms |
66860 KB |
Output is correct |
21 |
Correct |
1225 ms |
64616 KB |
Output is correct |
22 |
Correct |
1215 ms |
64660 KB |
Output is correct |
23 |
Correct |
1222 ms |
64380 KB |
Output is correct |
24 |
Runtime error |
260 ms |
110692 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
53112 KB |
Output is correct |
2 |
Correct |
49 ms |
53112 KB |
Output is correct |
3 |
Correct |
51 ms |
53112 KB |
Output is correct |
4 |
Correct |
51 ms |
53064 KB |
Output is correct |
5 |
Correct |
49 ms |
53112 KB |
Output is correct |
6 |
Correct |
53 ms |
53164 KB |
Output is correct |
7 |
Correct |
52 ms |
53112 KB |
Output is correct |
8 |
Correct |
51 ms |
53112 KB |
Output is correct |
9 |
Correct |
51 ms |
53240 KB |
Output is correct |
10 |
Correct |
51 ms |
53144 KB |
Output is correct |
11 |
Correct |
63 ms |
53180 KB |
Output is correct |
12 |
Correct |
66 ms |
53412 KB |
Output is correct |
13 |
Correct |
68 ms |
53372 KB |
Output is correct |
14 |
Correct |
78 ms |
53496 KB |
Output is correct |
15 |
Correct |
78 ms |
53532 KB |
Output is correct |
16 |
Correct |
73 ms |
53368 KB |
Output is correct |
17 |
Correct |
73 ms |
53308 KB |
Output is correct |
18 |
Correct |
71 ms |
53368 KB |
Output is correct |
19 |
Execution timed out |
3019 ms |
109876 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |