跳到正文

剪贴板

剪贴板 u2mfh1oa

Loop1st
原文
剪贴板信息

剪贴板信息

发布
收录
更新

WrongAnswer_90’s NOIP 2023 T4 Code, don’t delete

C++
//freopen/xyx/xyx
//Lgx winwinwin,dwt winwinwin,HMSF winwinwin,Larry76 winwinwin,modinte winwinwin,lzsbg winwinwin,LHLeisus winwinwin,cly winwinwin,dyyzy winwinwin,WA90 loseloselose
#include<bits/stdc++.h>

#define LL
#define LOCALJUDGE

#ifdef LL
#define int long long
#endif

#define ll long long
#define pii pair<int,int>
#define ld long double
#define mp make_pair
#define fi first
#define se second
#define e emplace
#define ef emplace_front
#define eb emplace_back
using namespace std;
bool ST;
constexpr ll MOD=998244353;
constexpr ll inf=1073741824;
constexpr ll INF=4611686018427387904;
constexpr ld eps=1e-9;
namespace FastIO
{
	inline void read(int&x)
	{
		x=0;char ch=getchar();
		while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
		bool tf=(ch=='-')&&(ch=getchar());
		while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
		tf?x=-x:0;
	}
	inline void write(int x,char ch=' ')
	{
		static char st[41];int top=0;
		if(x<0)putchar('-'),x=-x;
		do st[++top]=x%10+'0',x/=10;while(x);
		while(top)putchar(st[top--]);
		putchar(ch);
	}
	#ifndef LL
	inline void read(ll&x)
	{
		x=0;char ch=getchar();
		while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
		bool tf=(ch=='-')&&(ch=getchar());
		while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
		tf?x=-x:0;
	}
	inline void write(ll x,char ch=' ')
	{
		static char st[41];int top=0;
		if(x<0)putchar('-'),x=-x;
		do st[++top]=x%10+'0',x/=10;while(x);
		while(top)putchar(st[top--]);
		putchar(ch);
	}
	#endif
	template<typename...Args> inline void read(int&x,Args&...args){read(x),read(args...);}
}
using namespace FastIO;
namespace MTool
{
	inline void Madd(int&x,int y){x=x+y>=MOD?x+y-MOD:x+y;}
	inline void Mdel(int&x,int y){x=x-y<0?x-y+MOD:x-y;}
	inline void Mmul(int&x,int y){x=x*y%MOD;}
	inline int Cadd(int x,int y){return x+y>=MOD?x+y-MOD:x+y;}
	inline int Cdel(int x,int y){return x-y<0?x-y+MOD:x-y;}
	inline int Cmul(int x,int y){return x*y%MOD;}
	template<typename...Args> inline void Madd(int&x,int y,Args...args){Madd(x,y),Madd(x,args...);}
	template<typename...Args> inline void Mdel(int&x,int y,Args...args){Mdel(x,y),Mdel(x,args...);}
	template<typename...Args> inline void Mmul(int&x,int y,Args...args){Mmul(x,y),Mmul(x,args...);}
	template<typename...Args> inline int Cadd(int x,int y,Args...args){return Cadd(Cadd(x,y),args...);}
	template<typename...Args> inline int Cdel(int x,int y,Args...args){return Cdel(x,Cadd(x,args...));}
	template<typename...Args> inline int Cmul(int x,int y,Args...args){return Cmul(Cmul(x,y),args...);}
}
using namespace MTool;
namespace WrongAnswer_90
{
	int c,T,n,m,K,D,oth[100010],pos[100010],from[100010],sum[100010],f[100010],pre[100010];
	struct Node{int l,r,k,id;}a[100010],b[100010];
	vector<int> ve[100010];
	inline bool cmp(Node nd1,Node nd2){return nd1.r<nd2.r||(nd1.r==nd2.r&&nd1.l<nd2.l);}
	inline bool cmp2(Node nd1,Node nd2){return nd1.l<nd2.l||(nd1.l==nd2.l&&nd1.r<nd2.r);}
	namespace Segment
	{
		struct{int l,r,tag,maxn;}t[400010];
		inline void update(int p){t[p].maxn=max(t[p*2].maxn,t[p*2+1].maxn);}
		inline void down(int p,int x){t[p].maxn+=x,t[p].tag+=x;}
		inline void spread(int p){down(p*2,t[p].tag),down(p*2+1,t[p].tag),t[p].tag=0;}
		void build(int p,int l,int r)
		{
			t[p].l=l,t[p].r=r;
			if(l==r)return t[p].maxn=D*b[l].l-INF,void();
			int mid=l+((r-l)>>1);
			build(p*2,l,mid),build(p*2+1,mid+1,r),update(p);
		}
		void modify(int p,int l,int r,int k)
		{
			if(l<=t[p].l&&r>=t[p].r)return down(p,k);
			spread(p);
			if(l<=t[p*2].r)modify(p*2,l,r,k);
			if(r>t[p*2].r)modify(p*2+1,l,r,k);
			update(p);
		}
		int ask(int p,int l,int r)
		{
			if(l<=t[p].l&&r>=t[p].r)return t[p].maxn;
			spread(p);int s=-INF;
			if(l<=t[p*2].r)s=max(s,ask(p*2,l,r));
			if(r>t[p*2].r)s=max(s,ask(p*2+1,l,r));
			return s;
		}
	}
	using namespace Segment;
	inline void mian()
	{
		read(c,T);
		while(T--)
		{
			read(n,m,K,D),b[0].l=-INF,ve[0].clear();
			for(int i=0;i<=400000;++i)t[i]={0,0,0,0};
			for(int i=1;i<=m;++i)
			{
				ve[i].clear(),read(a[i].r,a[i].l,a[i].k),a[i].l=a[i].r-a[i].l+1,a[i].id=i,b[i]=a[i];
				if(a[i].r-a[i].l+1>K){--i,--m;continue;}
			}
			sort(a+1,a+1+m,cmp),memset(sum,0,sizeof(sum)),f[0]=0,a[0].r=-1;
			sort(b+1,b+1+m,cmp2),build(1,1,m);
			for(int i=1;i<=m;++i)oth[a[i].id]=i,f[i]=-INF;
			for(int i=1;i<=m;++i)
			{
				int l=0,r=i-1,mid;
				while(l<r)
				{
					mid=l+((r-l+1)>>1);
					if(a[mid].r<a[i].l-1)l=mid;
					else r=mid-1;
				}
				pre[i]=l;
			}
			for(int i=1;i<=m;++i)ve[pre[oth[b[i].id]]].eb(i);
			for(auto j:ve[0])modify(1,j,j,INF);
			for(int i=1;i<=m;++i)
			{
				int l=1,r=m,mid=-1;
				while(l<r)
				{
					mid=l+((r-l+1)>>1);
					if(b[mid].l<=a[i].l)l=mid;
					else r=mid-1;
				}
				modify(1,1,l,a[i].k);
				l=1,r=m;
				while(l<r)
				{
					mid=l+((r-l)>>1);
					if(b[mid].l>=a[i].r-K+1)r=mid;
					else l=mid+1; 
				}
				f[i]=max(f[i-1],ask(1,l,m)-D*a[i].r-D);
				for(auto j:ve[i])modify(1,j,j,f[i]+INF);
			}
			write(f[m],'\n');
		}
	}
}
bool ED;
signed main()
{
//	#ifdef LOCALJUDGE
//	freopen("run.in","r",stdin);
//	freopen("run.out","w",stdout);
//	#endif
	double st=clock();
	WrongAnswer_90::mian();
	double ed=clock();
	cerr<<"\nTime:"<<ed-st<<" ms\n";
	cerr<<"Memory:"<<abs(&ED-&ST)/1024.0/1024.0<<" mb\n";
	return 0;
}