题解:P13755 【MX-X17-T4】Yet another Game problem
做法
不需要那个结论。
先二分答案,设答案为
设
Alice 一定会走到一个全为
至于第一步可以走哪些,就是所有全
代码
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define pii pair<ll,ll>
#define fi first
#define se second
#define i128 __int128
#define ALL(x) x.begin(),x.end()
#define popcount(x) __builtin_popcountll(x)
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using namespace std;
const int INF=1e18;
const int N=1000005;
const int MOD1=1e9+7,MOD2=998244353;
const int MOD=MOD1;
int n,op;
int a[N],b[N];
bool check(int x){
for(int i=1;i<=n;i++){
b[i]=(a[i]>=x);
}
//从下到上扫
stack<int> stk;
for(int i=1;i<=n;i++){
if(b[i]==1){
stk.push(i);
if(i==n){
return 1;
}
}else{
if(i==n){
if(!stk.empty()&&stk.top()!=1){
return 1;
}else{
return 0;
}
}
if(!stk.empty())stk.pop();
}
}
}
void solve_(){
cin>>n>>op;
int mx=0;
for(int i=1;i<=n;i++){
cin>>a[i];
mx=max(mx,a[i]);
}
int l=1,r=mx,res=0;
while(l<=r){
int mid=(l+r)/2;
if(check(mid)){
res=mid;
l=mid+1;
}else{
r=mid-1;
}
}
cout<<res<<"\n";
if(op==1){
for(int i=1;i<=n;i++){
b[i]=(a[i]>=res);
}
stack<int> stk;
for(int i=1;i<=n;i++){
if(b[i]==1){
stk.push(i);
}else{
if(i!=n&&!stk.empty())stk.pop();
}
}
vector<int> vec;
while(!stk.empty()){
if(stk.top()!=1)vec.push_back(stk.top());
stk.pop();
}
sort(ALL(vec));
cout<<vec.size()<<"\n";
for(auto x:vec){
cout<<x<<" ";
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int testcase,multitest=0;
if(multitest)cin>>testcase;
else testcase=1;
while(testcase--){
solve_();
}
return 0;
}