Submission #286910

# Submission time Handle Problem Language Result Execution time Memory
286910 2020-08-31T07:00:25 Z dvdg6566 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2017 ms 166008 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define pb emplace_back
#define mp make_pair
#define f first
#define s second
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()
#define lb lower_bound
const int MAXN=1001000;
const ll MOD=998244353;

int A[MAXN];
int N,Q,a,b,c;

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){
			l=new node(s,m);
			r=new node(m+1,e);
			v=max(l->v,r->v);
		}
	}
	int ask(int a,int b){
		if(a==s&&e==b)return v;
		if(b<=m)return l->ask(a,b);
		if(a>m)return r->ask(a,b);
		return max(l->ask(a,m),r->ask(m+1,b));
	}
	void up(int x,int va){
		if(s==e){
			v=max(va,v);
			return;
		}
		if(x<=m)l->up(x,va);
		else r->up(x,va);
		v=max(l->v,r->v);
	}
}*root;

int fs[MAXN];
vpi V;
int endpt[MAXN];
typedef pair<int,pi> pp;
vector<pp> queries[MAXN];
int out[MAXN];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>N>>Q;
	for(int i=1;i<=N;++i){
		cin>>A[i];
	}
	root=new node(1,N);
	stack<int> S;
	for(int i=1;i<=N;++i){
		while(SZ(S) && A[S.top()] <= A[i]){
			S.pop();
		}
		if(SZ(S)){
			// V.pb(S.top(),i);
			endpt[i]=S.top();
		}
		S.push(i);
	}
	for(int i=0;i<Q;++i){
		cin>>a>>b>>c;
		queries[b].pb(i,mp(a,c));
	}

	for(int e=1;e<=N;++e){
		if(endpt[e]){
			root->up(endpt[e], A[endpt[e]] + A[e]);
			// cerr<<"Up "<<endpt[e]<<' '<<A[endpt[e]]+A[e]<<'\n';
		}
		for(auto i:queries[e]){
			int t=root->ask(i.s.f, e);
			if(t<=i.s.s)out[i.f]=1;
			// cerr<<t<<' '<<i.s.s<<'\n';
		}
	}

	for(int i=0;i<Q;++i){
		cout<<out[i]<<'\n';
	}

}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23936 KB Output is correct
4 Correct 16 ms 23936 KB Output is correct
5 Correct 17 ms 23936 KB Output is correct
6 Correct 17 ms 23936 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 17 ms 23936 KB Output is correct
9 Correct 16 ms 23936 KB Output is correct
10 Correct 17 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23936 KB Output is correct
4 Correct 16 ms 23936 KB Output is correct
5 Correct 17 ms 23936 KB Output is correct
6 Correct 17 ms 23936 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 17 ms 23936 KB Output is correct
9 Correct 16 ms 23936 KB Output is correct
10 Correct 17 ms 23936 KB Output is correct
11 Correct 18 ms 24192 KB Output is correct
12 Correct 20 ms 24448 KB Output is correct
13 Correct 21 ms 24448 KB Output is correct
14 Correct 21 ms 24576 KB Output is correct
15 Correct 22 ms 24576 KB Output is correct
16 Correct 20 ms 24576 KB Output is correct
17 Correct 20 ms 24448 KB Output is correct
18 Correct 20 ms 24576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2017 ms 160376 KB Output is correct
2 Correct 1930 ms 160760 KB Output is correct
3 Correct 2005 ms 160888 KB Output is correct
4 Correct 1962 ms 160640 KB Output is correct
5 Correct 1819 ms 160632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 38788 KB Output is correct
2 Correct 120 ms 39160 KB Output is correct
3 Correct 126 ms 38648 KB Output is correct
4 Correct 139 ms 38520 KB Output is correct
5 Correct 129 ms 38520 KB Output is correct
6 Correct 97 ms 38264 KB Output is correct
7 Correct 95 ms 38264 KB Output is correct
8 Correct 122 ms 38712 KB Output is correct
9 Correct 58 ms 28332 KB Output is correct
10 Correct 115 ms 38580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23936 KB Output is correct
4 Correct 16 ms 23936 KB Output is correct
5 Correct 17 ms 23936 KB Output is correct
6 Correct 17 ms 23936 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 17 ms 23936 KB Output is correct
9 Correct 16 ms 23936 KB Output is correct
10 Correct 17 ms 23936 KB Output is correct
11 Correct 18 ms 24192 KB Output is correct
12 Correct 20 ms 24448 KB Output is correct
13 Correct 21 ms 24448 KB Output is correct
14 Correct 21 ms 24576 KB Output is correct
15 Correct 22 ms 24576 KB Output is correct
16 Correct 20 ms 24576 KB Output is correct
17 Correct 20 ms 24448 KB Output is correct
18 Correct 20 ms 24576 KB Output is correct
19 Correct 339 ms 53496 KB Output is correct
20 Correct 337 ms 53624 KB Output is correct
21 Correct 252 ms 54136 KB Output is correct
22 Correct 250 ms 54136 KB Output is correct
23 Correct 251 ms 53980 KB Output is correct
24 Correct 207 ms 53240 KB Output is correct
25 Correct 209 ms 53240 KB Output is correct
26 Correct 262 ms 52728 KB Output is correct
27 Correct 261 ms 52344 KB Output is correct
28 Correct 274 ms 52216 KB Output is correct
29 Correct 304 ms 51960 KB Output is correct
30 Correct 297 ms 51960 KB Output is correct
31 Correct 301 ms 51960 KB Output is correct
32 Correct 292 ms 51960 KB Output is correct
33 Correct 298 ms 51960 KB Output is correct
34 Correct 199 ms 51960 KB Output is correct
35 Correct 195 ms 52088 KB Output is correct
36 Correct 195 ms 51960 KB Output is correct
37 Correct 190 ms 51960 KB Output is correct
38 Correct 195 ms 51960 KB Output is correct
39 Correct 261 ms 51760 KB Output is correct
40 Correct 198 ms 44464 KB Output is correct
41 Correct 277 ms 52008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23936 KB Output is correct
4 Correct 16 ms 23936 KB Output is correct
5 Correct 17 ms 23936 KB Output is correct
6 Correct 17 ms 23936 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 17 ms 23936 KB Output is correct
9 Correct 16 ms 23936 KB Output is correct
10 Correct 17 ms 23936 KB Output is correct
11 Correct 18 ms 24192 KB Output is correct
12 Correct 20 ms 24448 KB Output is correct
13 Correct 21 ms 24448 KB Output is correct
14 Correct 21 ms 24576 KB Output is correct
15 Correct 22 ms 24576 KB Output is correct
16 Correct 20 ms 24576 KB Output is correct
17 Correct 20 ms 24448 KB Output is correct
18 Correct 20 ms 24576 KB Output is correct
19 Correct 2017 ms 160376 KB Output is correct
20 Correct 1930 ms 160760 KB Output is correct
21 Correct 2005 ms 160888 KB Output is correct
22 Correct 1962 ms 160640 KB Output is correct
23 Correct 1819 ms 160632 KB Output is correct
24 Correct 154 ms 38788 KB Output is correct
25 Correct 120 ms 39160 KB Output is correct
26 Correct 126 ms 38648 KB Output is correct
27 Correct 139 ms 38520 KB Output is correct
28 Correct 129 ms 38520 KB Output is correct
29 Correct 97 ms 38264 KB Output is correct
30 Correct 95 ms 38264 KB Output is correct
31 Correct 122 ms 38712 KB Output is correct
32 Correct 58 ms 28332 KB Output is correct
33 Correct 115 ms 38580 KB Output is correct
34 Correct 339 ms 53496 KB Output is correct
35 Correct 337 ms 53624 KB Output is correct
36 Correct 252 ms 54136 KB Output is correct
37 Correct 250 ms 54136 KB Output is correct
38 Correct 251 ms 53980 KB Output is correct
39 Correct 207 ms 53240 KB Output is correct
40 Correct 209 ms 53240 KB Output is correct
41 Correct 262 ms 52728 KB Output is correct
42 Correct 261 ms 52344 KB Output is correct
43 Correct 274 ms 52216 KB Output is correct
44 Correct 304 ms 51960 KB Output is correct
45 Correct 297 ms 51960 KB Output is correct
46 Correct 301 ms 51960 KB Output is correct
47 Correct 292 ms 51960 KB Output is correct
48 Correct 298 ms 51960 KB Output is correct
49 Correct 199 ms 51960 KB Output is correct
50 Correct 195 ms 52088 KB Output is correct
51 Correct 195 ms 51960 KB Output is correct
52 Correct 190 ms 51960 KB Output is correct
53 Correct 195 ms 51960 KB Output is correct
54 Correct 261 ms 51760 KB Output is correct
55 Correct 198 ms 44464 KB Output is correct
56 Correct 277 ms 52008 KB Output is correct
57 Correct 1937 ms 164856 KB Output is correct
58 Correct 1973 ms 164856 KB Output is correct
59 Correct 1856 ms 165780 KB Output is correct
60 Correct 1797 ms 165880 KB Output is correct
61 Correct 1802 ms 166008 KB Output is correct
62 Correct 1869 ms 165752 KB Output is correct
63 Correct 1080 ms 162808 KB Output is correct
64 Correct 1099 ms 162936 KB Output is correct
65 Correct 1682 ms 162296 KB Output is correct
66 Correct 1641 ms 162040 KB Output is correct
67 Correct 1661 ms 161912 KB Output is correct
68 Correct 1789 ms 160932 KB Output is correct
69 Correct 1802 ms 160888 KB Output is correct
70 Correct 1780 ms 161016 KB Output is correct
71 Correct 1799 ms 161144 KB Output is correct
72 Correct 1780 ms 161044 KB Output is correct
73 Correct 959 ms 158648 KB Output is correct
74 Correct 969 ms 158968 KB Output is correct
75 Correct 925 ms 159176 KB Output is correct
76 Correct 935 ms 159352 KB Output is correct
77 Correct 932 ms 158632 KB Output is correct
78 Correct 1498 ms 159680 KB Output is correct
79 Correct 1039 ms 110104 KB Output is correct
80 Correct 1462 ms 160008 KB Output is correct