답안 #433059

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433059 2021-06-18T19:27:04 Z bigg Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2090 ms 113064 KB
#include<bits/stdc++.h>
using namespace std;

#define esq(x) x << 1 
#define dir(x) (x<<1) | 1
#define mid(x,y,t) ((x+y)>>1) + t

typedef long long ll;
const int MAXN = 1e6 + 10;
ll seg[4*MAXN];

struct inter
{
	int l, id;
	ll k;
};

std::vector<inter> queries[MAXN];

void update(int node, int x, int y, int id, ll v){
	if(x > id || y < id) return;
	if(x == y){
		seg[node] = max(seg[node], v);
		return;
	}
	update(esq(node), x, mid(x,y,0), id, v);
	update(dir(node), mid(x,y,1), y, id, v);
	seg[node] = max(seg[esq(node)], seg[dir(node)]);
}

ll query(int node, int x, int y, int l, int r){
	if(x > r || y < l) return 0;
	if(x >= l && y <= r) return seg[node];
	ll e = query(esq(node), x, mid(x,y,0), l, r);
	ll d = query(dir(node), mid(x,y,1), y, l, r);
	return max (e,d);
	
}
ll b[MAXN];
int ans[MAXN];
int n, m;
int main(){
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%lld", &b[i]);
	for(int i = 1; i <= m; i++){
		int l, r;
		ll k;
		scanf("%d %d %lld", &l, &r, &k);
		queries[r].push_back({l,i,k});
	}
	vector<int> stac;
	for(int i = 1; i <= n; i++){
		while(!stac.empty() && b[stac.back()] <= b[i]) stac.pop_back();
		if(!stac.empty()) update(1, 1, n, stac.back(), b[stac.back()] + b[i]);
		for(int j = 0; j < queries[i].size(); j++){
			inter aqui = queries[i][j];
			ans[aqui.id] = (query(1,1,n, aqui.l, i) <= aqui.k);
		}
		stac.push_back(i);
	}
	for(int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<inter>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int j = 0; j < queries[i].size(); j++){
      |                  ~~^~~~~~~~~~~~~~~~~~~
sortbooks.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:44:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  for(int i = 1; i <= n; i++) scanf("%lld", &b[i]);
      |                              ~~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d %d %lld", &l, &r, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 15 ms 23784 KB Output is correct
4 Correct 14 ms 23756 KB Output is correct
5 Correct 16 ms 23760 KB Output is correct
6 Correct 15 ms 23780 KB Output is correct
7 Correct 15 ms 23776 KB Output is correct
8 Correct 15 ms 23824 KB Output is correct
9 Correct 16 ms 23796 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 15 ms 23784 KB Output is correct
4 Correct 14 ms 23756 KB Output is correct
5 Correct 16 ms 23760 KB Output is correct
6 Correct 15 ms 23780 KB Output is correct
7 Correct 15 ms 23776 KB Output is correct
8 Correct 15 ms 23824 KB Output is correct
9 Correct 16 ms 23796 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 17 ms 23888 KB Output is correct
12 Correct 18 ms 24060 KB Output is correct
13 Correct 18 ms 24140 KB Output is correct
14 Correct 20 ms 24268 KB Output is correct
15 Correct 20 ms 24212 KB Output is correct
16 Correct 19 ms 24140 KB Output is correct
17 Correct 18 ms 24116 KB Output is correct
18 Correct 19 ms 24068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2077 ms 80092 KB Output is correct
2 Correct 2076 ms 112984 KB Output is correct
3 Correct 2083 ms 112740 KB Output is correct
4 Correct 2055 ms 112876 KB Output is correct
5 Correct 1598 ms 96504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 161 ms 29764 KB Output is correct
2 Correct 140 ms 31484 KB Output is correct
3 Correct 123 ms 29636 KB Output is correct
4 Correct 153 ms 29628 KB Output is correct
5 Correct 122 ms 29616 KB Output is correct
6 Correct 103 ms 29216 KB Output is correct
7 Correct 103 ms 29276 KB Output is correct
8 Correct 129 ms 29140 KB Output is correct
9 Correct 66 ms 27628 KB Output is correct
10 Correct 118 ms 29140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 15 ms 23784 KB Output is correct
4 Correct 14 ms 23756 KB Output is correct
5 Correct 16 ms 23760 KB Output is correct
6 Correct 15 ms 23780 KB Output is correct
7 Correct 15 ms 23776 KB Output is correct
8 Correct 15 ms 23824 KB Output is correct
9 Correct 16 ms 23796 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 17 ms 23888 KB Output is correct
12 Correct 18 ms 24060 KB Output is correct
13 Correct 18 ms 24140 KB Output is correct
14 Correct 20 ms 24268 KB Output is correct
15 Correct 20 ms 24212 KB Output is correct
16 Correct 19 ms 24140 KB Output is correct
17 Correct 18 ms 24116 KB Output is correct
18 Correct 19 ms 24068 KB Output is correct
19 Correct 355 ms 42328 KB Output is correct
20 Correct 334 ms 42308 KB Output is correct
21 Correct 293 ms 42100 KB Output is correct
22 Correct 286 ms 41912 KB Output is correct
23 Correct 295 ms 42016 KB Output is correct
24 Correct 231 ms 37700 KB Output is correct
25 Correct 223 ms 37716 KB Output is correct
26 Correct 259 ms 38016 KB Output is correct
27 Correct 281 ms 37912 KB Output is correct
28 Correct 293 ms 38120 KB Output is correct
29 Correct 285 ms 38188 KB Output is correct
30 Correct 278 ms 38256 KB Output is correct
31 Correct 280 ms 38140 KB Output is correct
32 Correct 282 ms 38232 KB Output is correct
33 Correct 284 ms 38300 KB Output is correct
34 Correct 216 ms 37188 KB Output is correct
35 Correct 241 ms 37156 KB Output is correct
36 Correct 237 ms 37024 KB Output is correct
37 Correct 241 ms 37036 KB Output is correct
38 Correct 219 ms 37180 KB Output is correct
39 Correct 289 ms 37812 KB Output is correct
40 Correct 221 ms 34752 KB Output is correct
41 Correct 277 ms 35916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 15 ms 23784 KB Output is correct
4 Correct 14 ms 23756 KB Output is correct
5 Correct 16 ms 23760 KB Output is correct
6 Correct 15 ms 23780 KB Output is correct
7 Correct 15 ms 23776 KB Output is correct
8 Correct 15 ms 23824 KB Output is correct
9 Correct 16 ms 23796 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 17 ms 23888 KB Output is correct
12 Correct 18 ms 24060 KB Output is correct
13 Correct 18 ms 24140 KB Output is correct
14 Correct 20 ms 24268 KB Output is correct
15 Correct 20 ms 24212 KB Output is correct
16 Correct 19 ms 24140 KB Output is correct
17 Correct 18 ms 24116 KB Output is correct
18 Correct 19 ms 24068 KB Output is correct
19 Correct 2077 ms 80092 KB Output is correct
20 Correct 2076 ms 112984 KB Output is correct
21 Correct 2083 ms 112740 KB Output is correct
22 Correct 2055 ms 112876 KB Output is correct
23 Correct 1598 ms 96504 KB Output is correct
24 Correct 161 ms 29764 KB Output is correct
25 Correct 140 ms 31484 KB Output is correct
26 Correct 123 ms 29636 KB Output is correct
27 Correct 153 ms 29628 KB Output is correct
28 Correct 122 ms 29616 KB Output is correct
29 Correct 103 ms 29216 KB Output is correct
30 Correct 103 ms 29276 KB Output is correct
31 Correct 129 ms 29140 KB Output is correct
32 Correct 66 ms 27628 KB Output is correct
33 Correct 118 ms 29140 KB Output is correct
34 Correct 355 ms 42328 KB Output is correct
35 Correct 334 ms 42308 KB Output is correct
36 Correct 293 ms 42100 KB Output is correct
37 Correct 286 ms 41912 KB Output is correct
38 Correct 295 ms 42016 KB Output is correct
39 Correct 231 ms 37700 KB Output is correct
40 Correct 223 ms 37716 KB Output is correct
41 Correct 259 ms 38016 KB Output is correct
42 Correct 281 ms 37912 KB Output is correct
43 Correct 293 ms 38120 KB Output is correct
44 Correct 285 ms 38188 KB Output is correct
45 Correct 278 ms 38256 KB Output is correct
46 Correct 280 ms 38140 KB Output is correct
47 Correct 282 ms 38232 KB Output is correct
48 Correct 284 ms 38300 KB Output is correct
49 Correct 216 ms 37188 KB Output is correct
50 Correct 241 ms 37156 KB Output is correct
51 Correct 237 ms 37024 KB Output is correct
52 Correct 241 ms 37036 KB Output is correct
53 Correct 219 ms 37180 KB Output is correct
54 Correct 289 ms 37812 KB Output is correct
55 Correct 221 ms 34752 KB Output is correct
56 Correct 277 ms 35916 KB Output is correct
57 Correct 2084 ms 113048 KB Output is correct
58 Correct 2090 ms 113064 KB Output is correct
59 Correct 1976 ms 112236 KB Output is correct
60 Correct 1995 ms 112248 KB Output is correct
61 Correct 1995 ms 112228 KB Output is correct
62 Correct 2084 ms 112136 KB Output is correct
63 Correct 1275 ms 93460 KB Output is correct
64 Correct 1312 ms 93480 KB Output is correct
65 Correct 1654 ms 95664 KB Output is correct
66 Correct 1686 ms 95632 KB Output is correct
67 Correct 1733 ms 95796 KB Output is correct
68 Correct 1675 ms 96812 KB Output is correct
69 Correct 1559 ms 96672 KB Output is correct
70 Correct 1545 ms 96552 KB Output is correct
71 Correct 1533 ms 96524 KB Output is correct
72 Correct 1557 ms 96452 KB Output is correct
73 Correct 1057 ms 88448 KB Output is correct
74 Correct 1049 ms 89508 KB Output is correct
75 Correct 1057 ms 88608 KB Output is correct
76 Correct 1038 ms 88828 KB Output is correct
77 Correct 1052 ms 88124 KB Output is correct
78 Correct 1426 ms 94016 KB Output is correct
79 Correct 1028 ms 77556 KB Output is correct
80 Correct 1466 ms 85388 KB Output is correct