Submission #1096624

# Submission time Handle Problem Language Result Execution time Memory
1096624 2024-10-04T22:35:09 Z rayan_bd Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
17 / 100
3000 ms 262144 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 


#define getar(ar,n) for(ll i=0;i<n;++i) cin>>ar[i]
#define show(n) cout<<n<<'\n'
#define all(v) v.begin(), v.end()
#define br cout<<"\n"
#define pb push_back
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ret return
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())

const int mxN = 1e6 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ld EPS = 1e-9;

struct Node{
	vector<ll> vec;
	ll mx=0,bad_mx=0;
};
Node seg[mxN*4];
ll ar[mxN];

Node dummy_node;


ll calc1(ll node){
	ll lft_max=seg[node*2+1].mx;
	ll ans=-lft_max,st=0,en=seg[node*2+2].vec.size()-1;
	while(st<=en){
		ll mid=st+(en-st)/2;
		if(seg[node*2+2].vec[mid]<lft_max){
			st=mid+1;
			ans=seg[node*2+2].vec[mid];
		}else{
			en=mid-1;
		}
	}
	return ans+lft_max;
}

Node left_right_mrg(Node lft,Node rgt){
	ll lft_max=lft.mx;
	ll ans=-lft_max,st=0,en=rgt.vec.size()-1;
	while(st<=en){
		ll mid=st+(en-st)/2;
		if(rgt.vec[mid]<lft_max){
			st=mid+1;
			ans=rgt.vec[mid];
		}else{
			en=mid-1;
		}
	}	
	ans+=lft_max;

	Node curr;
	curr.bad_mx=max({lft.bad_mx,ans,rgt.bad_mx});
	merge(all(lft.vec),all(rgt.vec),back_inserter(curr.vec));
	curr.mx=max(lft.mx,rgt.mx);

	return curr;
}

void build(ll node,ll start,ll end){
	if(start==end){
		seg[node].vec.pb(ar[start]);
		seg[node].mx=ar[start];
		seg[node].bad_mx=0;
		return;
	}
	ll mid=start+(end-start)/2;
	build(node*2+1,start,mid);
	build(node*2+2,mid+1,end);

	merge(all(seg[node*2+1].vec),all(seg[node*2+2].vec),back_inserter(seg[node].vec));
	seg[node].bad_mx=max({seg[node*2+1].bad_mx,seg[node*2+2].bad_mx,calc1(node)});
	seg[node].mx=max(seg[node*2+1].mx,seg[node*2+2].mx);
}

Node qry(ll nd,ll start,ll end,ll l,ll r){
	if(start>r||end<l) return dummy_node;
	if(start>=l&&end<=r) return seg[nd];
	ll mid=start+(end-start)/2;
	Node lft=qry(nd*2+1,start,mid,l,r);
	Node rgt=qry(nd*2+2,mid+1,end,l,r);
	if(lft.mx==-1) return rgt;
	else if(rgt.mx==-1) return lft;
	return left_right_mrg(lft,rgt);
}

void solve(){
	ll n,l,r,w,q;cin>>n>>q;
	for(ll i=0;i<n;++i){
		cin>>ar[i];
	}
	dummy_node.mx=-1;
	build(0,0,n-1);
	while(q--){
		cin>>l>>r>>w;
		cout<<(qry(0,0,n-1,l-1,r-1).bad_mx<=w)<<nl;
	}
}


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 49 ms 158288 KB Output is correct
2 Correct 52 ms 158292 KB Output is correct
3 Correct 58 ms 158300 KB Output is correct
4 Correct 54 ms 158292 KB Output is correct
5 Correct 60 ms 158288 KB Output is correct
6 Correct 52 ms 158544 KB Output is correct
7 Correct 55 ms 158548 KB Output is correct
8 Correct 52 ms 158544 KB Output is correct
9 Correct 52 ms 158544 KB Output is correct
10 Correct 54 ms 158556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 158288 KB Output is correct
2 Correct 52 ms 158292 KB Output is correct
3 Correct 58 ms 158300 KB Output is correct
4 Correct 54 ms 158292 KB Output is correct
5 Correct 60 ms 158288 KB Output is correct
6 Correct 52 ms 158544 KB Output is correct
7 Correct 55 ms 158548 KB Output is correct
8 Correct 52 ms 158544 KB Output is correct
9 Correct 52 ms 158544 KB Output is correct
10 Correct 54 ms 158556 KB Output is correct
11 Correct 84 ms 158756 KB Output is correct
12 Correct 132 ms 159808 KB Output is correct
13 Correct 139 ms 159816 KB Output is correct
14 Correct 189 ms 159892 KB Output is correct
15 Correct 201 ms 159904 KB Output is correct
16 Correct 192 ms 159852 KB Output is correct
17 Correct 77 ms 159316 KB Output is correct
18 Correct 133 ms 159820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 244 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3043 ms 184168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 158288 KB Output is correct
2 Correct 52 ms 158292 KB Output is correct
3 Correct 58 ms 158300 KB Output is correct
4 Correct 54 ms 158292 KB Output is correct
5 Correct 60 ms 158288 KB Output is correct
6 Correct 52 ms 158544 KB Output is correct
7 Correct 55 ms 158548 KB Output is correct
8 Correct 52 ms 158544 KB Output is correct
9 Correct 52 ms 158544 KB Output is correct
10 Correct 54 ms 158556 KB Output is correct
11 Correct 84 ms 158756 KB Output is correct
12 Correct 132 ms 159808 KB Output is correct
13 Correct 139 ms 159816 KB Output is correct
14 Correct 189 ms 159892 KB Output is correct
15 Correct 201 ms 159904 KB Output is correct
16 Correct 192 ms 159852 KB Output is correct
17 Correct 77 ms 159316 KB Output is correct
18 Correct 133 ms 159820 KB Output is correct
19 Execution timed out 3028 ms 212384 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 158288 KB Output is correct
2 Correct 52 ms 158292 KB Output is correct
3 Correct 58 ms 158300 KB Output is correct
4 Correct 54 ms 158292 KB Output is correct
5 Correct 60 ms 158288 KB Output is correct
6 Correct 52 ms 158544 KB Output is correct
7 Correct 55 ms 158548 KB Output is correct
8 Correct 52 ms 158544 KB Output is correct
9 Correct 52 ms 158544 KB Output is correct
10 Correct 54 ms 158556 KB Output is correct
11 Correct 84 ms 158756 KB Output is correct
12 Correct 132 ms 159808 KB Output is correct
13 Correct 139 ms 159816 KB Output is correct
14 Correct 189 ms 159892 KB Output is correct
15 Correct 201 ms 159904 KB Output is correct
16 Correct 192 ms 159852 KB Output is correct
17 Correct 77 ms 159316 KB Output is correct
18 Correct 133 ms 159820 KB Output is correct
19 Runtime error 244 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -