/ Randle /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Accepted 6ms 256.0 KiB
#2 Accepted 4ms 256.0 KiB
#3 Accepted 4ms 348.0 KiB
#4 Accepted 5ms 384.0 KiB
#5 Accepted 6ms 360.0 KiB
#6 Accepted 6ms 356.0 KiB
#7 Wrong Answer 11ms 640.0 KiB
#8 Wrong Answer 10ms 516.0 KiB
#9 Wrong Answer 9ms 636.0 KiB
#10 Wrong Answer 10ms 592.0 KiB

代码

#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[20010];
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:33:23
评测时间
2017-11-02 16:33:23
评测机
分数
60
总耗时
74ms
峰值内存
640.0 KiB