# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
684226 | sudheerays123 | Po (COCI21_po) | C++17 | 52 ms | 15140 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
const ll N = 1e5+5 , INF = 1e18 , MOD = 1e9+7;
vector<ll> seg(4*N);
vector<ll> a(N);
void build(ll node , ll left , ll right){
if(left == right){
seg[node] = a[left];
return;
}
ll mid = (left+right)/2;
build(2*node,left,mid);
build(2*node+1,mid+1,right);
seg[node] = min(seg[2*node],seg[2*node+1]);
}
ll query(ll node , ll left , ll right , ll ql , ll qr){
if(left >= ql && right <= qr) return seg[node];
if(left > qr || right < ql) return INF;
ll mid = (left+right)/2;
ll l = query(2*node,left,mid,ql,qr);
ll r = query(2*node+1,mid+1,right,ql,qr);
return min(l,r);
}
void solve(){
ll n;
cin >> n;
map<ll,vector<ll>> m;
for(ll i = 1; i <= n; i++){
cin >> a[i];
m[a[i]].push_back(i);
}
build(1,1,n);
ll ans = n;
for(auto u : m){
vector<ll> ind = u.second;
for(ll i = 1; i < ind.size();i++)
if(query(1,1,n,ind[i-1],ind[i]) >= u.first)
ans--;
}
cout << ans;
}
int main(){
fast;
ll tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |