답안 #319245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319245 2020-11-04T14:56:02 Z kshitij_sodani Money (IZhO17_money) C++14
0 / 100
17 ms 23916 KB
#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 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<pair<int,int>,int>> tt;
	set<int> kk;
	build(0,0,n-1);
	int cur=0;
	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;

			tt.pb({{ne,i-1},cur});
			//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;
			}
		}

		if(cc.size()){
			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(auto j:tt){
		pre[j.a.b].pb(j.a.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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23916 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 16 ms 23916 KB Output is correct
4 Correct 16 ms 23820 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 17 ms 23788 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 16 ms 23908 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
11 Correct 16 ms 23788 KB Output is correct
12 Incorrect 16 ms 23916 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23916 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 16 ms 23916 KB Output is correct
4 Correct 16 ms 23820 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 17 ms 23788 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 16 ms 23908 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
11 Correct 16 ms 23788 KB Output is correct
12 Incorrect 16 ms 23916 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23916 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 16 ms 23916 KB Output is correct
4 Correct 16 ms 23820 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 17 ms 23788 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 16 ms 23908 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
11 Correct 16 ms 23788 KB Output is correct
12 Incorrect 16 ms 23916 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23916 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 16 ms 23916 KB Output is correct
4 Correct 16 ms 23820 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 17 ms 23788 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 16 ms 23908 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
11 Correct 16 ms 23788 KB Output is correct
12 Incorrect 16 ms 23916 KB Output isn't correct
13 Halted 0 ms 0 KB -