跳到正文

题解

P15773题解

Egicieb约 3 分钟
原文
文章信息与版本

文章信息

发布
2026年10月23日
收录
2026年10月27日
更新
2026年11月8日
篇幅
约 3 分钟
题目
P15573

版本

  1. v1当前

26.10.23的考试场切了

我好像在cf做过削弱版。

先想一下大概会按照什么顺序出牌

如果手里有胜利牌就优先出便宜的,没有的话也出最便宜的

这样一直出一会儿 就会发现手里有一些卡手的牌保留了

具体来说 后面一定是抽一打一,另外h-1张牌都是gunmu

所以先给胜利牌从小到大排序,再在这后面给非胜利牌从小到大排序

这样的后h-1个牌就将会成为gunmu

先模拟打出循环周期前的就可以了。后面每次查询时,做完循环剩下的部分二分就可以了。

C++
#include<bits/stdc++.h>
#define pi pair<int,int>
#define fi first
#define se second
#define int long long
using namespace std;
const int N=2e5+10;
int n,h,m,t,a[N];
pi sl[N];//用时 数量 
bool f[N];
struct node{
	int w;
	bool s;
};
bool operator <(node A,node B){
	if(A.s&&!B.s) return 0;
	if(!A.s&&B.s) return 1;
	return B.w<A.w;
}
queue<node> gt;
priority_queue<node> q;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	freopen("gunMu.in","r",stdin);
	freopen("Gunmu.out","w",stdout);
	cin>>n>>h;
	for(int i=1;i<=n;i++) cin>>a[i];
	cin>>m;
	for(int i=1;i<=m;i++){
		int x;cin>>x;
		f[x]=1;
	}
	for(int i=1;i<=h;i++) q.push({a[i],f[i]});
	for(int i=h+1;i<=n;i++) gt.push({a[i],f[i]});
	for(int i=1;i<=n-h+1;i++){
		int w=q.top().w,s=q.top().s; 
		q.pop();
		sl[i].fi=sl[i-1].fi+w;
		sl[i].se=sl[i-1].se+s;
		gt.push({w,s});
		node now=gt.front();
		gt.pop();
		q.push(now);//完整的出牌循环
	}
	cin>>t;
	while(t--){
		int zjx;cin>>zjx;
		int ans=zjx/sl[n-h+1].fi*sl[n-h+1].se;
		zjx%=sl[n-h+1].fi;
		int l=1,r=n-h+1,mid;
		while(l<=r){
			mid=l+r>>1;
			if(sl[mid].fi<=zjx) l=mid+1;
			else r=mid-1;
		}
		cout<<ans+sl[l-1].se<<'\n';
	} 
	return 0;
} 
/*
难道我真的是区? 
*/
原文