/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 4ms 2.25 MiB
#2 Accepted 5ms 2.367 MiB
#3 Accepted 3ms 2.359 MiB
#4 Accepted 5ms 2.352 MiB
#5 Accepted 5ms 2.355 MiB
#6 Accepted 5ms 2.352 MiB
#7 Accepted 48ms 3.375 MiB
#8 Accepted 62ms 3.312 MiB
#9 Accepted 50ms 3.375 MiB
#10 Accepted 55ms 3.355 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[200010];
struct tree
{
	int l,r;
	int maxn,lazy;
}a[800010];
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 push_col(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 modify(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 ;
	}
	push_col(i);
	modify(x,y,val,i<<1);
	modify(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;
	push_col(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;
		modify(e[i].x,e[i].y-1,rec,1);
	}
	cout<<ans;
	return 0;
}

信息

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