19723分布式队列
⭐️难度:中等
🌟考点:模拟、2024省赛
📖
📚
java
import javax.sound.sampled.Line;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static int N = 100010;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] count = new int[n + 1]; // 记录分布式队列的元素个数
while(sc.hasNext()){
String str = sc.next();
if(str.equals("add")){
int x = sc.nextInt();
count[0] ++; // add操作都是主队列加
} else if (str.equals("sync")) {
int x = sc.nextInt();
count[x] = Math.min(count[x] + 1,count[0]); // 副队列元素个数不可能超过主队列
}else if(str.equals("query")){
int min = count[0]; // 先假定同步个数是最多的,再在遍历的过程中找最小的
for (int i = 1; i < n; i++) {
min = Math.min(min,count[i]);
}
System.out.println(min);
}
}
}
}