답안 #1096645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096645 2024-10-04T23:21:58 Z rayan_bd Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
1151 ms 262300 KB
#include <bits/stdc++.h>
 
using namespace std;
 
 #pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
 
#define getar(ar,n) for(int 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 ld long double
#define sza(x) ((int)x.size())
 
struct Node{
	vector<int> vec;
	int mx=0,bad_mx=0;
};
vector<int> ar;
vector<Node> seg;
int mx=0;
 
void build(int node,int start,int end){
	if(start==end){
		seg[node].vec={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(all(seg[node*2+1].vec),all(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(all(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;
	ar.resize(n+1);
	for(int i=0;i<n;++i){
		cin>>ar[i];
	}
	seg.resize(n<<2);
	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:26:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
   26 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
sortbooks.cpp:33:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
   33 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
sortbooks.cpp:35:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
   35 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
sortbooks.cpp:49:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
   49 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
sortbooks.cpp:73:38: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   73 | void build(int node,int start,int end){
      |                                      ^
sortbooks.cpp:73:38: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
sortbooks.cpp:73:38: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
sortbooks.cpp:73:38: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
sortbooks.cpp:97:52: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   97 | bool qry(int nd,int start,int end,int l,int r,int k){
      |                                                    ^
sortbooks.cpp:97:52: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
sortbooks.cpp:97:52: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
sortbooks.cpp:97:52: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
sortbooks.cpp:108:12: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  108 | void solve(){
      |            ^
sortbooks.cpp:108:12: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
sortbooks.cpp:108:12: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
sortbooks.cpp:108:12: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
sortbooks.cpp:124:13: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  124 | signed main() {
      |             ^
sortbooks.cpp:124:13: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
sortbooks.cpp:124:13: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
sortbooks.cpp:124:13: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 3 ms 1628 KB Output is correct
13 Correct 3 ms 1632 KB Output is correct
14 Correct 4 ms 1756 KB Output is correct
15 Correct 4 ms 1628 KB Output is correct
16 Correct 4 ms 1628 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 3 ms 1624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1078 ms 262144 KB Output is correct
2 Correct 1004 ms 262144 KB Output is correct
3 Correct 991 ms 262144 KB Output is correct
4 Runtime error 1151 ms 262300 KB Memory limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 26832 KB Output is correct
2 Correct 74 ms 26960 KB Output is correct
3 Correct 93 ms 26924 KB Output is correct
4 Correct 81 ms 26960 KB Output is correct
5 Correct 80 ms 26960 KB Output is correct
6 Correct 53 ms 26704 KB Output is correct
7 Correct 51 ms 26704 KB Output is correct
8 Correct 75 ms 26556 KB Output is correct
9 Correct 24 ms 2024 KB Output is correct
10 Correct 58 ms 26712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 3 ms 1628 KB Output is correct
13 Correct 3 ms 1632 KB Output is correct
14 Correct 4 ms 1756 KB Output is correct
15 Correct 4 ms 1628 KB Output is correct
16 Correct 4 ms 1628 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 3 ms 1624 KB Output is correct
19 Correct 200 ms 56912 KB Output is correct
20 Correct 215 ms 56888 KB Output is correct
21 Correct 168 ms 56828 KB Output is correct
22 Correct 178 ms 56660 KB Output is correct
23 Correct 185 ms 56780 KB Output is correct
24 Correct 164 ms 56656 KB Output is correct
25 Correct 152 ms 56656 KB Output is correct
26 Correct 199 ms 56840 KB Output is correct
27 Correct 188 ms 56900 KB Output is correct
28 Correct 209 ms 56912 KB Output is correct
29 Correct 214 ms 57020 KB Output is correct
30 Correct 219 ms 56832 KB Output is correct
31 Correct 201 ms 56912 KB Output is correct
32 Correct 205 ms 56860 KB Output is correct
33 Correct 204 ms 56912 KB Output is correct
34 Correct 136 ms 56460 KB Output is correct
35 Correct 139 ms 56488 KB Output is correct
36 Correct 131 ms 56296 KB Output is correct
37 Correct 136 ms 56400 KB Output is correct
38 Correct 158 ms 56600 KB Output is correct
39 Correct 168 ms 55384 KB Output is correct
40 Correct 125 ms 37496 KB Output is correct
41 Correct 139 ms 55000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 3 ms 1628 KB Output is correct
13 Correct 3 ms 1632 KB Output is correct
14 Correct 4 ms 1756 KB Output is correct
15 Correct 4 ms 1628 KB Output is correct
16 Correct 4 ms 1628 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 3 ms 1624 KB Output is correct
19 Correct 1078 ms 262144 KB Output is correct
20 Correct 1004 ms 262144 KB Output is correct
21 Correct 991 ms 262144 KB Output is correct
22 Runtime error 1151 ms 262300 KB Memory limit exceeded
23 Halted 0 ms 0 KB -