답안 #166422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166422 2019-12-02T10:30:07 Z GioChkhaidze Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2420 ms 127432 KB
#include <bits/stdc++.h>
#define Tree int h,int l,int r
#define Left (h<<1),l,((l+r)>>1)
#define Right ((h<<1)|1),((l+r)>>1)+1,r
using namespace std;
const int N=2e6+5;
bool ANS[N];
int n,q,idx,val,L,R;
int w[N],a[N],b[N],c[N],Greater[N],v[6*N];
stack < int > st;
vector < int > Query[N];
void Upd(Tree) { 
	if (idx<l || r<idx) return;
	if (l==idx && r==idx)  { v[h]=val; return; }
	Upd(Left),Upd(Right);
	if (v[(h<<1)]>v[((h<<1)|1)]) v[h]=v[(h<<1)];	
							else v[h]=v[((h<<1)|1)];
}

int Get(Tree) { 
	if (r<L || R<l) return 0;
	if (L<=l && r<=R) return v[h];
	int x=Get(Left),y=Get(Right);
	if (x<y) return y;
	return x;
}

main () {
	scanf("%d%d",&n,&q);
	
	for (int i=1; i<=n; i++) 
		scanf("%d",&w[i]);
	
	w[0]=2e9+1;
	st.push(0);
	
	for (int i=1; i<=n; i++) {
		while (st.size() && w[st.top()]<=w[i]) st.pop();
		Greater[i]=st.top();	
		st.push(i);
	}
	
	for (int i=1; i<=q; i++) {
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		Query[b[i]].push_back(i);
	}
	
	for (int i=1; i<=n; i++) {
		if (Greater[i]) {
			idx=Greater[i],val=w[idx]+w[i];
			Upd(1,1,n);
		}
		
		for (int j=0; j<Query[i].size(); j++) {
			idx=Query[i][j],R=i,L=a[idx];
			if (Get(1,1,n)<=c[idx]) ANS[idx]=1;	
						  	   else ANS[idx]=0;
		}	
	}
	
	for (int i=1; i<=q; i++) 
		printf("%d\n",ANS[i]);
}

Compilation message

sortbooks.cpp:28:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:54:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0; j<Query[i].size(); j++) {
                 ~^~~~~~~~~~~~~~~~
sortbooks.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&w[i]);
   ~~~~~^~~~~~~~~~~~
