답안 #319288

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319288 2020-11-04T15:48:16 Z kshitij_sodani Money (IZhO17_money) C++14
45 / 100
1500 ms 121008 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#define endl '\n'
int n;
int it[1000001];
//int tree[1000001*4];
pair<int,int> pp[1000001];
int ans[1000001];
int re[1000001];
//int mi[1000001][20];
/*void build(int no,int l,int r){
	if(l==r){
		tree[no]=it[l];
	}
	else{
		int mid=(l+r)/2;
		build(no*2+1,l,mid);
		build(no*2+2,mid+1,r);
		tree[no]=max(tree[no*2+1],tree[no*2+2]);
	}
}
int query(int no,int l,int r,int aa,int bb){
	if(r<aa){
		return -1;
	}
	if(aa<=l){
		if(tree[no]<=bb){
			return -1;
		}
		if(l==r){
			return l;
		}
	}
	int mid=(l+r)/2;
	int x=query(no*2+1,l,mid,aa,bb);
	if(x==-1){
		return query(no*2+2,mid+1,r,aa,bb);
	}
	else{
		return x;
	}
}*/
vector<int> pre[1000001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	/*for(int i=0;i<n;i++){
		for(int j=0;j<20;j++){
			mi[i][j]=1;
		}
	}*/
	for(int i=0;i<n;i++){
		cin>>it[i];
	}
	vector<pair<int,int>> ss;
	vector<pair<int,int>> tt;
	set<int> kk;
	//build(0,0,n-1);
	for(int i=0;i<n;i++){
		while(ss.size()){
			if(ss.back().a<=it[i]){
				ss.pop_back();
			}
			else{
				break;
			}
		}
		pp[i]={-1,-1};
		if(ss.size()){
			int ne=ss.back().b;
 			pre[i-1].pb(ne);
			//tt.pb({ne,i-1});
			//cur++;
			int jj=*kk.upper_bound(it[i]);

			pp[i]={ss.back().b,jj};
			/*
			int low=query(0,0,n-1,i,jj);
			if(low!=-1){
				tt.pb({{i,low-1},cur});
				//cur++;
			}*/
		}
		kk.insert(it[i]);
		ss.pb({it[i],i});
	}
	vector<pair<int,int>> cc;
	for(int i=n-1;i>=0;i--){
		while(cc.size()){
			if(cc.back().a<=it[i]){
				cc.pop_back();
			}
			else{
				break;
			}
		}
		re[i]=-1;
		if(cc.size()){
 
			re[i]=cc.back().b;
			if(pp[i].a!=-1){
				if(cc[0].a>pp[i].b){
					int ind=0;
					for(int j=19;j>=0;j--){
						if(ind+(1<<j)<cc.size()){
							if(cc[ind+(1<<j)].a>pp[i].b){
								ind+=(1<<j);
							}
						}
					}
					pre[cc[ind].b-1].pb(i);
				//	tt.pb({i,cc[ind].b-1});
				}
			}
		}
	/*	if(cc.size()){
			re[i]=cc.back().b;
			if(pp[i].a!=-1){
				int cur2=cc.back().b;
				while(cur2!=-1){
					if(it[cur2]>pp[i].b){
					//	cout<<i<<":"<<cur2<<endl;
						tt.pb({{i,cur2-1},cur});
						break;
					}
					cur2=re[cur2];
				}
			}*/
			/*if(pp[i].a!=-1){
				if(cc[0].a>pp[i].b){
					if(cc.back().a<=pp[i].b){
						ans[i]=ans[cc.back().b];
					}
					else{
						ans[i]=cc.back().b;
					}
					tt.pb({{i,ans[i]-1},cur});
				}
			}*/
 
		//}
		cc.pb({it[i],i});
	}
/*	for(int i=0;i<n;i++){
		if(pp[i].b==-1){
			continue;
		}
		for(int j=i+1;j<n;j++){
			if(it[j]>pp[i].b){
				if(j!=re[pp[i].a]){
					while(true){
						continue;
					}
				}
				tt.pb({{i,j-1},cur});
				break;
			}
		}
		if(pp[i].a!=-1){
			if(re[pp[i].a]!=-1){
				
				int cur2=re[pp[i].a];
				tt.pb({{i,cur2-1},cur});
			}
		}
	}
*/
	/*for(auto j:tt){
		pre[j.b].pb(j.a);
	}*/
 
	int ans=1;
	
	int ma=-1;
	for(int i=0;i<n-1;i++){
		for(auto j:pre[i]){
			if(j<=ma){
				continue;
			}
			ans+=1;
			ma=i;
		}
	}
	cout<<ans<<endl;
 
	return 0;
}
/*
6
3 6 4 5 1 2*/

Compilation message

