답안 #959869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959869 2024-04-09T08:58:44 Z pcc Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1464 ms 180144 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
#define int ll

const int mxn = 1e6+10;

struct SEG{
#define mid ((l+r)>>1)
#define ls now*2+1
#define rs now*2+2
	pll seg[mxn*4];
	SEG(){
		for(auto &i:seg)i.fs = i.sc = 0;
	}
	void modify(int now,int l,int r,int s,int e,int v){
		if(l>=s&e>=r){
			seg[now].sc += v;
			return;
		}
		if(mid>=s)modify(ls,l,mid,s,e,v);
		if(mid<e)modify(rs,mid+1,r,s,e,v);
		seg[now].fs = max(seg[ls].fs+seg[ls].sc,seg[rs].fs+seg[rs].sc);
		return;
	}
	ll getval(int now,int l,int r,int s,int e){
		if(l>=s&&e>=r)return seg[now].fs+seg[now].sc;
		if(mid>=e)return getval(ls,l,mid,s,e)+seg[now].sc;
		else if(mid<s)return getval(rs,mid+1,r,s,e)+seg[now].sc;
		else return max(getval(ls,l,mid,s,e),getval(rs,mid+1,r,s,e))+seg[now].sc;
	}
};

const ll inf = 2e9+10;
SEG seg;
vector<int> st;
int arr[mxn];
vector<pii> ask[mxn];
int N,Q;
int need[mxn],ans[mxn];

main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>Q;
	for(int i = 1;i<=N;i++)cin>>arr[i];
	for(int i = 1;i<=Q;i++){
		int l,r;
		cin>>r>>l;
		cin>>need[i];
		l = N+1-l,r = N+1-r;
		ask[r].push_back(pii(l,i));
	}
	seg.modify(0,1,N,0,N,-inf);
	reverse(arr+1,arr+N+1);
	arr[0] = 1e9+10;
	st.push_back(0);
	for(int i = 1;i<=N;i++){
		while(arr[st.back()]<arr[i]){
			if(st.end()[-2]+1 != st.back())seg.modify(0,1,N,st.end()[-2]+1,st.end()[-1]-1,-arr[st.back()]);
			seg.modify(0,1,N,st.back(),st.back(),inf+arr[st.back()]);
			st.pop_back();
		}
		if(st.back()+1 != i)seg.modify(0,1,N,st.back()+1,i-1,arr[i]);
		st.push_back(i);
		for(auto &j:ask[i])ans[j.sc] = seg.getval(0,1,N,j.fs,i);
	}
	for(int i = 1;i<=Q;i++)cout<<(ans[i]<=need[i])<<'\n';
	return 0;
}

Compilation message

sortbooks.cpp: In member function 'void SEG::modify(long long int, long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:23:7: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   23 |   if(l>=s&e>=r){
      |      ~^~~