sortbooks.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&a[i],&b[i],&c[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47352 KB Output is correct
2 Correct 44 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 45 ms 47352 KB Output is correct
5 Correct 45 ms 47352 KB Output is correct
6 Correct 46 ms 47352 KB Output is correct
7 Correct 46 ms 47352 KB Output is correct
8 Correct 46 ms 47336 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 46 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47352 KB Output is correct
2 Correct 44 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 45 ms 47352 KB Output is correct
5 Correct 45 ms 47352 KB Output is correct
6 Correct 46 ms 47352 KB Output is correct
7 Correct 46 ms 47352 KB Output is correct
8 Correct 46 ms 47336 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 46 ms 47352 KB Output is correct
11 Correct 49 ms 47556 KB Output is correct
12 Correct 50 ms 47608 KB Output is correct
13 Correct 51 ms 47648 KB Output is correct
14 Correct 60 ms 47808 KB Output is correct
15 Correct 52 ms 47688 KB Output is correct
16 Correct 53 ms 47608 KB Output is correct
17 Correct 49 ms 47608 KB Output is correct
18 Correct 50 ms 47608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2322 ms 100904 KB Output is correct
2 Correct 2420 ms 100160 KB Output is correct
3 Correct 2379 ms 100392 KB Output is correct
4 Correct 2404 ms 100412 KB Output is correct
5 Correct 1763 ms 91392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 54216 KB Output is correct
2 Correct 177 ms 53512 KB Output is correct
3 Correct 161 ms 52004 KB Output is correct
4 Correct 175 ms 53112 KB Output is correct
5 Correct 163 ms 52296 KB Output is correct
6 Correct 134 ms 52012 KB Output is correct
7 Correct 134 ms 51960 KB Output is correct
8 Correct 155 ms 52808 KB Output is correct
9 Correct 98 ms 50132 KB Output is correct
10 Correct 152 ms 52852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47352 KB Output is correct
2 Correct 44 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 45 ms 47352 KB Output is correct
5 Correct 45 ms 47352 KB Output is correct
6 Correct 46 ms 47352 KB Output is correct
7 Correct 46 ms 47352 KB Output is correct
8 Correct 46 ms 47336 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 46 ms 47352 KB Output is correct
11 Correct 49 ms 47556 KB Output is correct
12 Correct 50 ms 47608 KB Output is correct
13 Correct 51 ms 47648 KB Output is correct
14 Correct 60 ms 47808 KB Output is correct
15 Correct 52 ms 47688 KB Output is correct
16 Correct 53 ms 47608 KB Output is correct
17 Correct 49 ms 47608 KB Output is correct
18 Correct 50 ms 47608 KB Output is correct
19 Correct 403 ms 58028 KB Output is correct
20 Correct 433 ms 57848 KB Output is correct
21 Correct 347 ms 56284 KB Output is correct
22 Correct 337 ms 56184 KB Output is correct
23 Correct 341 ms 56184 KB Output is correct
24 Correct 286 ms 59624 KB Output is correct
25 Correct 283 ms 59680 KB Output is correct
26 Correct 309 ms 60508 KB Output is correct
27 Correct 302 ms 60408 KB Output is correct
28 Correct 421 ms 60920 KB Output is correct
29 Correct 334 ms 61744 KB Output is correct
30 Correct 342 ms 61816 KB Output is correct
31 Correct 335 ms 61688 KB Output is correct
32 Correct 337 ms 61632 KB Output is correct
33 Correct 336 ms 61712 KB Output is correct
34 Correct 255 ms 59416 KB Output is correct
35 Correct 259 ms 59260 KB Output is correct
36 Correct 253 ms 59128 KB Output is correct
37 Correct 253 ms 59020 KB Output is correct
38 Correct 257 ms 59228 KB Output is correct
39 Correct 306 ms 60620 KB Output is correct
40 Correct 237 ms 58344 KB Output is correct
41 Correct 299 ms 59664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47352 KB Output is correct
2 Correct 44 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 45 ms 47352 KB Output is correct
5 Correct 45 ms 47352 KB Output is correct
6 Correct 46 ms 47352 KB Output is correct
7 Correct 46 ms 47352 KB Output is correct
8 Correct 46 ms 47336 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 46 ms 47352 KB Output is correct
11 Correct 49 ms 47556 KB Output is correct
12 Correct 50 ms 47608 KB Output is correct
13 Correct 51 ms 47648 KB Output is correct
14 Correct 60 ms 47808 KB Output is correct
15 Correct 52 ms 47688 KB Output is correct
16 Correct 53 ms 47608 KB Output is correct
17 Correct 49 ms 47608 KB Output is correct
18 Correct 50 ms 47608 KB Output is correct
19 Correct 2322 ms 100904 KB Output is correct
20 Correct 2420 ms 100160 KB Output is correct
21 Correct 2379 ms 100392 KB Output is correct
22 Correct 2404 ms 100412 KB Output is correct
23 Correct 1763 ms 91392 KB Output is correct
24 Correct 195 ms 54216 KB Output is correct
25 Correct 177 ms 53512 KB Output is correct
26 Correct 161 ms 52004 KB Output is correct
27 Correct 175 ms 53112 KB Output is correct
28 Correct 163 ms 52296 KB Output is correct
29 Correct 134 ms 52012 KB Output is correct
30 Correct 134 ms 51960 KB Output is correct
31 Correct 155 ms 52808 KB Output is correct
32 Correct 98 ms 50132 KB Output is correct
33 Correct 152 ms 52852 KB Output is correct
34 Correct 403 ms 58028 KB Output is correct
35 Correct 433 ms 57848 KB Output is correct
36 Correct 347 ms 56284 KB Output is correct
37 Correct 337 ms 56184 KB Output is correct
38 Correct 341 ms 56184 KB Output is correct
39 Correct 286 ms 59624 KB Output is correct
40 Correct 283 ms 59680 KB Output is correct
41 Correct 309 ms 60508 KB Output is correct
42 Correct 302 ms 60408 KB Output is correct
43 Correct 421 ms 60920 KB Output is correct
44 Correct 334 ms 61744 KB Output is correct
45 Correct 342 ms 61816 KB Output is correct
46 Correct 335 ms 61688 KB Output is correct
47 Correct 337 ms 61632 KB Output is correct
48 Correct 336 ms 61712 KB Output is correct
49 Correct 255 ms 59416 KB Output is correct
50 Correct 259 ms 59260 KB Output is correct
51 Correct 253 ms 59128 KB Output is correct
52 Correct 253 ms 59020 KB Output is correct
53 Correct 257 ms 59228 KB Output is correct
54 Correct 306 ms 60620 KB Output is correct
55 Correct 237 ms 58344 KB Output is correct
56 Correct 299 ms 59664 KB Output is correct
57 Correct 2224 ms 126608 KB Output is correct
58 Correct 2229 ms 127432 KB Output is correct
59 Correct 2107 ms 124040 KB Output is correct
60 Correct 2138 ms 123436 KB Output is correct
61 Correct 2169 ms 123520 KB Output is correct
62 Correct 2114 ms 123540 KB Output is correct
63 Correct 1354 ms 107176 KB Output is correct
64 Correct 1354 ms 106628 KB Output is correct
65 Correct 1776 ms 113752 KB Output is correct
66 Correct 1693 ms 115176 KB Output is correct
67 Correct 1733 ms 114492 KB Output is correct
68 Correct 1995 ms 120008 KB Output is correct
69 Correct 1853 ms 118848 KB Output is correct
70 Correct 1819 ms 119256 KB Output is correct
71 Correct 1771 ms 119172 KB Output is correct
72 Correct 1853 ms 119084 KB Output is correct
73 Correct 1271 ms 105848 KB Output is correct
74 Correct 1292 ms 106824 KB Output is correct
75 Correct 1283 ms 105896 KB Output is correct
76 Correct 1305 ms 105720 KB Output is correct
77 Correct 1298 ms 105556 KB Output is correct
78 Correct 1589 ms 114444 KB Output is correct
79 Correct 1156 ms 100660 KB Output is correct
80 Correct 1543 ms 109640 KB Output is correct