/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 3ms 384.0 KiB
#2 Accepted 3ms 276.0 KiB
#3 Accepted 3ms 196.0 KiB
#4 Accepted 4ms 332.0 KiB
#5 Accepted 4ms 352.0 KiB
#6 Accepted 4ms 256.0 KiB
#7 Accepted 48ms 1.875 MiB
#8 Accepted 50ms 1.875 MiB
#9 Accepted 45ms 1.961 MiB
#10 Accepted 45ms 1.965 MiB

代码

#include <bits/stdc++.h>
using namespace std;
inline int read()
{
    char ch=getchar();
    int x=0;
    while(!isdigit(ch))
        ch=getchar();
    while(isdigit(ch))
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x;
}
int k,n,m,ans;

struct node
{
	int x,y,c;
}e[50010];
struct tree
{
	int l,r;
	int maxn,lazy;
}a[80010];
inline void build(int x,int y,int i)
{
	a[i].l=x,a[i].r=y;
	if(x==y) return ;
	int mid=(x+y)>>1;
	build(x,mid,i<<1);
	build(mid+1,y,i<<1|1);
}

inline void pushdown(int i)
{
	if(a[i].lazy)
	{
		a[i<<1].lazy+=a[i].lazy;
		a[i<<1|1].lazy+=a[i].lazy;
		a[i<<1].maxn+=a[i].lazy;
		a[i<<1|1].maxn+=a[i].lazy;
		a[i].lazy=0;
	}
}
inline void update(int x,int y,int val,int i)
{
	if(a[i].r<x||y<a[i].l) return ;
	if(x<=a[i].l&&a[i].r<=y)
	{
		a[i].lazy+=val;
		a[i].maxn+=val;
		return ;
	}
	pushdown(i);
	update(x,y,val,i<<1);
	update(x,y,val,i<<1|1);
	a[i].maxn=max(a[i<<1].maxn,a[i<<1|1].maxn);
}
inline int query(int x,int y,int i)
{
	if(a[i].r<x||y<a[i].l) return 0;
	if(x<=a[i].l&&a[i].r<=y)
		return a[i].maxn;
	pushdown(i);
	return max(query(x,y,i<<1),query(x,y,i<<1|1));
}

inline bool cmp(node b,node c)
{
	if(b.y==c.y)
		return b.x>c.x;
	else
		return b.y<c.y;
}
int main()
{
	int i;
	k=read(),n=read(),m=read();
	for(i=1;i<=k;i++)
		e[i].x=read(),e[i].y=read(),e[i].c=read();
	sort(e+1,e+k+1,cmp);
	build(1,n,1);
	for(i=1;i<=k;i++)
	{
		int tmp=query(e[i].x,e[i].y,1),rec=0;
		if(tmp==m)
			continue;
		if(tmp+e[i].c<=m)
			rec=e[i].c;
		else
			rec=m-tmp;
		ans+=rec;
		update(e[i].x,e[i].y-1,rec,1);
	}
	cout<<ans;
	return 0;
}

信息

递交者
类型
递交
题目
公交与怪兽 T2
题目数据
下载
语言
C++
递交时间
2017-11-02 16:51:35
评测时间
2017-11-02 16:51:35
评测机
分数
100
总耗时
215ms
峰值内存
1.965 MiB