답안 #202075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202075 2020-02-13T13:52:51 Z guangxuan Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2272 ms 183560 KB
#include <bits/stdc++.h>
using namespace std;
int a[1000009];
vector<pair<int,pair<int,int> > > qs[1000009]; // end, k, qi
bool ans[1000009];
int lg[1000009];

struct node{
	int s,e,m,v;
	node *l,*r;
	node(int _s,int _e):s(_s),e(_e),m((_s+_e)/2),v(0){
		if(s==e)return;
		l = new node(s,m);
		r = new node(m+1,e);
	}
	int qu(int x,int y){
		if(s==x&&e==y)return v;
		if(x>m)return r->qu(x,y);
		if(y<=m)return l->qu(x,y);
		return max(l->qu(x,m),r->qu(m+1,y));
	}
	void up(int x,int uv){
		if(s==e){v= max(v,uv);return;}
		if(x>m)r->up(x,uv);
		else l->up(x,uv);
		v = max(l->v,r->v);
	}
}*root;

int main(){
	int n,t;
	scanf("%d%d",&n,&t);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int ti=0;ti<t;ti++){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		qs[r-1].push_back({l-1,{k,ti}});
	}
	stack<int> stk;
	for(int i=0;i<n;i++){
		while(stk.size()&&a[stk.top()]<=a[i])stk.pop();
		if(stk.size()==0)lg[i]=-1;
		else lg[i]=stk.top();
		stk.push(i);
	}
	root = new node(0,n-1);
	for(int r=0;r<n;r++){
		if(lg[r]!=-1){
			int lgr = lg[r];
			root->up(lgr,a[lgr]+a[r]);
		}
		for(auto q:qs[r]){
			int maxsum = root->qu(q.first,r);
			if(q.second.first>=maxsum)ans[q.second.second]=1;
			//printf("MS%d K%d\n",maxsum,q.second.first);
		}
	}
	for(int i=0;i<t;i++){
		printf("%d\n",ans[i]);
	}
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&t);
  ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
   ~~~~~^~~~~~~~~~~~
