답안 #381991

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381991 2021-03-26T08:42:13 Z dorijanlendvaj Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2025 ms 83492 KB
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
using ll=long long;
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vl vector<ll>
#define all(a) begin(a),end(a)

using namespace std;

const int N=1000010,MOD=1e9+7,M=1<<20;
const char en='\n';
const ll LLINF=1ll<<60;

int n,q,h[N],ans[N],seg[M*2+10];

void upd(int i,int x)
{
	seg[i+=M]=x;
	for (i/=2;i;i/=2) seg[i]=max(seg[i*2],seg[i*2+1]);
}

int ge(int l,int r,int lo=0,int hi=M,int i=1)
{
	if (lo>=l && hi<=r) return seg[i];
	if (lo>=r || hi<=l) return -1;
	int mid=(lo+hi)/2;
	return max(ge(l,r,lo,mid,i*2),ge(l,r,mid,hi,i*2+1));
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	vector<pair<pii,pii>> v;
	vector<pii> st;
	st.eb(MOD,-1);
	memset(seg,-1,sizeof(seg));
	cin>>n>>q;
	for (int i=0;i<n;++i)
	{
		cin>>h[i];
		while (st.back().x<=h[i]) st.pop_back();
		if (st.back().y!=-1)
		{
			v.pb({{st.back().x+h[i],-1},{st.back().y,i}});
		}
		st.eb(h[i],i);
	}
	for (int i=0;i<q;++i)
	{
		int l,r,k;
		cin>>l>>r>>k;
		--l;
		v.pb({{k,i},{l,r}});
	}
	sort(all(v));
	reverse(all(v));
	for (auto a: v)
	{
		//cout<<a.x.x<<' '<<a.x.y<<' '<<a.y.x<<' '<<a.y.y<<en;
		if (a.x.y==-1) upd(a.y.y,a.y.x);
		else ans[a.x.y]=(ge(a.y.x,a.y.y)<a.y.x);
	}
	for (int i=0;i<q;++i) cout<<ans[i]<<en;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8556 KB Output is correct
2 Correct 5 ms 8556 KB Output is correct
3 Correct 5 ms 8556 KB Output is correct
4 Correct 5 ms 8556 KB Output is correct
5 Correct 5 ms 8556 KB Output is correct
6 Correct 6 ms 8556 KB Output is correct
7 Correct 5 ms 8556 KB Output is correct
8 Correct 5 ms 8556 KB Output is correct
9 Correct 5 ms 8556 KB Output is correct
10 Correct 5 ms 8556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8556 KB Output is correct
2 Correct 5 ms 8556 KB Output is correct
3 Correct 5 ms 8556 KB Output is correct
4 Correct 5 ms 8556 KB Output is correct
5 Correct 5 ms 8556 KB Output is correct
6 Correct 6 ms 8556 KB Output is correct
7 Correct 5 ms 8556 KB Output is correct
8 Correct 5 ms 8556 KB Output is correct
9 Correct 5 ms 8556 KB Output is correct
10 Correct 5 ms 8556 KB Output is correct
11 Correct 8 ms 8812 KB Output is correct
12 Correct 9 ms 8940 KB Output is correct
13 Correct 9 ms 8940 KB Output is correct
14 Correct 11 ms 9072 KB Output is correct
15 Correct 12 ms 9200 KB Output is correct
16 Correct 10 ms 8940 KB Output is correct
17 Correct 9 ms 8940 KB Output is correct
18 Correct 10 ms 9068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1885 ms 62292 KB Output is correct
2 Correct 1953 ms 82752 KB Output is correct
3 Correct 2009 ms 82716 KB Output is correct
4 Correct 2025 ms 82748 KB Output is correct
5 Correct 1597 ms 67120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 14812 KB Output is correct
2 Correct 143 ms 14812 KB Output is correct
3 Correct 114 ms 13284 KB Output is correct
4 Correct 115 ms 13284 KB Output is correct
5 Correct 112 ms 13284 KB Output is correct
6 Correct 102 ms 13284 KB Output is correct
7 Correct 105 ms 13284 KB Output is correct
8 Correct 113 ms 14436 KB Output is correct
9 Correct 69 ms 12260 KB Output is correct
10 Correct 111 ms 14692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8556 KB Output is correct
2 Correct 5 ms 8556 KB Output is correct
3 Correct 5 ms 8556 KB Output is correct
4 Correct 5 ms 8556 KB Output is correct
5 Correct 5 ms 8556 KB Output is correct
6 Correct 6 ms 8556 KB Output is correct
7 Correct 5 ms 8556 KB Output is correct
8 Correct 5 ms 8556 KB Output is correct
9 Correct 5 ms 8556 KB Output is correct
10 Correct 5 ms 8556 KB Output is correct
11 Correct 8 ms 8812 KB Output is correct
12 Correct 9 ms 8940 KB Output is correct
13 Correct 9 ms 8940 KB Output is correct
14 Correct 11 ms 9072 KB Output is correct
15 Correct 12 ms 9200 KB Output is correct
16 Correct 10 ms 8940 KB Output is correct
17 Correct 9 ms 8940 KB Output is correct
18 Correct 10 ms 9068 KB Output is correct
19 Correct 296 ms 23624 KB Output is correct
20 Correct 289 ms 23632 KB Output is correct
21 Correct 291 ms 23380 KB Output is correct
22 Correct 298 ms 23376 KB Output is correct
23 Correct 287 ms 23388 KB Output is correct
24 Correct 237 ms 20188 KB Output is correct
25 Correct 244 ms 20172 KB Output is correct
26 Correct 248 ms 20316 KB Output is correct
27 Correct 252 ms 20316 KB Output is correct
28 Correct 248 ms 20316 KB Output is correct
29 Correct 256 ms 20444 KB Output is correct
30 Correct 251 ms 20444 KB Output is correct
31 Correct 255 ms 20620 KB Output is correct
32 Correct 257 ms 20676 KB Output is correct
33 Correct 245 ms 20444 KB Output is correct
34 Correct 221 ms 20188 KB Output is correct
35 Correct 225 ms 20060 KB Output is correct
36 Correct 212 ms 19804 KB Output is correct
37 Correct 218 ms 19804 KB Output is correct
38 Correct 229 ms 20000 KB Output is correct
39 Correct 241 ms 22876 KB Output is correct
40 Correct 175 ms 18524 KB Output is correct
41 Correct 229 ms 21468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8556 KB Output is correct
2 Correct 5 ms 8556 KB Output is correct
3 Correct 5 ms 8556 KB Output is correct
4 Correct 5 ms 8556 KB Output is correct
5 Correct 5 ms 8556 KB Output is correct
6 Correct 6 ms 8556 KB Output is correct
7 Correct 5 ms 8556 KB Output is correct
8 Correct 5 ms 8556 KB Output is correct
9 Correct 5 ms 8556 KB Output is correct
10 Correct 5 ms 8556 KB Output is correct
11 Correct 8 ms 8812 KB Output is correct
12 Correct 9 ms 8940 KB Output is correct
13 Correct 9 ms 8940 KB Output is correct
14 Correct 11 ms 9072 KB Output is correct
15 Correct 12 ms 9200 KB Output is correct
16 Correct 10 ms 8940 KB Output is correct
17 Correct 9 ms 8940 KB Output is correct
18 Correct 10 ms 9068 KB Output is correct
19 Correct 1885 ms 62292 KB Output is correct
20 Correct 1953 ms 82752 KB Output is correct
21 Correct 2009 ms 82716 KB Output is correct
22 Correct 2025 ms 82748 KB Output is correct
23 Correct 1597 ms 67120 KB Output is correct
24 Correct 138 ms 14812 KB Output is correct
25 Correct 143 ms 14812 KB Output is correct
26 Correct 114 ms 13284 KB Output is correct
27 Correct 115 ms 13284 KB Output is correct
28 Correct 112 ms 13284 KB Output is correct
29 Correct 102 ms 13284 KB Output is correct
30 Correct 105 ms 13284 KB Output is correct
31 Correct 113 ms 14436 KB Output is correct
32 Correct 69 ms 12260 KB Output is correct
33 Correct 111 ms 14692 KB Output is correct
34 Correct 296 ms 23624 KB Output is correct
35 Correct 289 ms 23632 KB Output is correct
36 Correct 291 ms 23380 KB Output is correct
37 Correct 298 ms 23376 KB Output is correct
38 Correct 287 ms 23388 KB Output is correct
39 Correct 237 ms 20188 KB Output is correct
40 Correct 244 ms 20172 KB Output is correct
41 Correct 248 ms 20316 KB Output is correct
42 Correct 252 ms 20316 KB Output is correct
43 Correct 248 ms 20316 KB Output is correct
44 Correct 256 ms 20444 KB Output is correct
45 Correct 251 ms 20444 KB Output is correct
46 Correct 255 ms 20620 KB Output is correct
47 Correct 257 ms 20676 KB Output is correct
48 Correct 245 ms 20444 KB Output is correct
49 Correct 221 ms 20188 KB Output is correct
50 Correct 225 ms 20060 KB Output is correct
51 Correct 212 ms 19804 KB Output is correct
52 Correct 218 ms 19804 KB Output is correct
53 Correct 229 ms 20000 KB Output is correct
54 Correct 241 ms 22876 KB Output is correct
55 Correct 175 ms 18524 KB Output is correct
56 Correct 229 ms 21468 KB Output is correct
57 Correct 1763 ms 83492 KB Output is correct
58 Correct 1779 ms 83428 KB Output is correct
59 Correct 1809 ms 83352 KB Output is correct
60 Correct 1765 ms 83352 KB Output is correct
61 Correct 1797 ms 83312 KB Output is correct
62 Correct 1772 ms 83352 KB Output is correct
63 Correct 1220 ms 65852 KB Output is correct
64 Correct 1220 ms 66108 KB Output is correct
65 Correct 1455 ms 67960 KB Output is correct
66 Correct 1447 ms 67644 KB Output is correct
67 Correct 1467 ms 67856 KB Output is correct
68 Correct 1447 ms 67956 KB Output is correct
69 Correct 1447 ms 67920 KB Output is correct
70 Correct 1479 ms 67984 KB Output is correct
71 Correct 1469 ms 67772 KB Output is correct
72 Correct 1474 ms 67884 KB Output is correct
73 Correct 1102 ms 64572 KB Output is correct
74 Correct 1110 ms 65448 KB Output is correct
75 Correct 1145 ms 64444 KB Output is correct
76 Correct 1103 ms 64444 KB Output is correct
77 Correct 1085 ms 64712 KB Output is correct
78 Correct 1369 ms 67396 KB Output is correct
79 Correct 956 ms 64828 KB Output is correct
80 Correct 1373 ms 69952 KB Output is correct