답안 #396014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396014 2021-04-29T11:12:16 Z andremfq Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1562 ms 122076 KB
//nossa ideia estava certa! obs principal se a resposta for i e j, entao i eh o proximo maior que j pela esquerda
#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:62:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   62 |  scanf("%d %d", &N, &M ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:63:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |  for(int i = 1 ; i <= N ; i++ ) scanf("%lld", &w[i] ) ;
      |                                 ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   78 |   scanf("%d %d %lld", &L[i], &R[i] , &K[i]) ;
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 5 ms 8140 KB Output is correct
3 Correct 7 ms 8140 KB Output is correct
4 Correct 6 ms 8140 KB Output is correct
5 Correct 5 ms 8084 KB Output is correct
6 Correct 6 ms 8140 KB Output is correct
7 Correct 6 ms 8140 KB Output is correct
8 Correct 6 ms 8140 KB Output is correct
9 Correct 6 ms 8140 KB Output is correct
10 Correct 5 ms 8140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 5 ms 8140 KB Output is correct
3 Correct 7 ms 8140 KB Output is correct
4 Correct 6 ms 8140 KB Output is correct
5 Correct 5 ms 8084 KB Output is correct
6 Correct 6 ms 8140 KB Output is correct
7 Correct 6 ms 8140 KB Output is correct
8 Correct 6 ms 8140 KB Output is correct
9 Correct 6 ms 8140 KB Output is correct
10 Correct 5 ms 8140 KB Output is correct
11 Correct 8 ms 8524 KB Output is correct
12 Correct 8 ms 8588 KB Output is correct
13 Correct 9 ms 8716 KB Output is correct
14 Correct 10 ms 8856 KB Output is correct
15 Correct 10 ms 8844 KB Output is correct
16 Correct 10 ms 8716 KB Output is correct
17 Correct 9 ms 8588 KB Output is correct
18 Correct 9 ms 8844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1436 ms 120268 KB Output is correct
2 Correct 1470 ms 121508 KB Output is correct
3 Correct 1444 ms 121168 KB Output is correct
4 Correct 1423 ms 121336 KB Output is correct
5 Correct 1133 ms 97828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 18204 KB Output is correct
2 Correct 107 ms 18192 KB Output is correct
3 Correct 87 ms 15868 KB Output is correct
4 Correct 92 ms 15920 KB Output is correct
5 Correct 86 ms 15916 KB Output is correct
6 Correct 86 ms 16004 KB Output is correct
7 Correct 81 ms 15952 KB Output is correct
8 Correct 94 ms 17768 KB Output is correct
9 Correct 70 ms 13996 KB Output is correct
10 Correct 89 ms 18236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 5 ms 8140 KB Output is correct
3 Correct 7 ms 8140 KB Output is correct
4 Correct 6 ms 8140 KB Output is correct
5 Correct 5 ms 8084 KB Output is correct
6 Correct 6 ms 8140 KB Output is correct
7 Correct 6 ms 8140 KB Output is correct
8 Correct 6 ms 8140 KB Output is correct
9 Correct 6 ms 8140 KB Output is correct
10 Correct 5 ms 8140 KB Output is correct
11 Correct 8 ms 8524 KB Output is correct
12 Correct 8 ms 8588 KB Output is correct
13 Correct 9 ms 8716 KB Output is correct
14 Correct 10 ms 8856 KB Output is correct
15 Correct 10 ms 8844 KB Output is correct
16 Correct 10 ms 8716 KB Output is correct
17 Correct 9 ms 8588 KB Output is correct
18 Correct 9 ms 8844 KB Output is correct
19 Correct 244 ms 30856 KB Output is correct
20 Correct 267 ms 30972 KB Output is correct
21 Correct 243 ms 30668 KB Output is correct
22 Correct 251 ms 30760 KB Output is correct
23 Correct 259 ms 30736 KB Output is correct
24 Correct 189 ms 25916 KB Output is correct
25 Correct 194 ms 25872 KB Output is correct
26 Correct 197 ms 26088 KB Output is correct
27 Correct 198 ms 26156 KB Output is correct
28 Correct 200 ms 26116 KB Output is correct
29 Correct 196 ms 26164 KB Output is correct
30 Correct 195 ms 26284 KB Output is correct
31 Correct 204 ms 26140 KB Output is correct
32 Correct 205 ms 26148 KB Output is correct
33 Correct 196 ms 26304 KB Output is correct
34 Correct 204 ms 25956 KB Output is correct
35 Correct 175 ms 25908 KB Output is correct
36 Correct 181 ms 25608 KB Output is correct
37 Correct 172 ms 25792 KB Output is correct
38 Correct 171 ms 25760 KB Output is correct
39 Correct 202 ms 31112 KB Output is correct
40 Correct 171 ms 24064 KB Output is correct
41 Correct 187 ms 29084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 5 ms 8140 KB Output is correct
3 Correct 7 ms 8140 KB Output is correct
4 Correct 6 ms 8140 KB Output is correct
5 Correct 5 ms 8084 KB Output is correct
6 Correct 6 ms 8140 KB Output is correct
7 Correct 6 ms 8140 KB Output is correct
8 Correct 6 ms 8140 KB Output is correct
9 Correct 6 ms 8140 KB Output is correct
10 Correct 5 ms 8140 KB Output is correct
11 Correct 8 ms 8524 KB Output is correct
12 Correct 8 ms 8588 KB Output is correct
13 Correct 9 ms 8716 KB Output is correct
14 Correct 10 ms 8856 KB Output is correct
15 Correct 10 ms 8844 KB Output is correct
16 Correct 10 ms 8716 KB Output is correct
17 Correct 9 ms 8588 KB Output is correct
18 Correct 9 ms 8844 KB Output is correct
19 Correct 1436 ms 120268 KB Output is correct
20 Correct 1470 ms 121508 KB Output is correct
21 Correct 1444 ms 121168 KB Output is correct
22 Correct 1423 ms 121336 KB Output is correct
23 Correct 1133 ms 97828 KB Output is correct
24 Correct 105 ms 18204 KB Output is correct
25 Correct 107 ms 18192 KB Output is correct
26 Correct 87 ms 15868 KB Output is correct
27 Correct 92 ms 15920 KB Output is correct
28 Correct 86 ms 15916 KB Output is correct
29 Correct 86 ms 16004 KB Output is correct
30 Correct 81 ms 15952 KB Output is correct
31 Correct 94 ms 17768 KB Output is correct
32 Correct 70 ms 13996 KB Output is correct
33 Correct 89 ms 18236 KB Output is correct
34 Correct 244 ms 30856 KB Output is correct
35 Correct 267 ms 30972 KB Output is correct
36 Correct 243 ms 30668 KB Output is correct
37 Correct 251 ms 30760 KB Output is correct
38 Correct 259 ms 30736 KB Output is correct
39 Correct 189 ms 25916 KB Output is correct
40 Correct 194 ms 25872 KB Output is correct
41 Correct 197 ms 26088 KB Output is correct
42 Correct 198 ms 26156 KB Output is correct
43 Correct 200 ms 26116 KB Output is correct
44 Correct 196 ms 26164 KB Output is correct
45 Correct 195 ms 26284 KB Output is correct
46 Correct 204 ms 26140 KB Output is correct
47 Correct 205 ms 26148 KB Output is correct
48 Correct 196 ms 26304 KB Output is correct
49 Correct 204 ms 25956 KB Output is correct
50 Correct 175 ms 25908 KB Output is correct
51 Correct 181 ms 25608 KB Output is correct
52 Correct 172 ms 25792 KB Output is correct
53 Correct 171 ms 25760 KB Output is correct
54 Correct 202 ms 31112 KB Output is correct
55 Correct 171 ms 24064 KB Output is correct
56 Correct 187 ms 29084 KB Output is correct
57 Correct 1452 ms 122036 KB Output is correct
58 Correct 1529 ms 122012 KB Output is correct
59 Correct 1515 ms 121912 KB Output is correct
60 Correct 1562 ms 122076 KB Output is correct
61 Correct 1491 ms 122020 KB Output is correct
62 Correct 1509 ms 121976 KB Output is correct
63 Correct 1039 ms 96580 KB Output is correct
64 Correct 997 ms 96540 KB Output is correct
65 Correct 1114 ms 96472 KB Output is correct
66 Correct 1114 ms 96072 KB Output is correct
67 Correct 1119 ms 93800 KB Output is correct
68 Correct 1112 ms 88520 KB Output is correct
69 Correct 1098 ms 83320 KB Output is correct
70 Correct 1133 ms 81936 KB Output is correct
71 Correct 1099 ms 81644 KB Output is correct
72 Correct 1100 ms 81644 KB Output is correct
73 Correct 827 ms 95180 KB Output is correct
74 Correct 870 ms 96048 KB Output is correct
75 Correct 840 ms 95080 KB Output is correct
76 Correct 835 ms 95068 KB Output is correct
77 Correct 858 ms 95000 KB Output is correct
78 Correct 1177 ms 102168 KB Output is correct
79 Correct 890 ms 99204 KB Output is correct
80 Correct 1162 ms 106304 KB Output is correct