QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377938#7905. Ticket to RideWrongAnswer_90TL 1ms4560kbC++145.9kb2024-04-05 20:47:262024-04-05 20:47:26

Judging History

你现在查看的是最新测评结果

  • [2024-04-05 20:47:26]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:4560kb
  • [2024-04-05 20:47:26]
  • 提交

answer

#include<bits/stdc++.h>
#define ull unsigned long long
//#define ui unsigned int
#define ld long double
#define ll long long
#define lll __int128
#define fi first
#define se second
#define e emplace
#define eb emplace_back
#define db double
#define ef emplace_front
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vp vector<pii>
#define mp make_pair

//#define LOCALJUDGE
#define int ll
bool ST;
static const ll MOD=998244353,Phi=998244352,inv2=499122177,Root=3,iRoot=332748118;
static const ll inf=1073741823,INF=4557430888798830399;
static const double eps=1e-8,pi=3.1415926535;
char in[1<<20],*p1=in,*p2=in;
using namespace std;
//#define getchar() (p1==p2&&(p2=(p1=in)+fread(in,1,1<<20,stdin),p1==p2)?EOF:*p1++)
struct tup{int x,y,z;tup(int X=0,int Y=0,int Z=0){x=X,y=Y,z=Z;}};
namespace FastIO
{
	template<typename T> inline void write(T x,char ch=' ')
	{
		if(is_same<char,T>::value)putchar(x);
		else
		{
			if(x<0)x=-x,putchar('-');
			static char st[25];int top=0;
			do{st[top++]=x%10+'0',x/=10;}while(x);
			while(top)putchar(st[--top]);
		}
		ch!='~'?putchar(ch):0;
	}
	inline void write(const char*x,char ch=' ')
	{
		for(int i=0;x[i]!='\0';++i)putchar(x[i]);
		ch!='~'?putchar(ch):0;
	}
	inline void read(char&s){do s=getchar();while(s=='\n'||s==' ');}
	inline void read(char s[])
	{
		int len=0;char st;
		do st=getchar();while(st=='\n'||st==' ');
		s[++len]=st,st=getchar();
		while(st!='\n'&&st!=' ')s[++len]=st,st=getchar();
		s[++len]='\0';
	}
	template<typename T> inline void read(T &s)
	{
		s=0;char ch=getchar();
		while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
		bool tf=(ch=='-')&&(ch=getchar());
		while((ch>='0')&&(ch<='9'))s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
		s=(tf?-s:s);
	}
	template<typename T1,typename T2> inline void read(pair<T1,T2> &s){read(s.fi),read(s.se);}
	template<typename T,typename...Args> inline void write(T x,Args...args){write(x,'~'),write(args...);}
	template<typename T,typename...Args> inline void read(T&x,Args&...args){read(x),read(args...);}
}
using namespace FastIO;
namespace MTool
{
	inline int Cadd(int a,int b){return (ll)a+b>=MOD?(ll)a+b-MOD:a+b;}
	inline int Cdel(int a,int b){return a-b<0?a-b+MOD:a-b;}
	inline int Cmul(int a,int b){return 1ll*a*b%MOD;}
	inline int sqr(int a){return 1ll*a*a%MOD;}
	inline void Madd(int&a,int b){a=((ll)a+b>=MOD?(ll)a+b-MOD:a+b);}
	inline void Mdel(int&a,int b){a=(a-b<0?a-b+MOD:a-b);}
	inline void Mmul(int&a,int b){a=1ll*a*b%MOD;}
	template<typename T> inline bool Mmax(T&a,T b){return a<b?a=b,1:0;}
	template<typename T> inline bool Mmin(T&a,T b){return a>b?a=b,1:0;}
	template<typename...Args> inline void Madd(int&a,int b,Args...args){Madd(a,b),Madd(a,args...);}
	template<typename...Args> inline void Mmul(int&a,int b,Args...args){Mmul(a,b),Mmul(a,args...);}
	template<typename...Args> inline void Mdel(int&a,int b,Args...args){Mdel(a,b),Mdel(a,args...);}
	template<typename...Args> inline int Cadd(int a,int b,Args...args){return Cadd(Cadd(a,b),args...);}
	template<typename...Args> inline int Cmul(int a,int b,Args...args){return Cmul(Cmul(a,b),args...);}
	template<typename...Args> inline int Cdel(int a,int b,Args...args){return Cdel(Cdel(a,b),args...);}
	template<typename...Args,typename T> inline bool Mmax(T&a,T b,Args...args){return Mmax(a,b)|Mmax(a,args...);}
	template<typename...Args,typename T> inline bool Mmin(T&a,T b,Args...args){return Mmin(a,b)|Mmin(a,args...);}
	inline int power(int x,int y){int s=1;for(;y;y>>=1,Mmul(x,x))if(y&1)Mmul(s,x);return s;}
}
using namespace MTool;
namespace WrongAnswer_90
{
	int T,n,m,maxn,pos[10010],ans[10010],f[2][10010],Fa[10010],pre[10010],nex[10010],val[10010];
	int sum[10010];
	int find(int x){return x==Fa[x]?x:Fa[x]=find(Fa[x]);}
	vector<pii> ve[10010];
	void modify(int x,int y,int j)
	{
		val[find(0)]+=y;
		if((x=find(x))==find(j-1))return maxn+=y,void();
		x=nex[x],val[x]-=y;
		while(val[x]<=0)
		{
			pre[nex[x]]=pre[x],nex[pre[x]]=pre[x],Fa[find(x)]=pre[x];
			if(x==find(j-1)){maxn=maxn-val[x];continue;}
		}
	}
	inline void mian()
	{
		read(T);int x,y,z;
		while(T--)
		{
			read(n,m);
			for(int i=1;i<=n;++i)ve[i].clear();
			while(m--)read(x,y,z),ve[y].eb(mp(x,z));
			memset(f,128,sizeof(f)),f[0][0]=0;
			for(int i=1;i<=n+1;++i)
			{
				f[0][i]=f[0][i-1];
				for(auto p:ve[i-1])f[0][i]+=p.se;
			}
			memset(ans,0,sizeof(ans));
			for(int i=1;i<=n;++i)
			{
				f[i&1][0]=-inf;
				memset(sum,0,sizeof(sum)),memset(val,0,sizeof(val)),maxn=f[(i&1)^1][0];
				for(int j=0;j<=n+1;++j)pre[j]=j?j-1:j,nex[j]=j+1,Fa[j]=j;
				for(int j=1;j<=n+1;++j)
				{
					f[i&1][j]=maxn; 
//					for(int k=j-1;k>=0;--k)
//					Mmax(f[i&1][j],f[i-1][k]+sum[k]);
					if(Mmax(ans[j-i],f[i&1][j]))pos[j-i]=i;
					
					for(auto p:ve[j])
					modify(p.fi,p.se,j);
					val[j]=f[(i&1)^1][j]-maxn;
					if(val[j]<=0)
					pre[nex[j]]=pre[j],nex[pre[j]]=nex[j],Fa[find(j)]=find(j-1);
					else
					maxn+=val[j];
//					for(int x=0;x<=p.fi;++x)sum[x]+=p.se;
				}
			}
//			for(int i=1;i<=n;++i)
//			{
//				f[i][0]=-inf;
//				for(int j=1;j<=n+1;++j)
//				{
//					f[i][j]=maxn;
//					for(auto p:ve[j])
//					modify(p.fi,p.se,j);
//					val[j]=f[i-1][j]-val[find(j-1)];
//					if(val[j]<=0)
//					nex[pre[j]]=nex[j],pre[nex[j]]=pre[j],Fa[find(j)]=find(j-1);
//				}
//			}
//			for(int i=1;i<=n;++i,puts(""))
//			for(int j=1;j<=n+1;++j)cout<<f[i][j]<<" ";
			for(int i=1;i<=n;++i)write(ans[i]);puts("");
//			for(int i=1;i<=n;++i)write(pos[i]);puts("");
		}
	}
}
bool ED;
signed main()
{
	#ifdef LOCALJUDGE
	freopen("immutable.in","r",stdin);
	freopen("immutable.out","w",stdout);
	#endif
	double st=clock();
	WrongAnswer_90::mian();
	double ed=clock();
	#ifndef LOCALJUDGE
 	cerr<<endl;
	#endif
 	cerr<<"Time: "<<ed-st<<" ms\n";
	#ifdef LOCALJUDGE
 	cerr<<"     ";
	#endif
 	cerr<<"Memory: "<<abs(&ST-&ED)/1024.0/1024.0<<" MB\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4560kb

input:

2
4 3
0 2 3
3 4 2
0 3 1
3 1
1 3 100

output:

2 3 5 6 
0 100 100 

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

1000
2 9
0 2 396628655
1 2 268792718
0 2 16843338
1 2 717268783
0 1 693319712
0 1 856168102
1 2 407246545
1 2 527268921
0 1 536134606
6 2
2 5 451394766
0 5 695984050
9 7
0 6 73936815
2 9 505041862
4 5 223718927
5 7 179262261
3 5 449258178
0 5 493128
0 3 994723920
6 6
3 5 433389755
2 4 773727734
4 5 ...

output:


result: