Submission #602170

# Submission time Handle Problem Language Result Execution time Memory
602170 2022-07-22T16:12:35 Z inksamurai Baloni (COCI15_baloni) C++17
0 / 100
2000 ms 92308 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=(c);i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3aFGabX ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

const int _n=1000011; // fix me
set<int> rbts[_n+11];

signed main(){
_3aFGabX;
	int n;
	cin>>n;
	vi a(n);
	rep(i,n){
		cin>>a[i];
		rbts[a[i]].insert(i);
	}
	// print(sz(rbts[1]));
	int res=0;
	for(int i=_n;i>=1;i--){
		int v=i,j=-1;
		while(sz(rbts[i])){
			res+=1;
			while(v and sz(rbts[v])){
				auto it=rbts[v].lower_bound(j);
				if(it!=rbts[v].end()){
					j=*it;
					rbts[v].erase(it);
				}else{
					break;
				}
				v-=1;
			}
		}
	}
	print(res);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 2090 ms 47268 KB Time limit exceeded
2 Execution timed out 2074 ms 47316 KB Time limit exceeded
3 Execution timed out 2078 ms 47376 KB Time limit exceeded
4 Execution timed out 2086 ms 47444 KB Time limit exceeded
5 Execution timed out 2086 ms 87488 KB Time limit exceeded
6 Execution timed out 2096 ms 92308 KB Time limit exceeded
7 Execution timed out 2074 ms 84396 KB Time limit exceeded
8 Execution timed out 2082 ms 83980 KB Time limit exceeded
9 Execution timed out 2093 ms 86036 KB Time limit exceeded
10 Execution timed out 2098 ms 87704 KB Time limit exceeded