QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575852#9313. Make Max1091857051WA 666ms91044kbJava82.4kb2024-09-19 17:02:052024-09-19 17:02:07

Judging History

你现在查看的是最新测评结果

  • [2024-09-19 17:02:07]
  • 评测
  • 测评结果:WA
  • 用时:666ms
  • 内存:91044kb
  • [2024-09-19 17:02:05]
  • 提交

answer

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
	static kattio sc=new kattio();
	static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	public static void main(String[] args) {
		int t=sc.nextint();
		while (t-->0) {
			sovle();
		}
		out.close();
	}
	static void sovle(){
		int n=sc.nextint();
		int []arr=new int[n+1];int max=0;
		int []q=new int[n+1];
		int []h=new int[n+1];Arrays.fill(h, n+1);
		for (int i = 1; i < arr.length; i++) {
			arr[i]=sc.nextint();
			max=Math.max(max, arr[i]);
		}
		Stack<Integer>stack=new Stack<>();
		for (int i = 1; i < arr.length; i++) {
			while (!stack.isEmpty()&&arr[i]>arr[stack.peek()]) {
				stack.pop();
			}
			if (!stack.isEmpty()) {
				q[i]=stack.peek();
			}
			stack.add(i);
		}
		int v=0;
		for (int i = n; i >0; i--) {
			arr[i]=Math.max(arr[i], v);
			v=Math.max(v, arr[i]);
		}
		stack.clear();
		for (int i = n; i >0; i--) {
			while (!stack.isEmpty()&&arr[i]>arr[stack.peek()]) {
				stack.pop();
			}
			if (!stack.isEmpty()) {
				h[i]=stack.peek();
			}
			stack.add(i);
		}
		long ans=0;
		for (int i = 1; i < q.length; i++) {
			ans+=i-q[i]-1+h[i]-i-1;
		}
		out.println(ans);
	}
}
class kattio extends PrintWriter{
	private BufferedReader b;
	private StringTokenizer st;
	public kattio(){this(System.in,System.out);}
	public kattio(InputStream i,OutputStream o){
		super(o);
		b=new BufferedReader(new InputStreamReader(i));
	}
	public kattio(String i,String o) throws IOException{
		super(o);
		b=new BufferedReader(new FileReader(i));
	}
	public String next(){
		try {
			while (st==null||!st.hasMoreElements()) {
				st=new StringTokenizer(b.readLine());
			}
			return st.nextToken();
		} catch (Exception e) {
			return null;
			// TODO: handle exception
		}
	}
	public int nextint(){return Integer.parseInt(next());}
	public long nextlong(){return Long.parseLong(next());}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 38ms
memory: 38448kb

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Wrong Answer
time: 666ms
memory: 91044kb

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:

2276620
2350054

result:

wrong answer 1st numbers differ - expected: '4084978', found: '2276620'