#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 pok=0,v=i,j=-1;
while(v and sz(rbts[v])){
pok=1;
auto it=rbts[v].lower_bound(j);
if(it!=rbts[v].end()){
j=*it;
rbts[v].erase(it);
}else{
break;
}
v-=1;
}
// if(i<=5) print(pok);
res+=pok;
}
print(res);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
47316 KB |
Output isn't correct |
2 |
Incorrect |
27 ms |
47388 KB |
Output isn't correct |
3 |
Incorrect |
29 ms |
47472 KB |
Output isn't correct |
4 |
Incorrect |
27 ms |
47540 KB |
Output isn't correct |
5 |
Correct |
652 ms |
91112 KB |
Output is correct |
6 |
Incorrect |
720 ms |
95896 KB |
Output isn't correct |
7 |
Incorrect |
551 ms |
87252 KB |
Output isn't correct |
8 |
Incorrect |
551 ms |
86836 KB |
Output isn't correct |
9 |
Incorrect |
621 ms |
89276 KB |
Output isn't correct |
10 |
Incorrect |
581 ms |
90720 KB |
Output isn't correct |