/ Randle /

记录详情

Time Exceeded

/in/foo.cc: In member function 'const void onbus::push(int)':
/in/foo.cc:59:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    if(!prior[p])s=p;if(!nex[p])e=p;
    ^~
/in/foo.cc:59:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    if(!prior[p])s=p;if(!nex[p])e=p;
                     ^~
# 状态 耗时 内存占用
#1 Accepted 6ms 5.934 MiB
#2 Accepted 5ms 6.184 MiB
#3 Accepted 3ms 5.93 MiB
#4 Time Exceeded ≥1006ms ≥5.68 MiB
#5 Time Exceeded ≥1007ms ≥6.441 MiB
#6 Time Exceeded ≥1007ms ≥5.312 MiB
#7 Time Exceeded ≥1006ms ≥5.547 MiB
#8 Time Exceeded ≥1006ms ≥5.816 MiB
#9 Time Exceeded ≥1006ms ≥5.301 MiB
#10 Time Exceeded ≥1007ms ≥4.938 MiB

代码

#include<bits/stdc++.h>
const int maxn=2e5;
inline const void read(int &a)
{
	a=0;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
}
inline const void write(int a)
{
	if(a>9)write(a/10);
	putchar(a%10+'0');
}
int k,n,m,ans=0;
int start[maxn],end[maxn],num[maxn],next[maxn],point[maxn],bus[maxn];
class onbus
{
	public:
		int v,s,e,nex[maxn],prior[maxn];
		inline const void clear()
		{
			s=0;v=0;e=0;
			memset(nex,0,sizeof(nex));
			memset(prior,0,sizeof(prior));
		}
		inline const void out(int k)
		{
			while(v)
			{
				if(end[s]<=k)
				{
					v-=bus[s];
					ans+=bus[s];
					s=nex[s];
					if(!v)e=s;
					prior[s]=0;
				}
				else return ;
			}
		}
		inline const void push(int p)
		{
			int c=e,sum=0,load;
			while(c&&end[c]>end[p])
			{
				sum+=bus[c];
				c=prior[c];
			}
			load=std::min(m-(v-sum),num[p]);
			if(load<=0)return ;
			bus[p]=load;v+=load;
			prior[nex[c]]=p;nex[p]=nex[c];
			nex[c]=p;prior[p]=c;
			if(!prior[p])s=p;if(!nex[p])e=p;
			if(v>m)
			{
				int cut=v-m;
				v=m;
				while(cut)
				{
					if(bus[e]>cut){bus[e]-=cut;return ;}
					else
					{
						cut-=bus[e];
						e=prior[e];
						nex[e]=0;
					}
				}
			}
		}
}on;
inline const void add(int i)
{
	next[i]=point[start[i]];
	point[start[i]]=i;
}
int main()
{
	memset(bus,0,sizeof(bus));
	memset(point,0,sizeof(point));
	read(k);read(n);read(m);
	for(int i=1;i<=k;i++){read(start[i]);read(end[i]);read(num[i]);add(i);}
	on.clear();
	for(int i=1;i<=n;i++)
	{
		int side=point[i];
		on.out(i);
		while(side)
		{	
			on.push(side);
			side=next[side];
		}
	}
	write(ans);
	return 0;
}

信息

递交者
类型
递交
题目
公交与怪兽 T2
题目数据
下载
语言
C++
递交时间
2017-10-03 13:27:07
评测时间
2017-10-03 13:27:07
评测机
分数
30
总耗时
≥7065ms
峰值内存
≥6.441 MiB