样例过了,但是全部RE了,求助,不知道为啥runtimeerror
查看原帖
样例过了,但是全部RE了,求助,不知道为啥runtimeerror
915148
XieLee楼主2023/3/8 10:29
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class Main {
	static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
	static PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	static int n;
	static int [][]a;
	public static void main(String[] args) throws IOException {
		n=nextInt();
		a=new int[n][2];
		Lianbiao start=new Lianbiao();
		for(int i=0;i<n;i++)
		{
			a[i][0]=nextInt();
			a[i][1]=nextInt();
			
		}
		start.setValue(a[0][1]);
		for(int i=1;i<n;i++)
		{
			switch(a[i][0])
			{
			case 1:
				while(start.getPre()!=null)
				{
					start=start.getPre();
				}
				int count=1;
				while(start.getValue()!=a[i][1])
				{
					start=start.getNext();
					count++;
				}
				System.out.println(count);
				break;
			case 2:
				while(start.getPre()!=null)
				{
					start=start.getPre();
				}
				while(a[i][1]!=1)
				{
					start=start.getNext();
					a[i][1]--;
				}
				System.out.println(start.getValue());
				break;
			case 3:
				while(start.getPre()!=null)
				{
					start=start.getPre();
				}
				while(start.getValue()!=a[i][1])
				{
					start=start.getNext();
				}
				System.out.println(start.getPre()!=null?start.getPre().getValue():"-2147483647");
				break;
			case 4:
				while(start.getPre()!=null)
				{
					start=start.getPre();
				}
				while(start.getValue()!=a[i][1])
				{
					start=start.getNext();
				}
				System.out.println(start.getNext()!=null?start.getNext().getValue():"2147483647");
				break;
			case 5://insert
				while(a[i][1]>start.getValue())
				{
					if(a[i][1]<=start.getValue())
					{
						if(start.getPre()==null)
						{
							Lianbiao l=new Lianbiao();
							l.setValue(a[i][1]);
							l.setNext(start);
							start.setPre(l);
						}
						else if(start.getPre().getValue()<=a[i][1])
						{
							Lianbiao l=new Lianbiao();
							l.setValue(a[i][1]);
							l.setPre(start.getPre());
							l.setNext(start);
							start.getPre().setNext(l);
							start.setPre(l);
						}
						else
						{
							start=start.getPre();
						}
					}
					else
					{
						if(start.getNext()==null)
						{
							Lianbiao l=new Lianbiao();
							l.setValue(a[i][1]);
							l.setPre(start);
							start.setNext(l);
						}
						else if(start.getNext().getValue()>a[i][1])
						{
							Lianbiao l=new Lianbiao();
							l.setValue(a[i][1]);
							l.setPre(start);
							l.setNext(start.getNext());
							start.getNext().setPre(l);
							start.setNext(l);
						}
						else
						{
							start=start.getNext();
						}		
					}
				}
				break;
			}
		}
	}
	static int nextInt() {
		try {
			st.nextToken();
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		return (int)st.nval;
	}
}
class Lianbiao{
	int value;
	Lianbiao next;
	Lianbiao pre;
	public int getValue() {
		return value;
	}
	public void setValue(int value) {
		this.value = value;
	}
	public Lianbiao getNext() {
		return next;
	}
	public void setNext(Lianbiao next) {
		this.next = next;
	}
	public Lianbiao getPre() {
		return pre;
	}
	public void setPre(Lianbiao pre) {
		this.pre = pre;
	}
	
}

https://www.luogu.com.cn/record/104009288

2023/3/8 10:29
加载中...