sortbooks.cpp: At global scope:
sortbooks.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 91224 KB Output is correct
2 Correct 19 ms 91224 KB Output is correct
3 Correct 20 ms 91372 KB Output is correct
4 Correct 19 ms 91224 KB Output is correct
5 Correct 20 ms 91228 KB Output is correct
6 Correct 22 ms 91228 KB Output is correct
7 Correct 20 ms 91228 KB Output is correct
8 Correct 22 ms 91384 KB Output is correct
9 Correct 21 ms 91224 KB Output is correct
10 Correct 20 ms 91228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 91224 KB Output is correct
2 Correct 19 ms 91224 KB Output is correct
3 Correct 20 ms 91372 KB Output is correct
4 Correct 19 ms 91224 KB Output is correct
5 Correct 20 ms 91228 KB Output is correct
6 Correct 22 ms 91228 KB Output is correct
7 Correct 20 ms 91228 KB Output is correct
8 Correct 22 ms 91384 KB Output is correct
9 Correct 21 ms 91224 KB Output is correct
10 Correct 20 ms 91228 KB Output is correct
11 Correct 21 ms 91484 KB Output is correct
12 Correct 24 ms 93532 KB Output is correct
13 Correct 22 ms 93528 KB Output is correct
14 Correct 24 ms 94044 KB Output is correct
15 Correct 25 ms 93784 KB Output is correct
16 Correct 23 ms 93776 KB Output is correct
17 Correct 23 ms 93648 KB Output is correct
18 Correct 23 ms 93740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1311 ms 138168 KB Output is correct
2 Correct 1438 ms 170736 KB Output is correct
3 Correct 1464 ms 170508 KB Output is correct
4 Correct 1442 ms 171128 KB Output is correct
5 Correct 1183 ms 178868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 100372 KB Output is correct
2 Correct 99 ms 100524 KB Output is correct
3 Correct 88 ms 101384 KB Output is correct
4 Correct 84 ms 101332 KB Output is correct
5 Correct 78 ms 101440 KB Output is correct
6 Correct 91 ms 101004 KB Output is correct
7 Correct 66 ms 100820 KB Output is correct
8 Correct 78 ms 101004 KB Output is correct
9 Correct 47 ms 97696 KB Output is correct
10 Correct 76 ms 101060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 91224 KB Output is correct
2 Correct 19 ms 91224 KB Output is correct
3 Correct 20 ms 91372 KB Output is correct
4 Correct 19 ms 91224 KB Output is correct
5 Correct 20 ms 91228 KB Output is correct
6 Correct 22 ms 91228 KB Output is correct
7 Correct 20 ms 91228 KB Output is correct
8 Correct 22 ms 91384 KB Output is correct
9 Correct 21 ms 91224 KB Output is correct
10 Correct 20 ms 91228 KB Output is correct
11 Correct 21 ms 91484 KB Output is correct
12 Correct 24 ms 93532 KB Output is correct
13 Correct 22 ms 93528 KB Output is correct
14 Correct 24 ms 94044 KB Output is correct
15 Correct 25 ms 93784 KB Output is correct
16 Correct 23 ms 93776 KB Output is correct
17 Correct 23 ms 93648 KB Output is correct
18 Correct 23 ms 93740 KB Output is correct
19 Correct 209 ms 109904 KB Output is correct
20 Correct 207 ms 109904 KB Output is correct
21 Correct 182 ms 109512 KB Output is correct
22 Correct 188 ms 109744 KB Output is correct
23 Correct 183 ms 109648 KB Output is correct
24 Correct 127 ms 111292 KB Output is correct
25 Correct 133 ms 111212 KB Output is correct
26 Correct 156 ms 111560 KB Output is correct
27 Correct 151 ms 111520 KB Output is correct
28 Correct 152 ms 111608 KB Output is correct
29 Correct 165 ms 111808 KB Output is correct
30 Correct 218 ms 111688 KB Output is correct
31 Correct 199 ms 111664 KB Output is correct
32 Correct 174 ms 111816 KB Output is correct
33 Correct 173 ms 111596 KB Output is correct
34 Correct 129 ms 110588 KB Output is correct
35 Correct 117 ms 110272 KB Output is correct
36 Correct 115 ms 110268 KB Output is correct
37 Correct 116 ms 110060 KB Output is correct
38 Correct 121 ms 110280 KB Output is correct
39 Correct 160 ms 109684 KB Output is correct
40 Correct 116 ms 108524 KB Output is correct
41 Correct 156 ms 109260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 91224 KB Output is correct
2 Correct 19 ms 91224 KB Output is correct
3 Correct 20 ms 91372 KB Output is correct
4 Correct 19 ms 91224 KB Output is correct
5 Correct 20 ms 91228 KB Output is correct
6 Correct 22 ms 91228 KB Output is correct
7 Correct 20 ms 91228 KB Output is correct
8 Correct 22 ms 91384 KB Output is correct
9 Correct 21 ms 91224 KB Output is correct
10 Correct 20 ms 91228 KB Output is correct
11 Correct 21 ms 91484 KB Output is correct
12 Correct 24 ms 93532 KB Output is correct
13 Correct 22 ms 93528 KB Output is correct
14 Correct 24 ms 94044 KB Output is correct
15 Correct 25 ms 93784 KB Output is correct
16 Correct 23 ms 93776 KB Output is correct
17 Correct 23 ms 93648 KB Output is correct
18 Correct 23 ms 93740 KB Output is correct
19 Correct 1311 ms 138168 KB Output is correct
20 Correct 1438 ms 170736 KB Output is correct
21 Correct 1464 ms 170508 KB Output is correct
22 Correct 1442 ms 171128 KB Output is correct
23 Correct 1183 ms 178868 KB Output is correct
24 Correct 123 ms 100372 KB Output is correct
25 Correct 99 ms 100524 KB Output is correct
26 Correct 88 ms 101384 KB Output is correct
27 Correct 84 ms 101332 KB Output is correct
28 Correct 78 ms 101440 KB Output is correct
29 Correct 91 ms 101004 KB Output is correct
30 Correct 66 ms 100820 KB Output is correct
31 Correct 78 ms 101004 KB Output is correct
32 Correct 47 ms 97696 KB Output is correct
33 Correct 76 ms 101060 KB Output is correct
34 Correct 209 ms 109904 KB Output is correct
35 Correct 207 ms 109904 KB Output is correct
36 Correct 182 ms 109512 KB Output is correct
37 Correct 188 ms 109744 KB Output is correct
38 Correct 183 ms 109648 KB Output is correct
39 Correct 127 ms 111292 KB Output is correct
40 Correct 133 ms 111212 KB Output is correct
41 Correct 156 ms 111560 KB Output is correct
42 Correct 151 ms 111520 KB Output is correct
43 Correct 152 ms 111608 KB Output is correct
44 Correct 165 ms 111808 KB Output is correct
45 Correct 218 ms 111688 KB Output is correct
46 Correct 199 ms 111664 KB Output is correct
47 Correct 174 ms 111816 KB Output is correct
48 Correct 173 ms 111596 KB Output is correct
49 Correct 129 ms 110588 KB Output is correct
50 Correct 117 ms 110272 KB Output is correct
51 Correct 115 ms 110268 KB Output is correct
52 Correct 116 ms 110060 KB Output is correct
53 Correct 121 ms 110280 KB Output is correct
54 Correct 160 ms 109684 KB Output is correct
55 Correct 116 ms 108524 KB Output is correct
56 Correct 156 ms 109260 KB Output is correct
57 Correct 1313 ms 172112 KB Output is correct
58 Correct 1373 ms 171972 KB Output is correct
59 Correct 1218 ms 171424 KB Output is correct
60 Correct 1241 ms 171524 KB Output is correct
61 Correct 1213 ms 171412 KB Output is correct
62 Correct 1239 ms 171408 KB Output is correct
63 Correct 590 ms 173756 KB Output is correct
64 Correct 569 ms 174256 KB Output is correct
65 Correct 950 ms 179400 KB Output is correct
66 Correct 955 ms 179556 KB Output is correct
67 Correct 1014 ms 179876 KB Output is correct
68 Correct 1140 ms 180116 KB Output is correct
69 Correct 1105 ms 180144 KB Output is correct
70 Correct 1050 ms 179892 KB Output is correct
71 Correct 1103 ms 180024 KB Output is correct
72 Correct 1079 ms 180056 KB Output is correct
73 Correct 623 ms 170932 KB Output is correct
74 Correct 529 ms 171784 KB Output is correct
75 Correct 559 ms 170840 KB Output is correct
76 Correct 539 ms 171044 KB Output is correct
77 Correct 537 ms 171184 KB Output is correct
78 Correct 1002 ms 168272 KB Output is correct
79 Correct 668 ms 160788 KB Output is correct
80 Correct 941 ms 168492 KB Output is correct