답안 #218341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218341 2020-04-02T03:08:04 Z Lawliet Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1762 ms 101304 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1000010;
const int INF = 1000000010;

struct query
{
	int L, K;
	int ind;

	query(int l, int k, int i)
		: L(l), K(k), ind(i) {}
};

class SegmentTree
{
	public:

		int getLeft(int node) { return 2*node; }
		int getRight(int node) { return 2*node + 1; }

		void update(int node, int l, int r, int i, int v)
		{
			if( i < l || r < i ) return;

			if( l == r )
			{
				mx[node] = max( mx[node] , v );
				return;
			}

			int m = ( l + r )/2;

			update( getLeft(node) , l , m , i , v );
			update( getRight(node) , m + 1 , r , i , v );

			mx[node] = max( mx[ getLeft(node) ] , mx[ getRight(node) ] );
		}

		int query(int node, int l, int r, int i, int j)
		{
			if( j < l || r < i ) return 0;
			if( i <= l && r <= j ) return mx[node];

			int m = ( l + r )/2;

			int maxLeft = query( getLeft(node) , l , m , i , j );
			int maxRight = query( getRight(node) , m + 1 , r , i , j );

			return max( maxLeft , maxRight );
		}

		SegmentTree() { memset( mx , 0 , sizeof(mx) ); }

	private:

		int mx[4*MAXN];
};

int n, q;

int v[MAXN];

bool ans[MAXN];

vector< int > s;

vector< query > sweep[MAXN];

SegmentTree SEG;

int main()
{
	scanf("%d %d",&n,&q);

	v[0] = INF;
	s.push_back( 0 );

	for(int i = 1 ; i <= n ; i++)
		scanf("%d",&v[i]);

	for(int i = 1 ; i <= q ; i++)
	{
		int L, R, k;
		scanf("%d %d %d",&L,&R,&k);

		sweep[R].push_back( query( L , k , i ) );
	}

	for(int i = 1 ; i <= n ; i++)
	{
		while( v[ s.back() ] <= v[i] )
			s.pop_back();

		if( s.back() != 0 )
		{
			int ind = s.back();
			SEG.update( 1 , 1 , n , ind , v[ind] + v[i] );
		}

		s.push_back( i );

		while( !sweep[i].empty() )
		{
			int curL = sweep[i].back().L;
			int curK = sweep[i].back().K;
			int curInd = sweep[i].back().ind;
			sweep[i].pop_back();

			ans[curInd] = ( SEG.query( 1 , 1 , n , curL , i ) <= curK );
		}
	}

	for(int i = 1 ; i <= q ; i++)
	{
		if( ans[i] ) printf("1\n");
		else printf("0\n");
	}
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:76: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:82:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&v[i]);
   ~~~~~^~~~~~~~~~~~
