# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
375411 | muhi1112 | Po (COCI21_po) | C++17 | 1121 ms | 524292 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 f1 first
#define s2 second
#define INF 1e9+10
#define ll long long
#define pb push_back
#define fri(a) freopen(a,"r",stdin)
#define fro(a) freopen(a,"w",stdout)
const int N=2e5+5;
ll n,dizi[N],t[4*N];
map<ll,vector<int>>mp;
void build(int v,int tl,int tr){
if(tl==tr)t[v]=dizi[tl];
else{
int tm=(tl+tr)/2;
build(v*2,tl,tm);
build(v*2+1,tm+1,tr);
t[v]=min(t[v*2],t[v*2+1]);
}
}
ll getmin(int v,int tl,int tr,int l,int r){
if(l>r)return INF;
if(l==tl && r==tr)return t[v];
int tm=(tl+tr)/2;
return min(getmin(v*2,tl,tm,l,min(r,tm)),getmin(v*2+1,tm+1,tr,max(l,tm+1),r));
}
int solve(int l,int r){
//cout<<l<<" "<<r<<endl;
if(l>r)return 0;
if(l+1==r-1)return 1;
if(l+1==r)return 0;
ll x=getmin(1,1,n+1,l+1,r-1);
//cout<<x<<endl;
int a=solve(l,mp[x][0])+solve(mp[x][mp[x].size()-1],r)+1;
for(int i=1;i<mp[x].size();i++){
a+=solve(mp[x][i-1],mp[x][i]);
//cout<<"sa"<<endl;
}
return a;
}
int main(){
//fri("in.txt");
//fro("out.txt");
cin>>n;
for(int i=1;i<=n;i++){
cin>>dizi[i];
mp[dizi[i]].pb(i);
}
build(1,1,n+1);
cout<<solve(0,n+1)<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |