提交记录 11319


用户 题目 状态 得分 用时 内存 语言 代码长度
MicDZ noip18a. 【NOIP2018】铺设道路 Accepted 100 6.38 ms 9028 KB C++ 1.88 KB
提交时间 评测时间
2019-11-14 22:18:46 2020-08-01 02:42:21
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>

using namespace std;
#define int ll
#define REP(i,e,s) for(register int i=(e); i<=(s); i++)
#define DREP(i,e,s) for(register int i=(e); i>=(s); i--)
#define ll long long
#define DE(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG(a) DE("DEBUG: %d\n",a)
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=100000+10;

int a[MAXN];

struct SegmentTree {
	int lf[MAXN<<2],rg[MAXN<<2],maxx[MAXN<<2],pos[MAXN<<2];
	#define l(x) lf[x]
	#define r(x) rg[x]
	#define len(x) (rg[x]-lf[x]+1)
	#define maxx(x) maxx[x]
	#define add(x) add[x]
	#define pos(x) pos[x]
	#define INF 0x3f3f3f3f
	void build(int p,int l,int r) {
		l(p)=l,r(p)=r;
		if(l==r) {maxx(p)=a[l]; pos[p]=l; return;}
		int mid=(l+r)>>1;
		build(p*2,l,mid);
		build(p*2+1,mid+1,r);
		int ans=INF;
		if(maxx(p*2)<ans) ans=maxx(p*2),pos[p]=pos[p*2];
		if(maxx(p*2+1)<ans) ans=maxx(p*2+1),pos[p]=pos[p*2+1];
		maxx(p)=ans;
	}
	pair<int,int> ask(int p,int l,int r) {
		if(l(p)>=l&&r(p)<=r) {return make_pair(maxx(p),pos(p));}
		int mid=(l(p)+r(p))>>1;
		int ans=INF,pos;
		pair<int,int> ansl,ansr;
		if(l<=mid) ansl=ask(p*2,l,r);
		if(r>mid) ansr=ask(p*2+1,l,r);
		if(l<=mid&&ansl.first<ans) ans=ansl.first,pos=ansl.second;
		if(r>mid&&ansr.first<ans) ans=ansr.first,pos=ansr.second;
		return make_pair(ans,pos);
	}
} s;

int ans;
void calc(int l,int r,int dept) {
	if(l>r) return ;
	//pair<int,int> x=s.ask(1,l,r);
	//int pos=s.ask(1,l,r).second;
	int pos=l;
	REP(i,l,r) if(a[pos]>a[i]) pos=i;
	
	ans+=a[pos]-dept;
	calc(l,pos-1,a[pos]);
	calc(pos+1,r,a[pos]);
}

signed main() {
	int n=read();
	REP(i,1,n) a[i]=read();
	s.build(1,1,n);
	calc(1,n,0);	
	printf("%lld\n",ans);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #136.57 us60 KBAcceptedScore: 10

Testcase #242.05 us64 KBAcceptedScore: 10

Testcase #337.97 us64 KBAcceptedScore: 10

Testcase #443.89 us64 KBAcceptedScore: 10

Testcase #538.48 us64 KBAcceptedScore: 10

Testcase #647.61 us80 KBAcceptedScore: 10

Testcase #784.55 us132 KBAcceptedScore: 10

Testcase #8596.75 us1 MB + 140 KBAcceptedScore: 10

Testcase #92.964 ms4 MB + 452 KBAcceptedScore: 10

Testcase #106.38 ms8 MB + 836 KBAcceptedScore: 10


Judge Duck Online | 评测鸭在线
Server Time: 2024-05-04 18:08:41 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用