QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#550417#9252. Penguins in Refrigeratorucup-team896#WA 55ms47568kbC++142.1kb2024-09-07 12:35:152024-09-07 12:35:17

Judging History

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

  • [2024-09-07 12:35:17]
  • 评测
  • 测评结果:WA
  • 用时:55ms
  • 内存:47568kb
  • [2024-09-07 12:35:15]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=1e6+5,P=1e9+7;
int n,W,ans=1;
vector<int>G[N];
set<pair<int,int>>Y;
vector<pair<int,int>>X;
priority_queue<int,vector<int>,greater<int>>Q;
int p[N],q[N],a[N],A[N],st[N],L[N],R[N],d[N];
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	cin>>n>>W;
	for(int i=1;i<=n;++i)cin>>p[i],q[p[i]]=i;
	for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=1;i<=n;++i)A[i]=a[p[i]];
	for(int i=1,top=0;i<=n;++i)
		if(A[i]<=W/2){
			int z=0;
			for(int l=1,r=top;l<=r;){
				const int mid=(l+r)>>1;
				if(A[st[mid]]+A[i]>W)z=mid,l=mid+1;
				else r=mid-1;
			}
			if(z)L[i]=st[z];
			else L[i]=0;
		}
		else{
			for(;top&&A[st[top]]<=A[i];--top);
			st[++top]=i;
		}
	for(int i=n,top=0;i>=1;--i)
		if(A[i]<=W/2){
			int z=0;
			for(int l=1,r=top;l<=r;){
				const int mid=(l+r)>>1;
				if(A[st[mid]]+A[i]>W)z=mid,l=mid+1;
				else r=mid-1;
			}
			if(z)R[i]=st[z];
			else R[i]=n+1;
		}
		else{
			for(;top&&A[st[top]]<=A[i];--top);
			st[++top]=i;
		}
	Y.emplace(0,0);
	for(int i=1;i<=n;++i)
		if(A[i]<=W/2)X.emplace_back(L[i],R[i]);
		else Y.emplace(i,1);
	Y.emplace(n+1,1);
	sort(X.begin(),X.end(),[&](pair<int,int>x,pair<int,int>y){
		return x.second-x.first<y.second-y.first;
	});
	for(auto [l,r]:X){
		int c=0;
		auto itl=next(Y.lower_bound(make_pair(l,-1))),itr=itl;
		while(itr!=Y.end()&&itr->first<=r)c+=itr->second,++itr;
		Y.erase(itl,itr);
		ans=1ll*ans*c%P;
		Y.emplace(r,c+1);
	}
	cout<<ans<<'\n';
	for(int i=1;i<=n;++i)
		if(A[i]<=W/2){
			if(L[i]>=1)G[q[i]].emplace_back(q[L[i]]);
			if(R[i]<=n)G[q[R[i]]].emplace_back(q[i]);
		}
	for(int i=1,j=0;i<=n;++i)
		if(A[i]>W/2){
			if(j)G[q[i]].emplace_back(q[j]);
			j=i;
		}
	for(int i=1;i<=n;++i)for(auto j:G[i])++d[j];
	for(int i=1;i<=n;++i)if(!d[i])Q.emplace(i);
	for(int i=1;i<=n;++i){
		int u=Q.top();Q.pop();
		cout<<u<<" \n"[i==n];
		for(auto v:G[u])if(!--d[v])Q.emplace(v);
	}
	return 0;
}
/*
*/

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 42428kb

input:

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

output:

3
5 4 2 1 3

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 10ms
memory: 41776kb

input:

5 10
1 2 3 4 5
2 4 3 3 8

output:

30
1 5 2 3 4

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 39712kb

input:

5 10
1 2 3 4 5
2 3 4 5 1

output:

120
1 2 3 4 5

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 3ms
memory: 42448kb

input:

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

output:

60
1 2 3 5 4

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 30ms
memory: 44632kb

input:

100000 96
1996 78922 45321 68844 32404 82013 66552 81163 17216 48170 35495 56660 13480 43118 23173 47257 50168 87069 26167 67231 31758 25694 61063 56642 8923 7727 54528 96554 38964 7604 6822 16256 45300 58869 31359 48638 87645 14779 81505 59585 89293 9291 7002 31810 84701 77648 78295 42595 11394 479...

output:

457992974
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...

result:

ok 2 lines

Test #6:

score: -100
Wrong Answer
time: 55ms
memory: 47568kb

input:

100000 84
93330 3894 94859 22134 49668 30606 26739 82976 76701 56323 75537 7626 87226 20857 98177 21811 70827 75898 8111 48223 26186 64222 63002 79024 19126 41638 1048 43857 25379 19764 60207 27675 77665 66327 6274 34861 30287 13449 64505 51490 5804 65843 49014 85795 12365 31565 34411 71697 66568 28...

output:

524727018
17609 25144 28710 32650 37825 46810 58859 60458 64502 64892 67718 68948 79326 89737 90927 92556 23867 35681 66474 1358 11204 11811 12244 13655 25824 28444 29952 32443 33123 34067 50885 54679 56377 72282 76518 79971 80568 81095 83739 87426 89917 46675 4067 12286 14477 19728 25502 33176 5106...

result:

wrong answer 2nd lines differ - expected: '1723 2800 15421 26278 31659 42...6 87226 93330 98177 26739 49668', found: '17609 25144 28710 32650 37825 ...3 27102 52218 82131 88738 95200'