sortbooks.cpp:38: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 20 ms 23800 KB Output is correct
2 Correct 19 ms 23804 KB Output is correct
3 Correct 20 ms 23928 KB Output is correct
4 Correct 19 ms 23672 KB Output is correct
5 Correct 19 ms 23800 KB Output is correct
6 Correct 19 ms 23928 KB Output is correct
7 Correct 19 ms 23928 KB Output is correct
8 Correct 18 ms 23800 KB Output is correct
9 Correct 18 ms 23932 KB Output is correct
10 Correct 19 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23800 KB Output is correct
2 Correct 19 ms 23804 KB Output is correct
3 Correct 20 ms 23928 KB Output is correct
4 Correct 19 ms 23672 KB Output is correct
5 Correct 19 ms 23800 KB Output is correct
6 Correct 19 ms 23928 KB Output is correct
7 Correct 19 ms 23928 KB Output is correct
8 Correct 18 ms 23800 KB Output is correct
9 Correct 18 ms 23932 KB Output is correct
10 Correct 19 ms 23928 KB Output is correct
11 Correct 21 ms 24184 KB Output is correct
12 Correct 22 ms 24568 KB Output is correct
13 Correct 23 ms 24508 KB Output is correct
14 Correct 25 ms 24696 KB Output is correct
15 Correct 26 ms 24568 KB Output is correct
16 Correct 25 ms 24568 KB Output is correct
17 Correct 24 ms 24440 KB Output is correct
18 Correct 25 ms 24568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2191 ms 181352 KB Output is correct
2 Correct 2182 ms 182392 KB Output is correct
3 Correct 2217 ms 182180 KB Output is correct
4 Correct 2223 ms 182520 KB Output is correct
5 Correct 2050 ms 183288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 38392 KB Output is correct
2 Correct 134 ms 38136 KB Output is correct
3 Correct 138 ms 38264 KB Output is correct
4 Correct 139 ms 38396 KB Output is correct
5 Correct 143 ms 38392 KB Output is correct
6 Correct 107 ms 37624 KB Output is correct
7 Correct 109 ms 37496 KB Output is correct
8 Correct 130 ms 37932 KB Output is correct
9 Correct 67 ms 26928 KB Output is correct
10 Correct 139 ms 37924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23800 KB Output is correct
2 Correct 19 ms 23804 KB Output is correct
3 Correct 20 ms 23928 KB Output is correct
4 Correct 19 ms 23672 KB Output is correct
5 Correct 19 ms 23800 KB Output is correct
6 Correct 19 ms 23928 KB Output is correct
7 Correct 19 ms 23928 KB Output is correct
8 Correct 18 ms 23800 KB Output is correct
9 Correct 18 ms 23932 KB Output is correct
10 Correct 19 ms 23928 KB Output is correct
11 Correct 21 ms 24184 KB Output is correct
12 Correct 22 ms 24568 KB Output is correct
13 Correct 23 ms 24508 KB Output is correct
14 Correct 25 ms 24696 KB Output is correct
15 Correct 26 ms 24568 KB Output is correct
16 Correct 25 ms 24568 KB Output is correct
17 Correct 24 ms 24440 KB Output is correct
18 Correct 25 ms 24568 KB Output is correct
19 Correct 377 ms 55672 KB Output is correct
20 Correct 365 ms 55648 KB Output is correct
21 Correct 312 ms 54776 KB Output is correct
22 Correct 285 ms 54884 KB Output is correct
23 Correct 284 ms 54776 KB Output is correct
24 Correct 236 ms 54648 KB Output is correct
25 Correct 247 ms 54648 KB Output is correct
26 Correct 280 ms 55160 KB Output is correct
27 Correct 283 ms 55188 KB Output is correct
28 Correct 297 ms 55288 KB Output is correct
29 Correct 331 ms 55904 KB Output is correct
30 Correct 333 ms 55672 KB Output is correct
31 Correct 335 ms 55672 KB Output is correct
32 Correct 325 ms 55672 KB Output is correct
33 Correct 333 ms 55752 KB Output is correct
34 Correct 218 ms 54008 KB Output is correct
35 Correct 229 ms 54136 KB Output is correct
36 Correct 222 ms 53880 KB Output is correct
37 Correct 224 ms 54008 KB Output is correct
38 Correct 226 ms 54008 KB Output is correct
39 Correct 285 ms 53936 KB Output is correct
40 Correct 222 ms 45996 KB Output is correct
41 Correct 280 ms 53416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23800 KB Output is correct
2 Correct 19 ms 23804 KB Output is correct
3 Correct 20 ms 23928 KB Output is correct
4 Correct 19 ms 23672 KB Output is correct
5 Correct 19 ms 23800 KB Output is correct
6 Correct 19 ms 23928 KB Output is correct
7 Correct 19 ms 23928 KB Output is correct
8 Correct 18 ms 23800 KB Output is correct
9 Correct 18 ms 23932 KB Output is correct
10 Correct 19 ms 23928 KB Output is correct
11 Correct 21 ms 24184 KB Output is correct
12 Correct 22 ms 24568 KB Output is correct
13 Correct 23 ms 24508 KB Output is correct
14 Correct 25 ms 24696 KB Output is correct
15 Correct 26 ms 24568 KB Output is correct
16 Correct 25 ms 24568 KB Output is correct
17 Correct 24 ms 24440 KB Output is correct
18 Correct 25 ms 24568 KB Output is correct
19 Correct 2191 ms 181352 KB Output is correct
20 Correct 2182 ms 182392 KB Output is correct
21 Correct 2217 ms 182180 KB Output is correct
22 Correct 2223 ms 182520 KB Output is correct
23 Correct 2050 ms 183288 KB Output is correct
24 Correct 158 ms 38392 KB Output is correct
25 Correct 134 ms 38136 KB Output is correct
26 Correct 138 ms 38264 KB Output is correct
27 Correct 139 ms 38396 KB Output is correct
28 Correct 143 ms 38392 KB Output is correct
29 Correct 107 ms 37624 KB Output is correct
30 Correct 109 ms 37496 KB Output is correct
31 Correct 130 ms 37932 KB Output is correct
32 Correct 67 ms 26928 KB Output is correct
33 Correct 139 ms 37924 KB Output is correct
34 Correct 377 ms 55672 KB Output is correct
35 Correct 365 ms 55648 KB Output is correct
36 Correct 312 ms 54776 KB Output is correct
37 Correct 285 ms 54884 KB Output is correct
38 Correct 284 ms 54776 KB Output is correct
39 Correct 236 ms 54648 KB Output is correct
40 Correct 247 ms 54648 KB Output is correct
41 Correct 280 ms 55160 KB Output is correct
42 Correct 283 ms 55188 KB Output is correct
43 Correct 297 ms 55288 KB Output is correct
44 Correct 331 ms 55904 KB Output is correct
45 Correct 333 ms 55672 KB Output is correct
46 Correct 335 ms 55672 KB Output is correct
47 Correct 325 ms 55672 KB Output is correct
48 Correct 333 ms 55752 KB Output is correct
49 Correct 218 ms 54008 KB Output is correct
50 Correct 229 ms 54136 KB Output is correct
51 Correct 222 ms 53880 KB Output is correct
52 Correct 224 ms 54008 KB Output is correct
53 Correct 226 ms 54008 KB Output is correct
54 Correct 285 ms 53936 KB Output is correct
55 Correct 222 ms 45996 KB Output is correct
56 Correct 280 ms 53416 KB Output is correct
57 Correct 2272 ms 183424 KB Output is correct
58 Correct 2229 ms 183476 KB Output is correct
59 Correct 2031 ms 181888 KB Output is correct
60 Correct 2048 ms 181888 KB Output is correct
61 Correct 2053 ms 181812 KB Output is correct
62 Correct 2071 ms 181836 KB Output is correct
63 Correct 1203 ms 177344 KB Output is correct
64 Correct 1203 ms 177348 KB Output is correct
65 Correct 1823 ms 181740 KB Output is correct
66 Correct 1821 ms 181572 KB Output is correct
67 Correct 1826 ms 181788 KB Output is correct
68 Correct 2009 ms 183560 KB Output is correct
69 Correct 2021 ms 183364 KB Output is correct
70 Correct 1991 ms 182684 KB Output is correct
71 Correct 2025 ms 182872 KB Output is correct
72 Correct 2003 ms 182444 KB Output is correct
73 Correct 1070 ms 171936 KB Output is correct
74 Correct 1066 ms 172712 KB Output is correct
75 Correct 1067 ms 171976 KB Output is correct
76 Correct 1076 ms 172072 KB Output is correct
77 Correct 1092 ms 171836 KB Output is correct
78 Correct 1700 ms 175464 KB Output is correct
79 Correct 1198 ms 120016 KB Output is correct
80 Correct 1685 ms 172148 KB Output is correct