QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#640516#9252. Penguins in Refrigeratorucup-team4153WA 9ms18920kbC++202.6kb2024-10-14 13:53:312024-10-14 13:53:31

Judging History

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

  • [2024-10-14 13:53:31]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:18920kb
  • [2024-10-14 13:53:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;using ll=long long;using i128=__int128;using ull=unsigned long long;using ld=long double;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pdd=pair<ld,ld>;
const int M=1e9+7,N=1e6+10;const ll inf=1e17;const ld eps=1e-10;
clock_t ct;bool ot;int tct=0;
void oT(char c='.'){cout<<c<<"Time:"<<double(clock()-ct)<<'\n';}
struct calcC{//precal needed
	ll poww(ll bs,ll x){ll res=1;for(bs=(bs%M+M)%M;x;x>>=1,(bs*=bs)%=M)if(x&1)(res*=bs)%=M;return res;}
	ll invv(ll bs){return poww(bs,M-2);}vector<ll>mul,inv;
	void precal(int P){mul.resize(P+1);mul[0]=1;for(int i=1;i<=P;i++)mul[i]=mul[i-1]*i%M;
		inv.resize(P+1);inv[P]=invv(mul[P]);for(int i=P;i;i--)inv[i-1]=inv[i]*i%M;}
	ll C(int n,int m){if(n<m||m<0)return 0;return mul[n]*inv[m]%M*inv[n-m]%M;}
	ll A(int n,int m){if(n<m||m<0)return 0;return mul[n]*inv[n-m]%M;}
}xC;
struct S
{	
	int n,lim,pt=0;set<int>xS;ll res=1;
	vector<int>h,pzi,toseg,cc,fc;vector<vector<int>>es,spe;
	struct node{int f,l,r,fc;};vector<node>nd;
	void Ade(int u,int v){u=pzi[u],v=pzi[v];spe[u].push_back(v);cc[v]++;}
	void gnew(int u,int _l,int _r){es[u].push_back(++pt);nd[pt]={u,_l,_r,0};toseg[_r]=pt;}
	int spr(int x)
	{
		int spz=nd[x].fc,siz=es[x].empty()^1;
		for(auto&k:es[x])siz+=spr(k);siz+=spz;(res*=xC.A(siz,spz))%=M;return siz;
	}
	void ini()
	{
		cin>>n>>lim;vector<int>g(n*2+2,0);toseg=pzi=h=cc=fc=g;
		nd.resize(n*2+2);es.resize(n*2+2);spe=es;
		for(int i=n;i;i--)cin>>pzi[i];for(int i=1;i<=n;i++)cin>>g[i];
		for(int i=n;i;i--)h[i]=g[pzi[i]];h[0]=h[n+1]=M;
		pt=0;pzi[0]=0,pzi[n+1]=n+1;nd[0]={0,0,n+1,0};xS.insert(n+1);toseg[n+1]=0;
		for(int i=1,lst=0;i<=n+1;i++)if(h[i]*2>lim)Ade(lst,i),lst=i;
		priority_queue<pii>Q;for(int i=1;i<=n;i++)Q.push(h[i]*2<=lim?pii{(lim-h[i])*2+1,i}:pii{h[i]*2,i});
		while(!Q.empty())
		{
			auto[v,x]=Q.top();Q.pop();int sp=abs(v)&1;			
			int rd=*xS.lower_bound(x),sg=toseg[rd];auto[_,l,r,z]=nd[sg];if(r^rd)exit(1);
			if(sp)fc[sg]++,Ade(x,rd),Ade(l,x);else xS.insert(x),gnew(sg,l,x),gnew(sg,x,r);
		}
		spr(0);cout<<res<<"\n";
	}
	void solve()
	{
		priority_queue<int>Q;Q.push(0);vector<int>res;
		while(!Q.empty())
		{
			auto x=Q.top();Q.pop();x=-x;res.push_back(x);
			for(auto&k:spe[x])if(!--cc[k])Q.push(-k);
		}
		for(int i=1;i<=n;i++)cout<<res[i]<<" \n"[i==n];
	}
};
void precal(){xC.precal(N);}
int main()
{
	//freopen("1.in","r",stdin);
	//cout<<fixed<<setprecision(12);
	ct=clock();
	ios::sync_with_stdio(0);cin.tie(0);precal();
	int t=1;//cin>>t;
	//clock_t a=clock();
	while(t--){tct++;S SS;SS.ini();SS.solve();}
	//cout<<"Time:"<<double(clock()-a)<<'\n';
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 9ms
memory: 18920kb

input:

5 10
1 2 3 4 5
6 5 3 9 2

output:

1
5 4 2 1 3

result:

wrong answer 1st lines differ - expected: '3', found: '1'