답안 #382005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382005 2021-03-26T09:07:32 Z vanic Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2017 ms 38928 KB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <array>

using namespace std;

const int maxn=1e6+5, Log=20, pot=(1<<Log);

struct tournament{
	int t[pot*2];
	int prop[pot*2];
	void propagate(int x){
		if(!prop[x]){
			return;
		}
		t[x]=max(t[x], prop[x]);
		if(x<pot){
			prop[x*2]=max(prop[x*2], prop[x]);
			prop[x*2+1]=max(prop[x*2+1], prop[x]);
		}
		prop[x]=0;
		
	}
	void update(int x, int val){
		//ak waa ovo mijenjaj
		for(; x>0; x/=2){
			t[x]=max(t[x], val);
		}
	}
	void update2(int L, int D, int x, int l, int d, int val){
		propagate(x);
		if(L>=l && D<=d){
			update(x, val);
			if(x<pot){
				prop[x*2]=max(prop[x*2], val);
				prop[x*2+1]=max(prop[x*2+1], val);
			}
			return;
		}
		if((L+D)/2>=l){
			update2(L, (L+D)/2, x*2, l, d, val);
		}
		if((L+D)/2+1<=d){
			update2((L+D)/2+1, D, x*2+1, l, d, val);
		}
	}
	int query(int L, int D, int x, int l, int d){
		propagate(x);
		if(L>=l && D<=d){
			return t[x];
		}
		int lijeva=0, desna=0;
		if((L+D)/2>=l){
			lijeva=query(L, (L+D)/2, x*2, l, d);
		}
		if((L+D)/2+1<=d){
			desna=query((L+D)/2+1, D, x*2+1, l, d);
		}
		return max(lijeva, desna);
	}
};


tournament T;
int n, m;
int a[maxn];
int ind[maxn];
bool sol[maxn];
int q[maxn][3];


bool cmp(int aa, int b){
	return q[aa][1]<q[b][1];
}

vector < pair < int, int > > red;

void rijesi(){
	int pos=0;
	for(int i=0; i<n; i++){
		while(!red.empty() && red.back().first<=a[i]){
			red.pop_back();
		}
		if(!red.empty()){
			T.update2(0, pot-1, 1, 0, red.back().second, red.back().first+a[i]);
		}
		red.push_back({a[i], i});
		while(pos<m && q[ind[pos]][1]==i){
			sol[ind[pos]]=T.query(0, pot-1, 1, q[ind[pos]][0], i)<=q[ind[pos]][2];
			pos++;
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<m; i++){
		cin >> q[i][0] >> q[i][1] >> q[i][2];
		q[i][0]--;
		q[i][1]--;
		ind[i]=i;
	}
	sort(ind, ind+m, cmp);
	rijesi();
	for(int i=0; i<m; i++){
		cout << sol[i] << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 4 ms 620 KB Output is correct
12 Correct 6 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 8 ms 876 KB Output is correct
15 Correct 11 ms 876 KB Output is correct
16 Correct 7 ms 748 KB Output is correct
17 Correct 5 ms 748 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1973 ms 38708 KB Output is correct
2 Correct 1933 ms 38560 KB Output is correct
3 Correct 1939 ms 38696 KB Output is correct
4 Correct 2017 ms 38928 KB Output is correct
5 Correct 1318 ms 23020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 4332 KB Output is correct
2 Correct 135 ms 4588 KB Output is correct
3 Correct 99 ms 2924 KB Output is correct
4 Correct 101 ms 3052 KB Output is correct
5 Correct 100 ms 2924 KB Output is correct
6 Correct 91 ms 3052 KB Output is correct
7 Correct 92 ms 3180 KB Output is correct
8 Correct 107 ms 4152 KB Output is correct
9 Correct 56 ms 2540 KB Output is correct
10 Correct 104 ms 4460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 4 ms 620 KB Output is correct
12 Correct 6 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 8 ms 876 KB Output is correct
15 Correct 11 ms 876 KB Output is correct
16 Correct 7 ms 748 KB Output is correct
17 Correct 5 ms 748 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 337 ms 8532 KB Output is correct
20 Correct 366 ms 8428 KB Output is correct
21 Correct 297 ms 8556 KB Output is correct
22 Correct 291 ms 8472 KB Output is correct
23 Correct 288 ms 8556 KB Output is correct
24 Correct 209 ms 5228 KB Output is correct
25 Correct 211 ms 5228 KB Output is correct
26 Correct 224 ms 5228 KB Output is correct
27 Correct 230 ms 5228 KB Output is correct
28 Correct 229 ms 5228 KB Output is correct
29 Correct 231 ms 5228 KB Output is correct
30 Correct 226 ms 5376 KB Output is correct
31 Correct 223 ms 5356 KB Output is correct
32 Correct 229 ms 5228 KB Output is correct
33 Correct 229 ms 5228 KB Output is correct
34 Correct 199 ms 5356 KB Output is correct
35 Correct 207 ms 5356 KB Output is correct
36 Correct 196 ms 5332 KB Output is correct
37 Correct 199 ms 5356 KB Output is correct
38 Correct 205 ms 5356 KB Output is correct
39 Correct 218 ms 7300 KB Output is correct
40 Correct 163 ms 6124 KB Output is correct
41 Correct 237 ms 7660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 4 ms 620 KB Output is correct
12 Correct 6 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 8 ms 876 KB Output is correct
15 Correct 11 ms 876 KB Output is correct
16 Correct 7 ms 748 KB Output is correct
17 Correct 5 ms 748 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 1973 ms 38708 KB Output is correct
20 Correct 1933 ms 38560 KB Output is correct
21 Correct 1939 ms 38696 KB Output is correct
22 Correct 2017 ms 38928 KB Output is correct
23 Correct 1318 ms 23020 KB Output is correct
24 Correct 136 ms 4332 KB Output is correct
25 Correct 135 ms 4588 KB Output is correct
26 Correct 99 ms 2924 KB Output is correct
27 Correct 101 ms 3052 KB Output is correct
28 Correct 100 ms 2924 KB Output is correct
29 Correct 91 ms 3052 KB Output is correct
30 Correct 92 ms 3180 KB Output is correct
31 Correct 107 ms 4152 KB Output is correct
32 Correct 56 ms 2540 KB Output is correct
33 Correct 104 ms 4460 KB Output is correct
34 Correct 337 ms 8532 KB Output is correct
35 Correct 366 ms 8428 KB Output is correct
36 Correct 297 ms 8556 KB Output is correct
37 Correct 291 ms 8472 KB Output is correct
38 Correct 288 ms 8556 KB Output is correct
39 Correct 209 ms 5228 KB Output is correct
40 Correct 211 ms 5228 KB Output is correct
41 Correct 224 ms 5228 KB Output is correct
42 Correct 230 ms 5228 KB Output is correct
43 Correct 229 ms 5228 KB Output is correct
44 Correct 231 ms 5228 KB Output is correct
45 Correct 226 ms 5376 KB Output is correct
46 Correct 223 ms 5356 KB Output is correct
47 Correct 229 ms 5228 KB Output is correct
48 Correct 229 ms 5228 KB Output is correct
49 Correct 199 ms 5356 KB Output is correct
50 Correct 207 ms 5356 KB Output is correct
51 Correct 196 ms 5332 KB Output is correct
52 Correct 199 ms 5356 KB Output is correct
53 Correct 205 ms 5356 KB Output is correct
54 Correct 218 ms 7300 KB Output is correct
55 Correct 163 ms 6124 KB Output is correct
56 Correct 237 ms 7660 KB Output is correct
57 Correct 1936 ms 38728 KB Output is correct
58 Correct 1966 ms 38692 KB Output is correct
59 Correct 1891 ms 38628 KB Output is correct
60 Correct 1886 ms 38636 KB Output is correct
61 Correct 1879 ms 38764 KB Output is correct
62 Correct 1889 ms 38764 KB Output is correct
63 Correct 1216 ms 23020 KB Output is correct
64 Correct 1196 ms 23148 KB Output is correct
65 Correct 1295 ms 23020 KB Output is correct
66 Correct 1282 ms 22972 KB Output is correct
67 Correct 1330 ms 23060 KB Output is correct
68 Correct 1327 ms 22992 KB Output is correct
69 Correct 1324 ms 23020 KB Output is correct
70 Correct 1323 ms 23020 KB Output is correct
71 Correct 1299 ms 23020 KB Output is correct
72 Correct 1314 ms 23020 KB Output is correct
73 Correct 1121 ms 23268 KB Output is correct
74 Correct 1150 ms 23148 KB Output is correct
75 Correct 1111 ms 23148 KB Output is correct
76 Correct 1132 ms 23148 KB Output is correct
77 Correct 1124 ms 23020 KB Output is correct
78 Correct 1325 ms 33516 KB Output is correct
79 Correct 877 ms 25324 KB Output is correct
80 Correct 1336 ms 35308 KB Output is correct