sortbooks.cpp:87: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 39424 KB Output is correct
2 Correct 25 ms 39552 KB Output is correct
3 Correct 27 ms 39552 KB Output is correct
4 Correct 25 ms 39424 KB Output is correct
5 Correct 29 ms 39552 KB Output is correct
6 Correct 25 ms 39552 KB Output is correct
7 Correct 26 ms 39552 KB Output is correct
8 Correct 25 ms 39552 KB Output is correct
9 Correct 26 ms 39424 KB Output is correct
10 Correct 25 ms 39424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 39424 KB Output is correct
2 Correct 25 ms 39552 KB Output is correct
3 Correct 27 ms 39552 KB Output is correct
4 Correct 25 ms 39424 KB Output is correct
5 Correct 29 ms 39552 KB Output is correct
6 Correct 25 ms 39552 KB Output is correct
7 Correct 26 ms 39552 KB Output is correct
8 Correct 25 ms 39552 KB Output is correct
9 Correct 26 ms 39424 KB Output is correct
10 Correct 25 ms 39424 KB Output is correct
11 Correct 29 ms 39552 KB Output is correct
12 Correct 28 ms 39552 KB Output is correct
13 Correct 30 ms 39672 KB Output is correct
14 Correct 31 ms 39800 KB Output is correct
15 Correct 31 ms 39808 KB Output is correct
16 Correct 30 ms 39680 KB Output is correct
17 Correct 30 ms 39680 KB Output is correct
18 Correct 28 ms 39680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1762 ms 68320 KB Output is correct
2 Correct 1686 ms 101112 KB Output is correct
3 Correct 1655 ms 100928 KB Output is correct
4 Correct 1636 ms 101240 KB Output is correct
5 Correct 1449 ms 101164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 42464 KB Output is correct
2 Correct 126 ms 44024 KB Output is correct
3 Correct 119 ms 44152 KB Output is correct
4 Correct 125 ms 44280 KB Output is correct
5 Correct 130 ms 44412 KB Output is correct
6 Correct 106 ms 43640 KB Output is correct
7 Correct 101 ms 43688 KB Output is correct
8 Correct 130 ms 43824 KB Output is correct
9 Correct 74 ms 42684 KB Output is correct
10 Correct 112 ms 43832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 39424 KB Output is correct
2 Correct 25 ms 39552 KB Output is correct
3 Correct 27 ms 39552 KB Output is correct
4 Correct 25 ms 39424 KB Output is correct
5 Correct 29 ms 39552 KB Output is correct
6 Correct 25 ms 39552 KB Output is correct
7 Correct 26 ms 39552 KB Output is correct
8 Correct 25 ms 39552 KB Output is correct
9 Correct 26 ms 39424 KB Output is correct
10 Correct 25 ms 39424 KB Output is correct
11 Correct 29 ms 39552 KB Output is correct
12 Correct 28 ms 39552 KB Output is correct
13 Correct 30 ms 39672 KB Output is correct
14 Correct 31 ms 39800 KB Output is correct
15 Correct 31 ms 39808 KB Output is correct
16 Correct 30 ms 39680 KB Output is correct
17 Correct 30 ms 39680 KB Output is correct
18 Correct 28 ms 39680 KB Output is correct
19 Correct 298 ms 51704 KB Output is correct
20 Correct 306 ms 51772 KB Output is correct
21 Correct 255 ms 51064 KB Output is correct
22 Correct 254 ms 51064 KB Output is correct
23 Correct 256 ms 51064 KB Output is correct
24 Correct 211 ms 50808 KB Output is correct
25 Correct 216 ms 51088 KB Output is correct
26 Correct 239 ms 51192 KB Output is correct
27 Correct 238 ms 51192 KB Output is correct
28 Correct 243 ms 51320 KB Output is correct
29 Correct 255 ms 51704 KB Output is correct
30 Correct 275 ms 51932 KB Output is correct
31 Correct 258 ms 51704 KB Output is correct
32 Correct 251 ms 51708 KB Output is correct
33 Correct 257 ms 51704 KB Output is correct
34 Correct 190 ms 50424 KB Output is correct
35 Correct 191 ms 50296 KB Output is correct
36 Correct 183 ms 50168 KB Output is correct
37 Correct 191 ms 50168 KB Output is correct
38 Correct 194 ms 50424 KB Output is correct
39 Correct 239 ms 49964 KB Output is correct
40 Correct 184 ms 48556 KB Output is correct
41 Correct 237 ms 49588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 39424 KB Output is correct
2 Correct 25 ms 39552 KB Output is correct
3 Correct 27 ms 39552 KB Output is correct
4 Correct 25 ms 39424 KB Output is correct
5 Correct 29 ms 39552 KB Output is correct
6 Correct 25 ms 39552 KB Output is correct
7 Correct 26 ms 39552 KB Output is correct
8 Correct 25 ms 39552 KB Output is correct
9 Correct 26 ms 39424 KB Output is correct
10 Correct 25 ms 39424 KB Output is correct
11 Correct 29 ms 39552 KB Output is correct
12 Correct 28 ms 39552 KB Output is correct
13 Correct 30 ms 39672 KB Output is correct
14 Correct 31 ms 39800 KB Output is correct
15 Correct 31 ms 39808 KB Output is correct
16 Correct 30 ms 39680 KB Output is correct
17 Correct 30 ms 39680 KB Output is correct
18 Correct 28 ms 39680 KB Output is correct
19 Correct 1762 ms 68320 KB Output is correct
20 Correct 1686 ms 101112 KB Output is correct
21 Correct 1655 ms 100928 KB Output is correct
22 Correct 1636 ms 101240 KB Output is correct
23 Correct 1449 ms 101164 KB Output is correct
24 Correct 145 ms 42464 KB Output is correct
25 Correct 126 ms 44024 KB Output is correct
26 Correct 119 ms 44152 KB Output is correct
27 Correct 125 ms 44280 KB Output is correct
28 Correct 130 ms 44412 KB Output is correct
29 Correct 106 ms 43640 KB Output is correct
30 Correct 101 ms 43688 KB Output is correct
31 Correct 130 ms 43824 KB Output is correct
32 Correct 74 ms 42684 KB Output is correct
33 Correct 112 ms 43832 KB Output is correct
34 Correct 298 ms 51704 KB Output is correct
35 Correct 306 ms 51772 KB Output is correct
36 Correct 255 ms 51064 KB Output is correct
37 Correct 254 ms 51064 KB Output is correct
38 Correct 256 ms 51064 KB Output is correct
39 Correct 211 ms 50808 KB Output is correct
40 Correct 216 ms 51088 KB Output is correct
41 Correct 239 ms 51192 KB Output is correct
42 Correct 238 ms 51192 KB Output is correct
43 Correct 243 ms 51320 KB Output is correct
44 Correct 255 ms 51704 KB Output is correct
45 Correct 275 ms 51932 KB Output is correct
46 Correct 258 ms 51704 KB Output is correct
47 Correct 251 ms 51708 KB Output is correct
48 Correct 257 ms 51704 KB Output is correct
49 Correct 190 ms 50424 KB Output is correct
50 Correct 191 ms 50296 KB Output is correct
51 Correct 183 ms 50168 KB Output is correct
52 Correct 191 ms 50168 KB Output is correct
53 Correct 194 ms 50424 KB Output is correct
54 Correct 239 ms 49964 KB Output is correct
55 Correct 184 ms 48556 KB Output is correct
56 Correct 237 ms 49588 KB Output is correct
57 Correct 1648 ms 101172 KB Output is correct
58 Correct 1645 ms 101304 KB Output is correct
59 Correct 1537 ms 99716 KB Output is correct
60 Correct 1573 ms 99696 KB Output is correct
61 Correct 1574 ms 99704 KB Output is correct
62 Correct 1539 ms 99668 KB Output is correct
63 Correct 994 ms 95868 KB Output is correct
64 Correct 1000 ms 95732 KB Output is correct
65 Correct 1343 ms 99576 KB Output is correct
66 Correct 1346 ms 99444 KB Output is correct
67 Correct 1371 ms 99640 KB Output is correct
68 Correct 1463 ms 101236 KB Output is correct
69 Correct 1474 ms 101292 KB Output is correct
70 Correct 1435 ms 100848 KB Output is correct
71 Correct 1441 ms 101016 KB Output is correct
72 Correct 1435 ms 100904 KB Output is correct
73 Correct 886 ms 92168 KB Output is correct
74 Correct 874 ms 93304 KB Output is correct
75 Correct 894 ms 92024 KB Output is correct
76 Correct 890 ms 92152 KB Output is correct
77 Correct 859 ms 92152 KB Output is correct
78 Correct 1286 ms 93324 KB Output is correct
79 Correct 892 ms 84372 KB Output is correct
80 Correct 1204 ms 90392 KB Output is correct