답안 #167449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167449 2019-12-08T15:12:36 Z tincamatei Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2186 ms 110128 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1000000;
int aint[1+4*MAX_N];

void update(int poz, int val, int l = 1, int r = MAX_N, int nod = 1) {
	if(poz < l || r < poz) return;
	
	if(l == r)
		aint[nod] = max(aint[nod], val);
	else {
		int mid = (l + r) / 2;
		update(poz, val, l, mid, 2 * nod);
		update(poz, val, mid + 1, r, 2 * nod + 1);
		aint[nod] = max(aint[2 * nod], aint[2 * nod + 1]);
	}
}

int query(int i, int j, int l = 1, int r = MAX_N, int nod = 1) {
	if(j < l || r < i || j < i) return -1;

	if(i <= l && r <= j)
		return aint[nod];
	else {
		int mid = (l + r) / 2;
		return max(query(i, j, l, mid, 2 * nod),
		           query(i, j, mid + 1, r, 2 * nod + 1));
	}
}

int v[1+MAX_N];
int stiva[1+MAX_N], top;
int nextBigger[1+MAX_N];
bool rez[1+MAX_N];

struct Query {
	int l, r, k;
	bool *rez;
};
vector<Query> queryBucket[1+MAX_N];

int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; ++i) {
		scanf("%d", &v[i]);
		while(top > 0 && v[stiva[top - 1]] <= v[i])
			--top;

		if(top > 0)
			nextBigger[i] = stiva[top - 1];
		stiva[top++] = i;
	}

	for(int i = 0; i < M; ++i) {
		int l, r, k;
		scanf("%d%d%d", &l, &r, &k);
		queryBucket[r].push_back({l, r, k, &rez[i]});
	}

	for(int i = 1; i <= N; ++i) {
		if(nextBigger[i] != 0)
			update(nextBigger[i], v[i] + v[nextBigger[i]]);
	
		for(auto it: queryBucket[i]) {
			if(query(it.l, it.r) <= it.k)
				*it.rez = true;
			else
				*it.rez = false;
		}
	}

	for(int i = 0; i < M; ++i)
		printf("%d\n", rez[i]);

	return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &v[i]);
   ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &l, &r, &k);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23920 KB Output is correct
2 Correct 26 ms 23772 KB Output is correct
3 Correct 26 ms 23876 KB Output is correct
4 Correct 26 ms 23932 KB Output is correct
5 Correct 26 ms 23900 KB Output is correct
6 Correct 49 ms 23928 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 26 ms 23844 KB Output is correct
9 Correct 25 ms 23932 KB Output is correct
10 Correct 27 ms 23960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23920 KB Output is correct
2 Correct 26 ms 23772 KB Output is correct
3 Correct 26 ms 23876 KB Output is correct
4 Correct 26 ms 23932 KB Output is correct
5 Correct 26 ms 23900 KB Output is correct
6 Correct 49 ms 23928 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 26 ms 23844 KB Output is correct
9 Correct 25 ms 23932 KB Output is correct
10 Correct 27 ms 23960 KB Output is correct
11 Correct 29 ms 24100 KB Output is correct
12 Correct 31 ms 24116 KB Output is correct
13 Correct 32 ms 24184 KB Output is correct
14 Correct 33 ms 24284 KB Output is correct
15 Correct 33 ms 24284 KB Output is correct
16 Correct 31 ms 24228 KB Output is correct
17 Correct 31 ms 24156 KB Output is correct
18 Correct 32 ms 24156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2106 ms 77324 KB Output is correct
2 Correct 2156 ms 79368 KB Output is correct
3 Correct 2143 ms 79224 KB Output is correct
4 Correct 2186 ms 79372 KB Output is correct
5 Correct 1616 ms 67460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 30968 KB Output is correct
2 Correct 161 ms 31284 KB Output is correct
3 Correct 138 ms 29920 KB Output is correct
4 Correct 145 ms 29972 KB Output is correct
5 Correct 141 ms 29732 KB Output is correct
6 Correct 115 ms 29844 KB Output is correct
7 Correct 116 ms 29816 KB Output is correct
8 Correct 146 ms 29868 KB Output is correct
9 Correct 91 ms 28432 KB Output is correct
10 Correct 145 ms 29744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23920 KB Output is correct
2 Correct 26 ms 23772 KB Output is correct
3 Correct 26 ms 23876 KB Output is correct
4 Correct 26 ms 23932 KB Output is correct
5 Correct 26 ms 23900 KB Output is correct
6 Correct 49 ms 23928 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 26 ms 23844 KB Output is correct
9 Correct 25 ms 23932 KB Output is correct
10 Correct 27 ms 23960 KB Output is correct
11 Correct 29 ms 24100 KB Output is correct
12 Correct 31 ms 24116 KB Output is correct
13 Correct 32 ms 24184 KB Output is correct
14 Correct 33 ms 24284 KB Output is correct
15 Correct 33 ms 24284 KB Output is correct
16 Correct 31 ms 24228 KB Output is correct
17 Correct 31 ms 24156 KB Output is correct
18 Correct 32 ms 24156 KB Output is correct
19 Correct 389 ms 41080 KB Output is correct
20 Correct 409 ms 40912 KB Output is correct
21 Correct 326 ms 41212 KB Output is correct
22 Correct 326 ms 41144 KB Output is correct
23 Correct 323 ms 41224 KB Output is correct
24 Correct 259 ms 38648 KB Output is correct
25 Correct 258 ms 38616 KB Output is correct
26 Correct 288 ms 38820 KB Output is correct
27 Correct 288 ms 38708 KB Output is correct
28 Correct 300 ms 38544 KB Output is correct
29 Correct 305 ms 38520 KB Output is correct
30 Correct 309 ms 38288 KB Output is correct
31 Correct 302 ms 38392 KB Output is correct
32 Correct 319 ms 38392 KB Output is correct
33 Correct 311 ms 38444 KB Output is correct
34 Correct 236 ms 38140 KB Output is correct
35 Correct 236 ms 38072 KB Output is correct
36 Correct 225 ms 37880 KB Output is correct
37 Correct 227 ms 37880 KB Output is correct
38 Correct 235 ms 38008 KB Output is correct
39 Correct 286 ms 37296 KB Output is correct
40 Correct 236 ms 35176 KB Output is correct
41 Correct 295 ms 37160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23920 KB Output is correct
2 Correct 26 ms 23772 KB Output is correct
3 Correct 26 ms 23876 KB Output is correct
4 Correct 26 ms 23932 KB Output is correct
5 Correct 26 ms 23900 KB Output is correct
6 Correct 49 ms 23928 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 26 ms 23844 KB Output is correct
9 Correct 25 ms 23932 KB Output is correct
10 Correct 27 ms 23960 KB Output is correct
11 Correct 29 ms 24100 KB Output is correct
12 Correct 31 ms 24116 KB Output is correct
13 Correct 32 ms 24184 KB Output is correct
14 Correct 33 ms 24284 KB Output is correct
15 Correct 33 ms 24284 KB Output is correct
16 Correct 31 ms 24228 KB Output is correct
17 Correct 31 ms 24156 KB Output is correct
18 Correct 32 ms 24156 KB Output is correct
19 Correct 2106 ms 77324 KB Output is correct
20 Correct 2156 ms 79368 KB Output is correct
21 Correct 2143 ms 79224 KB Output is correct
22 Correct 2186 ms 79372 KB Output is correct
23 Correct 1616 ms 67460 KB Output is correct
24 Correct 168 ms 30968 KB Output is correct
25 Correct 161 ms 31284 KB Output is correct
26 Correct 138 ms 29920 KB Output is correct
27 Correct 145 ms 29972 KB Output is correct
28 Correct 141 ms 29732 KB Output is correct
29 Correct 115 ms 29844 KB Output is correct
30 Correct 116 ms 29816 KB Output is correct
31 Correct 146 ms 29868 KB Output is correct
32 Correct 91 ms 28432 KB Output is correct
33 Correct 145 ms 29744 KB Output is correct
34 Correct 389 ms 41080 KB Output is correct
35 Correct 409 ms 40912 KB Output is correct
36 Correct 326 ms 41212 KB Output is correct
37 Correct 326 ms 41144 KB Output is correct
38 Correct 323 ms 41224 KB Output is correct
39 Correct 259 ms 38648 KB Output is correct
40 Correct 258 ms 38616 KB Output is correct
41 Correct 288 ms 38820 KB Output is correct
42 Correct 288 ms 38708 KB Output is correct
43 Correct 300 ms 38544 KB Output is correct
44 Correct 305 ms 38520 KB Output is correct
45 Correct 309 ms 38288 KB Output is correct
46 Correct 302 ms 38392 KB Output is correct
47 Correct 319 ms 38392 KB Output is correct
48 Correct 311 ms 38444 KB Output is correct
49 Correct 236 ms 38140 KB Output is correct
50 Correct 236 ms 38072 KB Output is correct
51 Correct 225 ms 37880 KB Output is correct
52 Correct 227 ms 37880 KB Output is correct
53 Correct 235 ms 38008 KB Output is correct
54 Correct 286 ms 37296 KB Output is correct
55 Correct 236 ms 35176 KB Output is correct
56 Correct 295 ms 37160 KB Output is correct
57 Correct 2058 ms 109124 KB Output is correct
58 Correct 2055 ms 109320 KB Output is correct
59 Correct 2015 ms 110084 KB Output is correct
60 Correct 2067 ms 110128 KB Output is correct
61 Correct 2013 ms 109064 KB Output is correct
62 Correct 2059 ms 108712 KB Output is correct
63 Correct 1295 ms 96464 KB Output is correct
64 Correct 1269 ms 96340 KB Output is correct
65 Correct 1688 ms 98304 KB Output is correct
66 Correct 1796 ms 97656 KB Output is correct
67 Correct 1661 ms 97732 KB Output is correct
68 Correct 1657 ms 96180 KB Output is correct
69 Correct 1675 ms 95896 KB Output is correct
70 Correct 1656 ms 93348 KB Output is correct
71 Correct 1661 ms 96252 KB Output is correct
72 Correct 1652 ms 92880 KB Output is correct
73 Correct 1114 ms 79796 KB Output is correct
74 Correct 1118 ms 75960 KB Output is correct
75 Correct 1131 ms 73244 KB Output is correct
76 Correct 1141 ms 75456 KB Output is correct
77 Correct 1143 ms 78684 KB Output is correct
78 Correct 1491 ms 85684 KB Output is correct
79 Correct 1134 ms 79860 KB Output is correct
80 Correct 1437 ms 86684 KB Output is correct