// __builtin_popcount(x)
// __builtin_popcountll(x)
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 1000005
ll n,q;
ll a[maxn];
set<ll> t[4*maxn];
ll mood;
bool moe = 1;
void init(ll v,ll tl,ll tr){
if(tl==tr){
t[v].insert(a[tl]);
return;
}
ll mid = (tl+tr)/2;
init(2*v,tl,mid);
init(2*v+1,mid+1,tr);
for(ll i = tl;i<=tr;i++) t[v].insert(a[i]);
}
set<ll> get(ll v,ll tl,ll tr,ll l,ll r){
if(l>r) return {};
if(tl==l&&tr==r) return t[v];
ll mid = (tl+tr)/2;
set<ll> lf = get(2*v,tl,mid,l,min(mid,r));
set<ll> rf = get(2*v+1,mid+1,tr,max(mid+1,l),r);
if(sz(lf)==0) return rf;
if(sz(rf)==0) return lf;
auto it = lf.end();
it--;
ll x = *it;
it = rf.lower_bound(x);
if(it==rf.begin()){
for(ll x : lf) rf.insert(x);
return rf;
}
it--;
if(x+*it>mood){
moe = 0;
return {};
}
for(ll x : lf) rf.insert(x);
return rf;
}
int main(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
cin >> n >> q;
for(ll i = 1;i<=n;i++) cin >> a[i];
init(1,1,n);
while(q--){
ll l,r; cin >> l >> r >> mood;
moe = 1;
get(1,1,n,l,r);
cout<<moe<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
188108 KB |
Output is correct |
2 |
Correct |
92 ms |
188280 KB |
Output is correct |
3 |
Incorrect |
101 ms |
188144 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
188108 KB |
Output is correct |
2 |
Correct |
92 ms |
188280 KB |
Output is correct |
3 |
Incorrect |
101 ms |
188144 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
324 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3073 ms |
242432 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
188108 KB |
Output is correct |
2 |
Correct |
92 ms |
188280 KB |
Output is correct |
3 |
Incorrect |
101 ms |
188144 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
188108 KB |
Output is correct |
2 |
Correct |
92 ms |
188280 KB |
Output is correct |
3 |
Incorrect |
101 ms |
188144 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |