QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#717611#9252. Penguins in RefrigeratorzyxawaWA 6ms52708kbC++141.6kb2024-11-06 18:29:052024-11-06 18:29:07

Judging History

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

  • [2024-11-06 18:29:07]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:52708kb
  • [2024-11-06 18:29:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,x,lst,p[1000001],w[1000001],a[1000001],b[1000001],L[1000001],R[1000001],st[1000001][21],t[1000001],ind[1000001];
long long s=1;
basic_string <int> G[1000001];
priority_queue <pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
const int mod=1e9+7;
int query(int l,int r){
	int k=__lg(r-l+1);
	return max(st[l][k],st[r-(1<<k)+1][k]);
}
bool cmp(int x,int y){
	return w[x]>w[y];
}
void add(int i){
	for(;i<=n;i+=i&-i) t[i]++;
}
int ask(int i){
	int s=0;
	for(;i;i-=i&-i) s+=t[i];
	return s;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&p[i]),a[p[i]]=b[i]=i;
	for(int i=1;i<=n;i++) scanf("%d",&x),w[p[i]]=x;
	for(int i=1;i<=n;i++) st[i][0]=w[i];
	for(int k=1;k<=20;k++) for(int i=1;i+(1<<k)-1<=n;i++) st[i][k]=max(st[i][k-1],st[i+(1<<k-1)][k-1]);
	for(int i=1;i<=n;i++){
		if(w[i]>m/2) continue;
		int l=1,r=i;
		while(l<r){
			int mid=(l+r)/2;
			if(query(mid,i-1)+w[i]>m) l=mid+1;
			else r=mid;
		}
		L[i]=l-1,l=i,r=n;
		while(l<r){
			int mid=(l+r+1)/2;
			if(query(i+1,mid)+w[i]>m) r=mid-1;
			else l=mid;
		}
		R[i]=l+1,G[L[i]]+=i,G[i]+=R[i],ind[i]++,ind[R[i]]++;
	}
	sort(b+1,b+1+n,cmp);
	for(int i=1;i<=n;i++){
		if(w[i]>m/2) G[lst]+=i,lst=i,ind[i]++;
		add(b[i]);
		if(w[b[i]]<=m/2) s=s*(ask(R[b[i]]-1)-ask(L[b[i]]))%mod;
	}
	for(int i=0;i<=n;i++) if(!ind[i]) q.push({a[i],i});
	printf("%lld\n",s);
	while(q.size()){
		auto [k,x]=q.top();
		q.pop();
		if(k) printf("%d ",k);
		for(int y:G[x]) if(!--ind[y]) q.push({a[y],y});
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 52708kb

input:

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

output:

3
1 2 3 4 5 

result:

wrong answer 2nd lines differ - expected: '5 4 2 1 3', found: '1 2 3 4 5 '