#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"
bool comp(vector<int> v1, vector<int> v2)
{
return v1[0]<v2[0];
}
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("input.000","r",stdin);
// freopen("output.000","w",stdout);
// srand((unsigned)time(NULL));
// rand()
int n,i,a[1000005],ans,m,r,pos;
vector<int> v[1000005];
ordered_set s;
cin>>n;a[0]=0;
for (i=1;i<n+1;i++) cin>>a[i];
m=1;
for (i=1;i<n+1;i++)
{
if (a[i-1]>a[i]) m++;
v[m].pb(a[i]);
}
sort(v+1,v+m+1,comp);
// for (i=1;i<m+1;i++)
// {
// cout<<i<<": ";
// for (auto val:v[i]) cout<<val<<" ";
// cout<<"\n";
// }
ans=m;
s.insert(0);s.insert(1e7);
for (i=1;i<m+1;i++)
{
pos=s.order_of_key(v[i][0]+1);
r=*s.find_by_order(pos);
for (auto val:v[i]) if (val>r)
{
ans++;
pos=s.order_of_key(val+1);
r=*s.find_by_order(pos);
}
for (auto val:v[i]) s.insert(val);
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
31572 KB |
Output is correct |
2 |
Correct |
17 ms |
31552 KB |
Output is correct |
3 |
Correct |
17 ms |
31572 KB |
Output is correct |
4 |
Correct |
17 ms |
31504 KB |
Output is correct |
5 |
Correct |
17 ms |
31620 KB |
Output is correct |
6 |
Correct |
17 ms |
31560 KB |
Output is correct |
7 |
Correct |
17 ms |
31620 KB |
Output is correct |
8 |
Correct |
17 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31572 KB |
Output is correct |
10 |
Incorrect |
17 ms |
31624 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
31572 KB |
Output is correct |
2 |
Correct |
17 ms |
31552 KB |
Output is correct |
3 |
Correct |
17 ms |
31572 KB |
Output is correct |
4 |
Correct |
17 ms |
31504 KB |
Output is correct |
5 |
Correct |
17 ms |
31620 KB |
Output is correct |
6 |
Correct |
17 ms |
31560 KB |
Output is correct |
7 |
Correct |
17 ms |
31620 KB |
Output is correct |
8 |
Correct |
17 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31572 KB |
Output is correct |
10 |
Incorrect |
17 ms |
31624 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
31572 KB |
Output is correct |
2 |
Correct |
17 ms |
31552 KB |
Output is correct |
3 |
Correct |
17 ms |
31572 KB |
Output is correct |
4 |
Correct |
17 ms |
31504 KB |
Output is correct |
5 |
Correct |
17 ms |
31620 KB |
Output is correct |
6 |
Correct |
17 ms |
31560 KB |
Output is correct |
7 |
Correct |
17 ms |
31620 KB |
Output is correct |
8 |
Correct |
17 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31572 KB |
Output is correct |
10 |
Incorrect |
17 ms |
31624 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
31572 KB |
Output is correct |
2 |
Correct |
17 ms |
31552 KB |
Output is correct |
3 |
Correct |
17 ms |
31572 KB |
Output is correct |
4 |
Correct |
17 ms |
31504 KB |
Output is correct |
5 |
Correct |
17 ms |
31620 KB |
Output is correct |
6 |
Correct |
17 ms |
31560 KB |
Output is correct |
7 |
Correct |
17 ms |
31620 KB |
Output is correct |
8 |
Correct |
17 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31572 KB |
Output is correct |
10 |
Incorrect |
17 ms |
31624 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |