求卡常
查看原帖
求卡常
295864
eigw22h619楼主2022/8/26 09:34

O(mlogm)O(mlogm) , 1.04s,感觉挺有希望的样子

#include<bits/stdc++.h>
using namespace std;
namespace io
{
	#define L 2000000
	char ib[L],*iS,*iT,ob[L],*oS=ob,*oT=ob+L-1;
	int x;bool f;
	#define gc() (iS==iT?(iT=(iS=ib)+fread(ib,1,L,stdin),iS==iT?EOF:*iS++):*iS++)
	#define R register
	#define cn const
	inline int gi()
	{
		R char c=gc();
		for(f=0;c<'0'||c>'9';c=gc())f=(c==45);
		for(x=c&15,c=gc();c>='0'&&c<='9';c=gc())x=(x<<3)+(x<<1)+(c&15);
		return f?-x:x;
	}
	inline void Flush()
	{
		fwrite(ob,1,oS-ob,stdout);oS=ob;
	}
	#define pc(x) {*oS++=x;if(oS==oT)Flush();}
	template<typename _Tp>
	inline void pr(cn _Tp&x)
	{
		cn _Tp c=x/10;
		c&&(pr(c),0);
		pc(x-(c<<3)-(c<<1)|48);
	}
	template<typename _Tp>
	inline void pr(cn _Tp&x,cn char&c)
	{
		if(x<0){pc(45);pr(-x);}else pr(x);
		pc(c);
	}
}
using namespace io;
void msort(int*st,int*ed)//基数排序
{
	#define r 255
	#define For(i,l,r) for(int i=l;i<=r;++i)
	#define ref(i,r,l) for(int i=r;i>=l;--i)
	int n=ed-st,s1[256]={0},s2[256]={0},s3[256]={0},s4[256]={0};
	int *a=st,*b=new int [n];
	for(int i=0;i<n;++i)
	{
		++s1[a[i]&r];++s2[a[i]>>8&r];
		++s3[a[i]>>16&r];++s4[a[i]>>24&r];
	}
	For(i,1,r)s1[i]+=s1[i-1];
	For(i,1,r)s2[i]+=s2[i-1];
	For(i,1,r)s3[i]+=s3[i-1];
	For(i,1,r)s4[i]+=s4[i-1];
	ref(i,n-1,0)b[--s1[a[i]&r]]=a[i];
	ref(i,n-1,0)a[--s2[b[i]>>8&r]]=b[i];
	ref(i,n-1,0)b[--s3[a[i]>>16&r]]=a[i];
	ref(i,n-1,0)a[--s4[b[i]>>24&r]]=b[i];
	delete [] b;
	#undef for
	#undef ref
	#undef r
}
template<typename _Tp>
struct pq//priority_queue,本质是二叉堆
{
	_Tp t[14200001];int sz;pq(){}
private:
	void swim(int i)
	{
		for(;i!=1&&t[i]>t[i>>1];i>>=1)swap(t[i],t[i>>1]);
	}
	#define son(i) (i<<1|(t[i<<1|1]>t[i<<1]))
	void sink(int i)
	{
		for(int c=son(i);c<=sz&&t[c]>t[i];i=c,c=son(i))swap(t[i],t[c]);
	}
	#undef son
public:
	void push(const _Tp&x)
	{
		t[++sz]=x;swim(sz);
	}
	void pop()
	{
		swap(t[1],t[sz--]);sink(1);
	}
	#define top() t[1]
	void work(const int d,const int T)//输出第二行
	{
		for(int i=1;i<=sz;++i)t[i]+=d;
		msort(t+1,t+1+sz);
		for(int i=sz-T+1;i>0;i-=T)pr(t[i],32);
	}
};
pq<int>a;
int main()
{
	ios::sync_with_stdio(false);
	int n=gi();
	const int m=gi(),q=gi(),u=gi(),v=gi(),t=gi();
	while(n --> 0)a.push(gi());
	for(int i=1,ct=t,d=0;i<=m;++i)
	{
		const int p=a.top()+d;a.pop();
		i==ct&&(pr(p,32),ct+=t);
		const int c=(long long)p*u/v;d+=q;
		a.push(c-d);a.push(p-c-d);
	}
	pc(10);
	a.work(m*q,t);//输出第二行
	Flush();
	return 0;
}
2022/8/26 09:34
加载中...