# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
375424 |
2021-03-09T11:11:09 Z |
muhi1112 |
Po (COCI21_po) |
C++17 |
|
85 ms |
9964 KB |
#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];
pair<ll,int>t[4*N];
void build(int v,int tl,int tr){
if(tl==tr)t[v]={dizi[tl],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]);
}
}
pair<ll,int> getmin(int v,int tl,int tr,int l,int r){
if(l>r)return {INF,-1};
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,int y){
//cout<<l<<" "<<r<<endl;
if(l>r)return 0;
pair<ll,int> x=getmin(1,0,n,l,r);
return solve(l,x.s2-1,x.f1)+solve(x.s2+1,r,x.f1)+(y!=x.f1);
}
int main(){
//fri("in.txt");
//fro("out.txt");
cin>>n;
for(int i=0;i<n;i++){
cin>>dizi[i];
}
build(1,0,n);
cout<<solve(0,n-1,-1)<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Incorrect |
26 ms |
2924 KB |
Output isn't correct |
5 |
Incorrect |
36 ms |
5100 KB |
Output isn't correct |
6 |
Correct |
85 ms |
9964 KB |
Output is correct |
7 |
Incorrect |
67 ms |
8684 KB |
Output isn't correct |