money.cpp: In function 'int main()':
money.cpp:112:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |       if(ind+(1<<j)<cc.size()){
      |          ~~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23948 KB Output is correct
3 Correct 16 ms 23788 KB Output is correct
4 Correct 17 ms 24044 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 16 ms 23788 KB Output is correct
11 Correct 16 ms 23808 KB Output is correct
12 Correct 16 ms 23788 KB Output is correct
13 Correct 16 ms 23788 KB Output is correct
14 Correct 16 ms 23788 KB Output is correct
15 Correct 17 ms 23788 KB Output is correct
16 Correct 16 ms 23788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23948 KB Output is correct
3 Correct 16 ms 23788 KB Output is correct
4 Correct 17 ms 24044 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 16 ms 23788 KB Output is correct
11 Correct 16 ms 23808 KB Output is correct
12 Correct 16 ms 23788 KB Output is correct
13 Correct 16 ms 23788 KB Output is correct
14 Correct 16 ms 23788 KB Output is correct
15 Correct 17 ms 23788 KB Output is correct
16 Correct 16 ms 23788 KB Output is correct
17 Correct 16 ms 23788 KB Output is correct
18 Correct 17 ms 23820 KB Output is correct
19 Correct 17 ms 23788 KB Output is correct
20 Correct 17 ms 23788 KB Output is correct
21 Correct 16 ms 23916 KB Output is correct
22 Correct 16 ms 23808 KB Output is correct
23 Correct 16 ms 23788 KB Output is correct
24 Correct 16 ms 23788 KB Output is correct
25 Correct 16 ms 23788 KB Output is correct
26 Correct 16 ms 23788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23948 KB Output is correct
3 Correct 16 ms 23788 KB Output is correct
4 Correct 17 ms 24044 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 16 ms 23788 KB Output is correct
11 Correct 16 ms 23808 KB Output is correct
12 Correct 16 ms 23788 KB Output is correct
13 Correct 16 ms 23788 KB Output is correct
14 Correct 16 ms 23788 KB Output is correct
15 Correct 17 ms 23788 KB Output is correct
16 Correct 16 ms 23788 KB Output is correct
17 Correct 16 ms 23788 KB Output is correct
18 Correct 17 ms 23820 KB Output is correct
19 Correct 17 ms 23788 KB Output is correct
20 Correct 17 ms 23788 KB Output is correct
21 Correct 16 ms 23916 KB Output is correct
22 Correct 16 ms 23808 KB Output is correct
23 Correct 16 ms 23788 KB Output is correct
24 Correct 16 ms 23788 KB Output is correct
25 Correct 16 ms 23788 KB Output is correct
26 Correct 16 ms 23788 KB Output is correct
27 Correct 17 ms 23920 KB Output is correct
28 Correct 16 ms 23788 KB Output is correct
29 Correct 17 ms 23916 KB Output is correct
30 Correct 18 ms 23788 KB Output is correct
31 Correct 17 ms 23788 KB Output is correct
32 Correct 16 ms 23916 KB Output is correct
33 Correct 17 ms 24044 KB Output is correct
34 Correct 16 ms 23788 KB Output is correct
35 Correct 16 ms 23916 KB Output is correct
36 Correct 17 ms 23916 KB Output is correct
37 Correct 16 ms 23916 KB Output is correct
38 Correct 18 ms 23916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23948 KB Output is correct
3 Correct 16 ms 23788 KB Output is correct
4 Correct 17 ms 24044 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 16 ms 23788 KB Output is correct
11 Correct 16 ms 23808 KB Output is correct
12 Correct 16 ms 23788 KB Output is correct
13 Correct 16 ms 23788 KB Output is correct
14 Correct 16 ms 23788 KB Output is correct
15 Correct 17 ms 23788 KB Output is correct
16 Correct 16 ms 23788 KB Output is correct
17 Correct 16 ms 23788 KB Output is correct
18 Correct 17 ms 23820 KB Output is correct
19 Correct 17 ms 23788 KB Output is correct
20 Correct 17 ms 23788 KB Output is correct
21 Correct 16 ms 23916 KB Output is correct
22 Correct 16 ms 23808 KB Output is correct
23 Correct 16 ms 23788 KB Output is correct
24 Correct 16 ms 23788 KB Output is correct
25 Correct 16 ms 23788 KB Output is correct
26 Correct 16 ms 23788 KB Output is correct
27 Correct 17 ms 23920 KB Output is correct
28 Correct 16 ms 23788 KB Output is correct
29 Correct 17 ms 23916 KB Output is correct
30 Correct 18 ms 23788 KB Output is correct
31 Correct 17 ms 23788 KB Output is correct
32 Correct 16 ms 23916 KB Output is correct
33 Correct 17 ms 24044 KB Output is correct
34 Correct 16 ms 23788 KB Output is correct
35 Correct 16 ms 23916 KB Output is correct
36 Correct 17 ms 23916 KB Output is correct
37 Correct 16 ms 23916 KB Output is correct
38 Correct 18 ms 23916 KB Output is correct
39 Correct 139 ms 45796 KB Output is correct
40 Correct 244 ms 61280 KB Output is correct
41 Correct 113 ms 41060 KB Output is correct
42 Correct 116 ms 40296 KB Output is correct
43 Correct 87 ms 35428 KB Output is correct
44 Correct 286 ms 70756 KB Output is correct
45 Correct 279 ms 70116 KB Output is correct
46 Correct 294 ms 70884 KB Output is correct
47 Correct 185 ms 55140 KB Output is correct
48 Correct 236 ms 65764 KB Output is correct
49 Correct 794 ms 89692 KB Output is correct
50 Correct 788 ms 88024 KB Output is correct
51 Correct 822 ms 90204 KB Output is correct
52 Correct 792 ms 88024 KB Output is correct
53 Correct 793 ms 89180 KB Output is correct
54 Correct 818 ms 88112 KB Output is correct
55 Execution timed out 1583 ms 121008 KB Time limit exceeded
56 Halted 0 ms 0 KB -