因为找不到什么好的题目 也没有什么好的想法 所以就找了一场没做过的题 正好当康复训练了 毕竟下周是牛客寒假训练营
但是远超预期 这场思维量比较大 有些东西还是想了很久很久
选自 Codeforces Round 1034 Div3
https://codeforces.com/contest/2123
实况

A
题目给出 a +b≡3(mod4)
翻译
a+b 除 3 余 4
则 a+b-3 是 4 的倍数
a 是 Alice 选的数
b 是 Bob 选的数
这两个数和必须是 3 7 11 15 19 ...
两个人 选 必须消耗掉所有的数
枚举即发现 每次选出两个数都能消耗, n 必须是 4 的倍数 Bob 就能赢
n=1: 0
n=2: 0 1
n=3: 0 1 2
n=4: 0 1 2 3 可以
n=5: 0 1 2 3 4
n=6: 0 1 2 3 4 5
n=7: 0 1 2 3 4 5 6
n=8: 0 1 2 3 4 5 6 7 可以
// https://github.com/Dddddduo/acm-java-algorithm
// powed by Dduo from bhu-acm
import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;
// 多多世界第一可爱!
public class Main {
private static IoScanner sc = new IoScanner();
// private static final long mod = (long) (1e9 + 7);
// private static final long mod = (long) (998244353);
private static int n;
private static int arr[];
private static boolean visited[];
private static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
private static Stack<Integer> stack = new Stack<>();
private static Queue<Integer> queue = new LinkedList<>();
private static Deque<Integer> deque = new LinkedList<>();
private static void solve() throws IOException {
int n = sc.nextInt();
if(n==0){
sc.println("Alice");
return;
}
if(n==1){
sc.println("Alice");
return;
}
if(n==2){
sc.println("Alice");
return;
}
if(n==3){
sc.println("Alice");
return;
}
if(n==4){
sc.println("Bob");
return;
}
if((n)%4==0){
sc.println("Bob");
}else{
sc.println("Alice");
}
}
public static void main(String[] args) throws Exception {
int t = 1;
t = sc.nextInt();
while (t-- > 0) {
solve();
}
sc.flush();
sc.bw.close();
}
private static <T> void dduo(T t) {
System.out.print(t);
}
private static <T> void dduoln() {
System.out.println("");
}
private static <T> void dduoln(T t) {
System.out.println(t);
}
}
class IoScanner {
BufferedReader bf;
StringTokenizer st;
BufferedWriter bw;
public IoScanner() {
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
protected String nextLine() throws IOException {
return bf.readLine();
}
protected String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
protected char nextChar() throws IOException {
return next().charAt(0);
}
protected int nextInt() throws IOException {
return Integer.parseInt(next());
}
protected long nextLong() throws IOException {
return Long.parseLong(next());
}
protected double nextDouble() throws IOException {
return Double.parseDouble(next());
}
protected float nextFloat() throws IOException {
return Float.parseFloat(next());
}
protected BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
protected BigDecimal nextDecimal() throws IOException {
return new BigDecimal(next());
}
protected void println(int a) throws IOException{
print(a);
println();
}
protected void print(int a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(String a) throws IOException{
print(a);
println();
}
protected void print(String a) throws IOException{
bw.write(a);
}
protected void println(long a) throws IOException{
print(a);
println();
}
protected void print(long a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(double a) throws IOException{
print(a);
println();
}
protected void print(double a) throws IOException{
bw.write(String.valueOf(a));
}
protected void print(BigInteger a) throws IOException{
bw.write(a.toString());
}
protected void println(BigInteger a) throws IOException{
bw.write(a.toString());
println();
}
protected void print(char a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(char a) throws IOException{
print(a);
println();
}
protected void println() throws IOException{
bw.newLine();
}
//其他调试命令:
protected void flush() throws IOException{
//交互题分组调试,或者提前退出的情况下可以先运行此语句再推出
bw.flush();
return;
}
protected boolean hasNext() throws IOException{
//本地普通IDE难以使用这个方法调试,需要按照数据组flush,刷新语句:
//sc.flush()
//调试完可删去
return bf.ready();
}
}
B
贪心找最优解
操作两个数 留下一个数
如果最后剩 1 个以上的数 完全可以做到并不处理我们想要留下的数值 将其他所有的数操作减少即可
如果最后剩 1 个数 这个数必会和其他数比较
这个我们想要留下的数如果是最小的话 那么必会在比较中被淘汰
所以他不能是最小的
// https://github.com/Dddddduo/acm-java-algorithm
// powed by Dduo from bhu-acm
import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;
// 多多世界第一可爱!
public class Main {
private static IoScanner sc = new IoScanner();
// private static final long mod = (long) (1e9 + 7);
// private static final long mod = (long) (998244353);
private static int n;
private static int arr[];
private static boolean visited[];
private static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
private static Stack<Integer> stack = new Stack<>();
private static Queue<Integer> queue = new LinkedList<>();
private static Deque<Integer> deque = new LinkedList<>();
private static void solve() throws IOException {
int n=sc.nextInt();
int j=sc.nextInt()-1;
int k=sc.nextInt();
int arr[]=new int[n];
HashMap<Integer, Integer> map = new HashMap<>();
int min=Integer.MAX_VALUE;
int max=Integer.MIN_VALUE;
for(int i=0;i<n;i++) {
arr[i]=sc.nextInt();
min=Math.min(min,arr[i]);
max=Math.max(max,arr[i]);
map.put(arr[i],map.getOrDefault(arr[i],0)+1);
}
if(k==1&&arr[j]<max) {
sc.println("NO");
return;
}
sc.println("YES");
}
public static void main(String[] args) throws Exception {
int t = 1;
t = sc.nextInt();
while (t-- > 0) {
solve();
}
sc.flush();
sc.bw.close();
}
private static <T> void dduo(T t) {
System.out.print(t);
}
private static <T> void dduoln() {
System.out.println("");
}
private static <T> void dduoln(T t) {
System.out.println(t);
}
}
class IoScanner {
BufferedReader bf;
StringTokenizer st;
BufferedWriter bw;
public IoScanner() {
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
protected String nextLine() throws IOException {
return bf.readLine();
}
protected String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
protected char nextChar() throws IOException {
return next().charAt(0);
}
protected int nextInt() throws IOException {
return Integer.parseInt(next());
}
protected long nextLong() throws IOException {
return Long.parseLong(next());
}
protected double nextDouble() throws IOException {
return Double.parseDouble(next());
}
protected float nextFloat() throws IOException {
return Float.parseFloat(next());
}
protected BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
protected BigDecimal nextDecimal() throws IOException {
return new BigDecimal(next());
}
protected void println(int a) throws IOException{
print(a);
println();
}
protected void print(int a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(String a) throws IOException{
print(a);
println();
}
protected void print(String a) throws IOException{
bw.write(a);
}
protected void println(long a) throws IOException{
print(a);
println();
}
protected void print(long a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(double a) throws IOException{
print(a);
println();
}
protected void print(double a) throws IOException{
bw.write(String.valueOf(a));
}
protected void print(BigInteger a) throws IOException{
bw.write(a.toString());
}
protected void println(BigInteger a) throws IOException{
bw.write(a.toString());
println();
}
protected void print(char a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(char a) throws IOException{
print(a);
println();
}
protected void println() throws IOException{
bw.newLine();
}
//其他调试命令:
protected void flush() throws IOException{
//交互题分组调试,或者提前退出的情况下可以先运行此语句再推出
bw.flush();
return;
}
protected boolean hasNext() throws IOException{
//本地普通IDE难以使用这个方法调试,需要按照数据组flush,刷新语句:
//sc.flush()
//调试完可删去
return bf.ready();
}
}
C
改变自力扣 hard 题接雨水
https://leetcode.cn/problems/trapping-rain-water/description/

// https://github.com/Dddddduo/acm-java-algorithm
// powed by Dduo from bhu-acm
import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;
// 多多世界第一可爱!
public class Main {
private static IoScanner sc = new IoScanner();
// private static final long mod = (long) (1e9 + 7);
// private static final long mod = (long) (998244353);
private static int n;
private static int arr[];
private static boolean visited[];
private static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
private static Stack<Integer> stack = new Stack<>();
private static Queue<Integer> queue = new LinkedList<>();
private static Deque<Integer> deque = new LinkedList<>();
private static void solve() throws IOException {
int n = sc.nextInt();
int[] a = new int[n + 1];
// 前缀
int[] preSum = new int[n + 1];
// 后缀
int[] sufSum = new int[n + 2];
boolean[] judge= new boolean[n + 1];
preSum[0] = Integer.MAX_VALUE;
for (int i = 1; i <= n; i++) {
a[i] = sc.nextInt();
preSum[i] = Math.min(preSum[i - 1], a[i]);
if(a[i]==preSum[i]){
judge[i]=true;
}
}
sufSum[n+1] = Integer.MIN_VALUE;
for (int i = n; i >= 1; i--) {
sufSum[i] = Math.max(sufSum[i + 1], a[i]);
if(a[i]==sufSum[i]){
judge[i]=true;
}
}
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= n; i++) {
if(judge[i]==true){
sb.append("1");
}else {
sb.append("0");
}
}
sc.println(sb.toString());
}
public static void main(String[] args) throws Exception {
int t = 1;
t = sc.nextInt();
while (t-- > 0) {
solve();
}
sc.flush();
sc.bw.close();
}
private static <T> void dduo(T t) {
System.out.print(t);
}
private static <T> void dduoln() {
System.out.println("");
}
private static <T> void dduoln(T t) {
System.out.println(t);
}
}
class IoScanner {
BufferedReader bf;
StringTokenizer st;
BufferedWriter bw;
public IoScanner() {
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
protected String nextLine() throws IOException {
return bf.readLine();
}
protected String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
protected char nextChar() throws IOException {
return next().charAt(0);
}
protected int nextInt() throws IOException {
return Integer.parseInt(next());
}
protected long nextLong() throws IOException {
return Long.parseLong(next());
}
protected double nextDouble() throws IOException {
return Double.parseDouble(next());
}
protected float nextFloat() throws IOException {
return Float.parseFloat(next());
}
protected BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
protected BigDecimal nextDecimal() throws IOException {
return new BigDecimal(next());
}
protected void println(int a) throws IOException{
print(a);
println();
}
protected void print(int a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(String a) throws IOException{
print(a);
println();
}
protected void print(String a) throws IOException{
bw.write(a);
}
protected void println(long a) throws IOException{
print(a);
println();
}
protected void print(long a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(double a) throws IOException{
print(a);
println();
}
protected void print(double a) throws IOException{
bw.write(String.valueOf(a));
}
protected void print(BigInteger a) throws IOException{
bw.write(a.toString());
}
protected void println(BigInteger a) throws IOException{
bw.write(a.toString());
println();
}
protected void print(char a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(char a) throws IOException{
print(a);
println();
}
protected void println() throws IOException{
bw.newLine();
}
//其他调试命令:
protected void flush() throws IOException{
//交互题分组调试,或者提前退出的情况下可以先运行此语句再推出
bw.flush();
return;
}
protected boolean hasNext() throws IOException{
//本地普通IDE难以使用这个方法调试,需要按照数据组flush,刷新语句:
//sc.flush()
//调试完可删去
return bf.ready();
}
}
D
首先第一轮 Alice 先手抹去所有 1 直接获胜
之后思考 如何陷入死循环
就是 Alice 必定赢不了
首先放缩 n 至无限大
不难想到 现在有 5 个 1 每次染 4 个
Alice 染了 4 个 1 Bob 又将其变成 1 ... 以此反复
这样 Alice 永远不会获胜
这样的假设是 n 无限大
我们再把 n 缩小
Alice 每次选的 k 个位置,Bob 选 k 个位置 而这 k 个位置正好包含了先前的 5 个中的 1 个
那 n 必有一个边界
之后贪心 发现 Alice 每次都从两边染使用 Bob 操作机会会变少
画图 举例 发现 n<2*k 的时候 Alice 每次都能染先前的 5 个中的 1 个

// https://github.com/Dddddduo/acm-java-algorithm
// powed by Dduo from bhu-acm
import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;
// 多多世界第一可爱!
public class Main {
private static IoScanner sc = new IoScanner();
// private static final long mod = (long) (1e9 + 7);
// private static final long mod = (long) (998244353);
private static int n;
private static int arr[];
private static boolean visited[];
private static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
private static Stack<Integer> stack = new Stack<>();
private static Queue<Integer> queue = new LinkedList<>();
private static Deque<Integer> deque = new LinkedList<>();
private static void solve() throws IOException {
int n = sc.nextInt();
int k = sc.nextInt();
String s = sc.next();
int cnt1=0;
for (int i = 0; i < n; i++) {
char ch = s.charAt(i);
if(ch=='1') cnt1++;
}
if(cnt1<=k){
sc.println("Alice");
return;
}
// 奇数
if(n%2!=0&&k*2>n){
sc.println("Alice");
return;
}
// 偶数
if(n%2==0&&k*2>n){
sc.println("Alice");
return;
}
sc.println("Bob");
}
public static void main(String[] args) throws Exception {
int t = 1;
t = sc.nextInt();
while (t-- > 0) {
solve();
}
sc.flush();
sc.bw.close();
}
private static <T> void dduo(T t) {
System.out.print(t);
}
private static <T> void dduoln() {
System.out.println("");
}
private static <T> void dduoln(T t) {
System.out.println(t);
}
}
class IoScanner {
BufferedReader bf;
StringTokenizer st;
BufferedWriter bw;
public IoScanner() {
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
protected String nextLine() throws IOException {
return bf.readLine();
}
protected String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
protected char nextChar() throws IOException {
return next().charAt(0);
}
protected int nextInt() throws IOException {
return Integer.parseInt(next());
}
protected long nextLong() throws IOException {
return Long.parseLong(next());
}
protected double nextDouble() throws IOException {
return Double.parseDouble(next());
}
protected float nextFloat() throws IOException {
return Float.parseFloat(next());
}
protected BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
protected BigDecimal nextDecimal() throws IOException {
return new BigDecimal(next());
}
protected void println(int a) throws IOException{
print(a);
println();
}
protected void print(int a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(String a) throws IOException{
print(a);
println();
}
protected void print(String a) throws IOException{
bw.write(a);
}
protected void println(long a) throws IOException{
print(a);
println();
}
protected void print(long a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(double a) throws IOException{
print(a);
println();
}
protected void print(double a) throws IOException{
bw.write(String.valueOf(a));
}
protected void print(BigInteger a) throws IOException{
bw.write(a.toString());
}
protected void println(BigInteger a) throws IOException{
bw.write(a.toString());
println();
}
protected void print(char a) throws IOException{
bw.write(String.valueOf(a));
}
protected void println(char a) throws IOException{
print(a);
println();
}
protected void println() throws IOException{
bw.newLine();
}
//其他调试命令:
protected void flush() throws IOException{
//交互题分组调试,或者提前退出的情况下可以先运行此语句再推出
bw.flush();
return;
}
protected boolean hasNext() throws IOException{
//本地普通IDE难以使用这个方法调试,需要按照数据组flush,刷新语句:
//sc.flush()
//调试完可删去
return bf.ready();
}
}
E
如草稿所示
举例 0 0 1 1 2 我们得到的 mex 只能是 0 1 2
举例 0 0 2 2 3 我们得到的 mex 只能是 0 1
不难发现 mex 值对答案有最终有贡献 所以反推
接下来思考 0 0 1 1 2
如何删掉一部分数 使 mex 等于 1
首先我们想到的是 肯定要把 1 全删掉
其次 不能破坏原先结构 即不能把两个 0 都删掉 可以删一个 等效于可以留一个 即删 2,3,4 个数 可以得到 mex 为 1
同理思考 如何删掉一部分数 使 mex 等于 2 不难想象是 2,3,4 个数
下界:mex 出现的次数
上界:mex 出现的次数 + mex 前面的数只出现一次 + mex 后面有多少数
不难得出为 [hm.get(mex),n-mex-1+1]
连续区间的贡献值使用差分数组即可~

// https://github.com/Dddddduo/acm-java-algorithm
// powed by Dduo from bhu-acm
import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;
// 多多世界第一可爱!
public class Main {
private static IoScanner sc = new IoScanner();
// private static final long mod = (long) (1e9 + 7);
// private static final long mod = (long) (998244353);
private static int n;
private static int arr[];
private static boolean visited[];
private static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
private static Stack<Integer> stack = new Stack<>();
private static Queue<Integer> queue = new LinkedList<>();
private static Deque<Integer> deque = new LinkedList<>();
private static void solve() throws IOException {
int n = sc.nextInt();
int arr[] = new int[n];
HashMap<Integer, Integer> map = new HashMap<>();
int mex=0;
for (int i1 = 0; i1 < n; i1++) {
arr[i1] = sc.nextInt();
map.put(arr[i1], map.getOrDefault(arr[i1], 0) + 1);
}
Arrays.sort(arr);
for (int i1 = 0; i1 < n; i1++) {
if(arr[i1]==mex)mex++;
}
// map.forEach((key, value) -> {
// try {
// sc.println(key+" "+value);
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// });
// sc.println(mex);
int diff[] = new int[n + 2];
// 0~mex
for(int i=0;i<=mex;i++){
if(map.containsKey(i))diff[map.get(i)]++;
else diff[0]++;
diff[n-i+1]--;
// sc.println(map.get(i)+" "+(n-i+1));
}
int result = 0;
StringBuilder sb = new StringBuilder();
// 0~n
for (int i1 = 0; i1 < n+1; i1++) {
// sc.println(diff[i1]);
result += diff[i1];
sb.append(result+" ");
}
sc.println(sb.toString());
}
/**
1
5
1 0 0 1 2
*/
public static void main(String[] args) throws Exception {
int t = 1;
t = sc.nextInt();
while (t-- > 0) {
solve();
}
sc.flush();
sc.bw.close();
}
private static <T> void dduo(T t) {
System.out.print(t);
}
private static <T> void dduoln() {
System.out.println("");
}
private static <T> void dduoln(T t) {
System.out.println(t);
}
}
class IoScanner {
BufferedReader bf;
StringTokenizer st;
BufferedWriter bw;
public IoScanner() {
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
protected String nextLine() throws IOException {
return bf.readLine();
}
protected String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
protected char nextChar() throws IOException {
return next().charAt(0);
}
protected int nextInt() throws IOException {
return Integer.parseInt(next());
}
protected long nextLong() throws IOException {
return Long.parseLong(next());
}
protected double nextDouble() throws IOException {
return Double.parseDouble(next());
}
protected float nextFloat() throws IOException {
return Float.parseFloat(next());
}
protected BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
protected BigDecimal nextDecimal() throws IOException {
return new BigDecimal(next());
}
protected void println(int a) throws IOException {
print(a);
println();
}
protected void print(int a) throws IOException {
bw.write(String.valueOf(a));
}
protected void println(String a) throws IOException {
print(a);
println();
}
protected void print(String a) throws IOException {
bw.write(a);
}
protected void println(long a) throws IOException {
print(a);
println();
}
protected void print(long a) throws IOException {
bw.write(String.valueOf(a));
}
protected void println(double a) throws IOException {
print(a);
println();
}
protected void print(double a) throws IOException {
bw.write(String.valueOf(a));
}
protected void print(BigInteger a) throws IOException {
bw.write(a.toString());
}
protected void println(BigInteger a) throws IOException {
bw.write(a.toString());
println();
}
protected void print(char a) throws IOException {
bw.write(String.valueOf(a));
}
protected void println(char a) throws IOException {
print(a);
println();
}
protected void println() throws IOException {
bw.newLine();
}
//其他调试命令:
protected void flush() throws IOException {
//交互题分组调试,或者提前退出的情况下可以先运行此语句再推出
bw.flush();
return;
}
protected boolean hasNext() throws IOException {
//本地普通IDE难以使用这个方法调试,需要按照数据组flush,刷新语句:
//sc.flush()
//调试完可删去
return bf.ready();
}
}