AcWing 3548. 双端队列
原题链接
中等
作者:
L_1
,
2021-05-22 23:35:12
,
所有人可见
,
阅读 255
题目描述
JAVA 代码
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int x;
int N = 200010;
int l = 0;
int r = 1;
int[] arr = new int[N];
while(n-- > 0){
s = br.readLine().split(" ");
x = Integer.parseInt(s[1]);
if(s[0].equals("L")) arr[x] = l--;
else if(s[0].equals("R"))
arr[x] = r++;
else
System.out.println(Math.min(r-arr[x]-1,arr[x]-l-1));
}
}
}