Submission #395794

# Submission time Handle Problem Language Result Execution time Memory
395794 2021-04-28T23:36:07 Z CaroLinda Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1519 ms 122208 KB
#include <bits/stdc++.h>

#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)(x.size())

const int MAXN = 1e6+10 ;
const ll inf = 1e15+10 ;

using namespace std ;

struct Event
{
	bool type ; //0 is an object, 1 is a query
	ll weight ;
	int id ;

	Event(bool type = 0 , ll weight = 0 , int id =0 ) : 
	type(type) , weight(weight) , id(id) {}

	bool operator < ( Event other ) const
	{
		if(weight != other.weight) return weight > other.weight ;
		return type > other.type ;
	}

} ;

struct Seg
{
	int n ;
	int tree[MAXN*2] ;

	Seg() { for(int i= 0 ; i <MAXN*2 ; i++ ) tree[i] = -2 ; }

	void upd(int pos, int val) { for(pos += n ; pos > 0 ; pos >>= 1) tree[pos] = max(tree[pos] , val) ; }
	int qry(int l, int r)
	{
		int ans = -2 ;
		for(l += n , r += n ; l < r ; l >>= 1 , r >>= 1) 
		{
			if(l&1) ans = max(ans, tree[l++]) ;
			if(r&1) ans = max(ans, tree[--r]) ;
		}
		return ans ;
	}

} seg ;

int N , M ;
int lef[MAXN] , L[MAXN] , R[MAXN] ;
int ans[MAXN] ;
ll w[MAXN] , K[MAXN] ;
vector<Event> sweep ;

int main()
{	
	scanf("%d %d", &N, &M ) ;
	for(int i = 1 ; i <= N ; i++ ) scanf("%lld", &w[i] ) ;

	w[0] = inf;
	seg.n = N ;

	for(int i = 1 ;i <= N ; i++ )
	{
		lef[i] = i-1 ;
		while( w[lef[i]] <= w[i] ) lef[i] = lef[ lef[i] ] ;

		if(lef[i]) sweep.push_back( Event(0, w[lef[i]]+w[i] , i) ) ;
	}

	for(int i = 1 ; i <= M ; i++ )
	{
		scanf("%d %d %lld", &L[i], &R[i] , &K[i]) ;
		sweep.push_back( Event(1, K[i], i) ) ;
	}

	sort(all(sweep) );

	for(auto e : sweep )
	{		
		if(!e.type) seg.upd( e.id-1 , lef[e.id] ) ;
		else ans[e.id] = (seg.qry( L[e.id]-1 , R[e.id] ) < L[e.id]) ;
	}

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

}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |  scanf("%d %d", &N, &M ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:62:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   62 |  for(int i = 1 ; i <= N ; i++ ) scanf("%lld", &w[i] ) ;
      |                                 ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   77 |   scanf("%d %d %lld", &L[i], &R[i] , &K[i]) ;
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 5 ms 8128 KB Output is correct
3 Correct 5 ms 8160 KB Output is correct
4 Correct 5 ms 8140 KB Output is correct
5 Correct 5 ms 8140 KB Output is correct
6 Correct 6 ms 8240 KB Output is correct
7 Correct 5 ms 8144 KB Output is correct
8 Correct 5 ms 8140 KB Output is correct
9 Correct 5 ms 8132 KB Output is correct
10 Correct 5 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 5 ms 8128 KB Output is correct
3 Correct 5 ms 8160 KB Output is correct
4 Correct 5 ms 8140 KB Output is correct
5 Correct 5 ms 8140 KB Output is correct
6 Correct 6 ms 8240 KB Output is correct
7 Correct 5 ms 8144 KB Output is correct
8 Correct 5 ms 8140 KB Output is correct
9 Correct 5 ms 8132 KB Output is correct
10 Correct 5 ms 8140 KB Output is correct
11 Correct 7 ms 8524 KB Output is correct
12 Correct 8 ms 8588 KB Output is correct
13 Correct 10 ms 8716 KB Output is correct
14 Correct 10 ms 8844 KB Output is correct
15 Correct 10 ms 8832 KB Output is correct
16 Correct 9 ms 8636 KB Output is correct
17 Correct 8 ms 8652 KB Output is correct
18 Correct 8 ms 8844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1441 ms 120420 KB Output is correct
2 Correct 1361 ms 121404 KB Output is correct
3 Correct 1403 ms 121224 KB Output is correct
4 Correct 1400 ms 121540 KB Output is correct
5 Correct 1105 ms 98028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 18212 KB Output is correct
2 Correct 114 ms 18304 KB Output is correct
3 Correct 88 ms 15932 KB Output is correct
4 Correct 88 ms 15948 KB Output is correct
5 Correct 85 ms 15908 KB Output is correct
6 Correct 77 ms 15948 KB Output is correct
7 Correct 80 ms 16048 KB Output is correct
8 Correct 89 ms 17768 KB Output is correct
9 Correct 63 ms 14088 KB Output is correct
10 Correct 86 ms 18228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 5 ms 8128 KB Output is correct
3 Correct 5 ms 8160 KB Output is correct
4 Correct 5 ms 8140 KB Output is correct
5 Correct 5 ms 8140 KB Output is correct
6 Correct 6 ms 8240 KB Output is correct
7 Correct 5 ms 8144 KB Output is correct
8 Correct 5 ms 8140 KB Output is correct
9 Correct 5 ms 8132 KB Output is correct
10 Correct 5 ms 8140 KB Output is correct
11 Correct 7 ms 8524 KB Output is correct
12 Correct 8 ms 8588 KB Output is correct
13 Correct 10 ms 8716 KB Output is correct
14 Correct 10 ms 8844 KB Output is correct
15 Correct 10 ms 8832 KB Output is correct
16 Correct 9 ms 8636 KB Output is correct
17 Correct 8 ms 8652 KB Output is correct
18 Correct 8 ms 8844 KB Output is correct
19 Correct 243 ms 31124 KB Output is correct
20 Correct 241 ms 30948 KB Output is correct
21 Correct 270 ms 30740 KB Output is correct
22 Correct 249 ms 30852 KB Output is correct
23 Correct 255 ms 30672 KB Output is correct
24 Correct 183 ms 25900 KB Output is correct
25 Correct 190 ms 25936 KB Output is correct
26 Correct 194 ms 26132 KB Output is correct
27 Correct 211 ms 26108 KB Output is correct
28 Correct 194 ms 26096 KB Output is correct
29 Correct 190 ms 26168 KB Output is correct
30 Correct 193 ms 26200 KB Output is correct
31 Correct 190 ms 26132 KB Output is correct
32 Correct 222 ms 26300 KB Output is correct
33 Correct 192 ms 26212 KB Output is correct
34 Correct 171 ms 25820 KB Output is correct
35 Correct 169 ms 25808 KB Output is correct
36 Correct 167 ms 25660 KB Output is correct
37 Correct 164 ms 25640 KB Output is correct
38 Correct 178 ms 25820 KB Output is correct
39 Correct 202 ms 31124 KB Output is correct
40 Correct 164 ms 24056 KB Output is correct
41 Correct 186 ms 29024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 5 ms 8128 KB Output is correct
3 Correct 5 ms 8160 KB Output is correct
4 Correct 5 ms 8140 KB Output is correct
5 Correct 5 ms 8140 KB Output is correct
6 Correct 6 ms 8240 KB Output is correct
7 Correct 5 ms 8144 KB Output is correct
8 Correct 5 ms 8140 KB Output is correct
9 Correct 5 ms 8132 KB Output is correct
10 Correct 5 ms 8140 KB Output is correct
11 Correct 7 ms 8524 KB Output is correct
12 Correct 8 ms 8588 KB Output is correct
13 Correct 10 ms 8716 KB Output is correct
14 Correct 10 ms 8844 KB Output is correct
15 Correct 10 ms 8832 KB Output is correct
16 Correct 9 ms 8636 KB Output is correct
17 Correct 8 ms 8652 KB Output is correct
18 Correct 8 ms 8844 KB Output is correct
19 Correct 1441 ms 120420 KB Output is correct
20 Correct 1361 ms 121404 KB Output is correct
21 Correct 1403 ms 121224 KB Output is correct
22 Correct 1400 ms 121540 KB Output is correct
23 Correct 1105 ms 98028 KB Output is correct
24 Correct 103 ms 18212 KB Output is correct
25 Correct 114 ms 18304 KB Output is correct
26 Correct 88 ms 15932 KB Output is correct
27 Correct 88 ms 15948 KB Output is correct
28 Correct 85 ms 15908 KB Output is correct
29 Correct 77 ms 15948 KB Output is correct
30 Correct 80 ms 16048 KB Output is correct
31 Correct 89 ms 17768 KB Output is correct
32 Correct 63 ms 14088 KB Output is correct
33 Correct 86 ms 18228 KB Output is correct
34 Correct 243 ms 31124 KB Output is correct
35 Correct 241 ms 30948 KB Output is correct
36 Correct 270 ms 30740 KB Output is correct
37 Correct 249 ms 30852 KB Output is correct
38 Correct 255 ms 30672 KB Output is correct
39 Correct 183 ms 25900 KB Output is correct
40 Correct 190 ms 25936 KB Output is correct
41 Correct 194 ms 26132 KB Output is correct
42 Correct 211 ms 26108 KB Output is correct
43 Correct 194 ms 26096 KB Output is correct
44 Correct 190 ms 26168 KB Output is correct
45 Correct 193 ms 26200 KB Output is correct
46 Correct 190 ms 26132 KB Output is correct
47 Correct 222 ms 26300 KB Output is correct
48 Correct 192 ms 26212 KB Output is correct
49 Correct 171 ms 25820 KB Output is correct
50 Correct 169 ms 25808 KB Output is correct
51 Correct 167 ms 25660 KB Output is correct
52 Correct 164 ms 25640 KB Output is correct
53 Correct 178 ms 25820 KB Output is correct
54 Correct 202 ms 31124 KB Output is correct
55 Correct 164 ms 24056 KB Output is correct
56 Correct 186 ms 29024 KB Output is correct
57 Correct 1519 ms 122108 KB Output is correct
58 Correct 1482 ms 122208 KB Output is correct
59 Correct 1442 ms 122068 KB Output is correct
60 Correct 1463 ms 121924 KB Output is correct
61 Correct 1442 ms 121912 KB Output is correct
62 Correct 1454 ms 121908 KB Output is correct
63 Correct 1034 ms 96652 KB Output is correct
64 Correct 1026 ms 96848 KB Output is correct
65 Correct 1132 ms 98432 KB Output is correct
66 Correct 1111 ms 98504 KB Output is correct
67 Correct 1119 ms 98092 KB Output is correct
68 Correct 1115 ms 98260 KB Output is correct
69 Correct 1115 ms 98284 KB Output is correct
70 Correct 1120 ms 98360 KB Output is correct
71 Correct 1113 ms 98396 KB Output is correct
72 Correct 1127 ms 98616 KB Output is correct
73 Correct 829 ms 95168 KB Output is correct
74 Correct 846 ms 96168 KB Output is correct
75 Correct 845 ms 94916 KB Output is correct
76 Correct 837 ms 95000 KB Output is correct
77 Correct 848 ms 94872 KB Output is correct
78 Correct 1158 ms 102116 KB Output is correct
79 Correct 877 ms 98944 KB Output is correct
80 Correct 1085 ms 106232 KB Output is correct