답안 #1096636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096636 2024-10-04T23:09:52 Z rayan_bd Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
2033 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;


#define getar(ar,n) for(int i=0;i<n;++i) cin>>ar[i]
#define show(n) cout<<n<<'\n'
#define aint(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 ld long double
#define sza(x) ((int)x.size())

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

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

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

	seg[node].vec.assign(seg[node*2+1].vec.size()+seg[node*2+2].vec.size(),0);
	merge(aint(seg[node*2+1].vec),aint(seg[node*2+2].vec),seg[node].vec.begin());
	seg[node].mx=max(seg[node*2+1].mx,seg[node*2+2].mx);
	int mxx=0;
	for(int i=start;i<=end;++i){
		if(mxx>ar[i]){
			seg[node].bad_mx=max(seg[node].bad_mx,mxx+ar[i]);
		}else{
			mxx=ar[i];
		}
	}
}

bool qry(int nd,int start,int end,int l,int r,int k){
	if(start>r||end<l) return 1;
	if(start>=l&&end<=r){
		bool f=(max(seg[nd].bad_mx,(mx>seg[nd].vec[0]?mx+*--lower_bound(aint(seg[nd].vec),mx):0))<=k);
		mx=max(mx,seg[nd].mx);
		return f;
	}
	int mid=start+(end-start)/2;
	return ((!qry(nd*2+1,start,mid,l,r,k)||!qry(nd*2+2,mid+1,end,l,r,k))?0:1);
}

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


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}

Compilation message

sortbooks.cpp:20:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   20 | const int INF = 1e18;
      |                 ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 63308 KB Output is correct
2 Correct 27 ms 63320 KB Output is correct
3 Correct 27 ms 63324 KB Output is correct
4 Correct 26 ms 63324 KB Output is correct
5 Correct 26 ms 63280 KB Output is correct
6 Correct 28 ms 63224 KB Output is correct
7 Correct 28 ms 63324 KB Output is correct
8 Correct 27 ms 63320 KB Output is correct
9 Correct 31 ms 63400 KB Output is correct
10 Correct 28 ms 63316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 63308 KB Output is correct
2 Correct 27 ms 63320 KB Output is correct
3 Correct 27 ms 63324 KB Output is correct
4 Correct 26 ms 63324 KB Output is correct
5 Correct 26 ms 63280 KB Output is correct
6 Correct 28 ms 63224 KB Output is correct
7 Correct 28 ms 63324 KB Output is correct
8 Correct 27 ms 63320 KB Output is correct
9 Correct 31 ms 63400 KB Output is correct
10 Correct 28 ms 63316 KB Output is correct
11 Correct 32 ms 63580 KB Output is correct
12 Correct 31 ms 63824 KB Output is correct
13 Correct 32 ms 63836 KB Output is correct
14 Correct 33 ms 63824 KB Output is correct
15 Correct 31 ms 64008 KB Output is correct
16 Correct 32 ms 63824 KB Output is correct
17 Correct 32 ms 63736 KB Output is correct
18 Correct 29 ms 63836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2033 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 77140 KB Output is correct
2 Correct 96 ms 77164 KB Output is correct
3 Correct 106 ms 77008 KB Output is correct
4 Correct 102 ms 77140 KB Output is correct
5 Correct 102 ms 77056 KB Output is correct
6 Correct 75 ms 76880 KB Output is correct
7 Correct 74 ms 76884 KB Output is correct
8 Correct 82 ms 77148 KB Output is correct
9 Correct 48 ms 64848 KB Output is correct
10 Correct 80 ms 77124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 63308 KB Output is correct
2 Correct 27 ms 63320 KB Output is correct
3 Correct 27 ms 63324 KB Output is correct
4 Correct 26 ms 63324 KB Output is correct
5 Correct 26 ms 63280 KB Output is correct
6 Correct 28 ms 63224 KB Output is correct
7 Correct 28 ms 63324 KB Output is correct
8 Correct 27 ms 63320 KB Output is correct
9 Correct 31 ms 63400 KB Output is correct
10 Correct 28 ms 63316 KB Output is correct
11 Correct 32 ms 63580 KB Output is correct
12 Correct 31 ms 63824 KB Output is correct
13 Correct 32 ms 63836 KB Output is correct
14 Correct 33 ms 63824 KB Output is correct
15 Correct 31 ms 64008 KB Output is correct
16 Correct 32 ms 63824 KB Output is correct
17 Correct 32 ms 63736 KB Output is correct
18 Correct 29 ms 63836 KB Output is correct
19 Correct 222 ms 94032 KB Output is correct
20 Correct 216 ms 93864 KB Output is correct
21 Correct 206 ms 93524 KB Output is correct
22 Correct 207 ms 93520 KB Output is correct
23 Correct 208 ms 93720 KB Output is correct
24 Correct 194 ms 93508 KB Output is correct
25 Correct 174 ms 93524 KB Output is correct
26 Correct 224 ms 93704 KB Output is correct
27 Correct 223 ms 94036 KB Output is correct
28 Correct 229 ms 93780 KB Output is correct
29 Correct 234 ms 93892 KB Output is correct
30 Correct 239 ms 93692 KB Output is correct
31 Correct 233 ms 93652 KB Output is correct
32 Correct 243 ms 93776 KB Output is correct
33 Correct 233 ms 93780 KB Output is correct
34 Correct 153 ms 93416 KB Output is correct
35 Correct 162 ms 93460 KB Output is correct
36 Correct 159 ms 93264 KB Output is correct
37 Correct 155 ms 93268 KB Output is correct
38 Correct 176 ms 93264 KB Output is correct
39 Correct 184 ms 92496 KB Output is correct
40 Correct 149 ms 83380 KB Output is correct
41 Correct 171 ms 91984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 63308 KB Output is correct
2 Correct 27 ms 63320 KB Output is correct
3 Correct 27 ms 63324 KB Output is correct
4 Correct 26 ms 63324 KB Output is correct
5 Correct 26 ms 63280 KB Output is correct
6 Correct 28 ms 63224 KB Output is correct
7 Correct 28 ms 63324 KB Output is correct
8 Correct 27 ms 63320 KB Output is correct
9 Correct 31 ms 63400 KB Output is correct
10 Correct 28 ms 63316 KB Output is correct
11 Correct 32 ms 63580 KB Output is correct
12 Correct 31 ms 63824 KB Output is correct
13 Correct 32 ms 63836 KB Output is correct
14 Correct 33 ms 63824 KB Output is correct
15 Correct 31 ms 64008 KB Output is correct
16 Correct 32 ms 63824 KB Output is correct
17 Correct 32 ms 63736 KB Output is correct
18 Correct 29 ms 63836 KB Output is correct
19 Runtime error 2033 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -