QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#575843#9313. Make Max1091857051WA 666ms86316kbJava82.3kb2024-09-19 16:58:522024-09-19 16:58:52

Judging History

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

  • [2024-09-19 16:58:52]
  • 评测
  • 测评结果:WA
  • 用时:666ms
  • 内存:86316kb
  • [2024-09-19 16:58:52]
  • 提交

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);
		}
		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+=h[i]-q[i]-2;
		}
		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());}
}

详细

Test #1:

score: 100
Accepted
time: 43ms
memory: 38504kb

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: 0
Accepted
time: 628ms
memory: 86316kb

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:

4084978
4130372

result:

ok 2 number(s): "4084978 4130372"

Test #3:

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

input:

2
195768
3086 1582 7854 5577 5243 2734 8054 4805 5686 7065 5555 2410 6240 7589 2889 3745 8094 9147 9438 1252 5497 5786 6655 4437 3933 2579 5722 9512 3117 1742 5362 2068 1853 4069 9231 1126 3991 420 2571 5517 3063 7279 8085 6111 5503 5980 50 6003 244 9684 6343 6517 1598 5223 5520 982 3932 1093 1149 7...

output:

3358939
3247917

result:

wrong answer 1st numbers differ - expected: '3061429', found: '3358939'