답안 #319306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319306 2020-11-04T16:26:52 Z kshitij_sodani Money (IZhO17_money) C++14
0 / 100
1 ms 384 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];
void u(int i,int j){
	while(i<1000001){
		tree[i]+=j;
		i+=(i&-i);
	}
}
int ss(int i){
	int su=0;
	while(i>0){
		su+=tree[i];
		i-=(i&-i);
	}
	return su;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>it[i];
	//	u(it[i],1);
	}
	int ind=0;
	int ans=0;
//	u(it[0],-1);
	while(ind<n){
		int mi=it[ind];
		int ma=it[ind];
		ans++;
		//cout<<ind<<":"<<endl;
		ind++;
		//u(it[ind],1);
		//u(it[ind],-1);
		int pre=ind;
		while(ind<n){
			if(it[ind]<ma){
				break;
			}
			mi=min(mi,it[ind]);
			ma=max(ma,it[ind]);
		//	cout<<ind<<":"<<endl;
			if(ss(ma-1)-ss(mi)==0){
				//u(it[ind],1);
				ind++;
				continue;
			}
			break;
		}
		for(int i=pre;i<ind;i++){
			u(it[i],1);
		}
	}
	cout<<ans<<endl;

	return 0;
}
/*
6
3 6 4 5 1 2*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -