답안 #672094

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672094 2022-12-14T17:57:50 Z GudStonks Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1196 ms 107332 KB
#include<bits/stdc++.h>
using namespace std;
#define ft first
#define sd second
typedef long long ll;
const ll MOD = 1e9+7;
ll n, q, arr[1000005], brr[1000005], ans[1000005], t[(1000005 << 2)];
stack<ll>s;
vector<pair<pair<ll, ll>, pair<ll, ll> > >v;

void upd(ll pos, ll val, ll v = 1, ll tl = 1, ll tr = n){
	if(pos < tl || pos > tr)return;
	if(tl == tr){
		t[v] = max(t[v], val);
		return;
	}
	ll m = (tl + tr) / 2;
	upd(pos, val, v + v, tl, m);
	upd(pos, val, v + v + 1, m + 1, tr);
	t[v] = max(t[v + v], t[v + v + 1]);
}

ll get(ll l, ll r, ll v = 1, ll tl = 1, ll tr = n){
	if(r < tl || l > tr)return 0;
	if(l <= tl && tr <= r)
		return t[v];
	ll m = (tl + tr) / 2;
	return max(get(l, r, v + v, tl, m), get(l, r, v + v + 1, m + 1, tr));
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>q;
	for(int i = 1; i <= n; i++){
		cin>>arr[i];
		while(!s.empty() && arr[s.top()] <= arr[i])s.pop();
		if(!s.empty())brr[i] = s.top();
		s.push(i);
	}
	for(int i = 1, a, b, c; i <= q; i++){
		cin>>a>>b>>c;
		v.push_back({{b, a}, {c, i}});
	}
	sort(v.begin(), v.end());
	ll j = 0;
	for(auto it : v){
		ll r = it.ft.ft, l = it.ft.sd, k = it.sd.ft, i = it.sd.sd;
		while(j < r){
			j++;
			if(brr[j]){
				upd(brr[j], arr[j] + arr[brr[j]]);
			}
		}
		ans[i] = (get(l, r) <= k ? 1 : 0);
	}
	for(int i = 1; i <= q; i++)cout<<ans[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 4 ms 852 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 5 ms 984 KB Output is correct
15 Correct 5 ms 984 KB Output is correct
16 Correct 4 ms 920 KB Output is correct
17 Correct 3 ms 856 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1151 ms 105560 KB Output is correct
2 Correct 1194 ms 106560 KB Output is correct
3 Correct 1152 ms 106560 KB Output is correct
4 Correct 1177 ms 106556 KB Output is correct
5 Correct 871 ms 82420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 10132 KB Output is correct
2 Correct 85 ms 10064 KB Output is correct
3 Correct 71 ms 7304 KB Output is correct
4 Correct 69 ms 7304 KB Output is correct
5 Correct 69 ms 7308 KB Output is correct
6 Correct 66 ms 7284 KB Output is correct
7 Correct 66 ms 7272 KB Output is correct
8 Correct 68 ms 7628 KB Output is correct
9 Correct 40 ms 5896 KB Output is correct
10 Correct 66 ms 7468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 4 ms 852 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 5 ms 984 KB Output is correct
15 Correct 5 ms 984 KB Output is correct
16 Correct 4 ms 920 KB Output is correct
17 Correct 3 ms 856 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 199 ms 22516 KB Output is correct
20 Correct 210 ms 22580 KB Output is correct
21 Correct 192 ms 22416 KB Output is correct
22 Correct 196 ms 22284 KB Output is correct
23 Correct 207 ms 22376 KB Output is correct
24 Correct 171 ms 16568 KB Output is correct
25 Correct 154 ms 16552 KB Output is correct
26 Correct 164 ms 16752 KB Output is correct
27 Correct 160 ms 16788 KB Output is correct
28 Correct 163 ms 16792 KB Output is correct
29 Correct 172 ms 16872 KB Output is correct
30 Correct 169 ms 16884 KB Output is correct
31 Correct 163 ms 16868 KB Output is correct
32 Correct 168 ms 16856 KB Output is correct
33 Correct 165 ms 16800 KB Output is correct
34 Correct 154 ms 16496 KB Output is correct
35 Correct 166 ms 16544 KB Output is correct
36 Correct 150 ms 16336 KB Output is correct
37 Correct 147 ms 16248 KB Output is correct
38 Correct 158 ms 16524 KB Output is correct
39 Correct 156 ms 17392 KB Output is correct
40 Correct 118 ms 14424 KB Output is correct
41 Correct 148 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 4 ms 852 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 5 ms 984 KB Output is correct
15 Correct 5 ms 984 KB Output is correct
16 Correct 4 ms 920 KB Output is correct
17 Correct 3 ms 856 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 1151 ms 105560 KB Output is correct
20 Correct 1194 ms 106560 KB Output is correct
21 Correct 1152 ms 106560 KB Output is correct
22 Correct 1177 ms 106556 KB Output is correct
23 Correct 871 ms 82420 KB Output is correct
24 Correct 88 ms 10132 KB Output is correct
25 Correct 85 ms 10064 KB Output is correct
26 Correct 71 ms 7304 KB Output is correct
27 Correct 69 ms 7304 KB Output is correct
28 Correct 69 ms 7308 KB Output is correct
29 Correct 66 ms 7284 KB Output is correct
30 Correct 66 ms 7272 KB Output is correct
31 Correct 68 ms 7628 KB Output is correct
32 Correct 40 ms 5896 KB Output is correct
33 Correct 66 ms 7468 KB Output is correct
34 Correct 199 ms 22516 KB Output is correct
35 Correct 210 ms 22580 KB Output is correct
36 Correct 192 ms 22416 KB Output is correct
37 Correct 196 ms 22284 KB Output is correct
38 Correct 207 ms 22376 KB Output is correct
39 Correct 171 ms 16568 KB Output is correct
40 Correct 154 ms 16552 KB Output is correct
41 Correct 164 ms 16752 KB Output is correct
42 Correct 160 ms 16788 KB Output is correct
43 Correct 163 ms 16792 KB Output is correct
44 Correct 172 ms 16872 KB Output is correct
45 Correct 169 ms 16884 KB Output is correct
46 Correct 163 ms 16868 KB Output is correct
47 Correct 168 ms 16856 KB Output is correct
48 Correct 165 ms 16800 KB Output is correct
49 Correct 154 ms 16496 KB Output is correct
50 Correct 166 ms 16544 KB Output is correct
51 Correct 150 ms 16336 KB Output is correct
52 Correct 147 ms 16248 KB Output is correct
53 Correct 158 ms 16524 KB Output is correct
54 Correct 156 ms 17392 KB Output is correct
55 Correct 118 ms 14424 KB Output is correct
56 Correct 148 ms 15964 KB Output is correct
57 Correct 1196 ms 107320 KB Output is correct
58 Correct 1163 ms 107332 KB Output is correct
59 Correct 1129 ms 107212 KB Output is correct
60 Correct 1144 ms 107308 KB Output is correct
61 Correct 1125 ms 107220 KB Output is correct
62 Correct 1142 ms 107064 KB Output is correct
63 Correct 861 ms 81120 KB Output is correct
64 Correct 861 ms 81148 KB Output is correct
65 Correct 902 ms 83052 KB Output is correct
66 Correct 898 ms 82896 KB Output is correct
67 Correct 894 ms 82856 KB Output is correct
68 Correct 893 ms 83224 KB Output is correct
69 Correct 919 ms 83148 KB Output is correct
70 Correct 909 ms 82928 KB Output is correct
71 Correct 895 ms 82820 KB Output is correct
72 Correct 912 ms 82756 KB Output is correct
73 Correct 834 ms 79624 KB Output is correct
74 Correct 870 ms 80432 KB Output is correct
75 Correct 854 ms 79516 KB Output is correct
76 Correct 859 ms 79388 KB Output is correct
77 Correct 851 ms 79480 KB Output is correct
78 Correct 860 ms 84996 KB Output is correct
79 Correct 645 ms 69476 KB Output is correct
80 Correct 829 ms 79892 KB Output is correct