답안 #1005730

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005730 2024-06-22T23:12:48 Z Username_taken12 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) Java 11
100 / 100
2140 ms 185564 KB
import java.io.*;
import java.util.*;

public class sortbooks {
	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);

		StringTokenizer st = new StringTokenizer(r.readLine());
		TreeMap<Integer,Integer> map = new TreeMap<>();
		map.put(-1, 0);
		Stack<int[]> stack = new Stack<>();
		stack.add(new int[]{2100000000, -100});
		int N = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		map.put(N+1, 2100000001);

		st = new StringTokenizer(r.readLine());
		int[] a = new int[N];
		for(int i=0; i<N; i++)
			a[i]=Integer.parseInt(st.nextToken());
		int[][] queries = new int[Q][4];
		for(int i=0; i<Q; i++)
		{
			st=new StringTokenizer(r.readLine());
			queries[i]=new int[]{Integer.parseInt(st.nextToken())-1, Integer.parseInt(st.nextToken())-1, Integer.parseInt(st.nextToken()), i};
		}

		Arrays.sort(queries, new Comp());
		boolean[] ans = new boolean[Q];
		int qp=0;
		for(int i=N-1; i>-1; i--){
			//System.out.println(i);
			int[] it = new int[]{-1,-1};
			//System.out.println(stack);
			while(a[i]>stack.peek()[0]){
				it=stack.pop();
				while(true){
					int next=map.ceilingKey(it[1]);
					//System.out.println(it[1]);
					if(map.get(next)<=it[0]+a[i])
						map.remove(next);
					else
						break;
					//System.out.println("True");
				}
				map.put(it[1],it[0]+a[i]);
				//System.out.println("around and around");
			}
			//System.out.println("exit");
			if(a[i]==stack.peek()[0])
				stack.pop();
			stack.add(new int[]{a[i], i});
			while(qp<Q&&i==queries[qp][0])
			{
				ans[queries[qp][3]]=queries[qp][2]>=map.get(map.floorKey(queries[qp][1]));
				qp++;
			}
		}
		for(int i=0; i<Q; i++)
			pw.println((ans[i] ? 1 : 0));
		pw.close();
	}
}
class Comp implements Comparator<int[]>{
	public int compare(int[] a, int[] b){
		return Integer.compare(-a[0],-b[0]);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 22560 KB Output is correct
2 Correct 55 ms 28204 KB Output is correct
3 Correct 74 ms 22112 KB Output is correct
4 Correct 58 ms 26488 KB Output is correct
5 Correct 53 ms 26500 KB Output is correct
6 Correct 84 ms 24072 KB Output is correct
7 Correct 88 ms 23860 KB Output is correct
8 Correct 78 ms 26188 KB Output is correct
9 Correct 64 ms 22432 KB Output is correct
10 Correct 74 ms 24280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 22560 KB Output is correct
2 Correct 55 ms 28204 KB Output is correct
3 Correct 74 ms 22112 KB Output is correct
4 Correct 58 ms 26488 KB Output is correct
5 Correct 53 ms 26500 KB Output is correct
6 Correct 84 ms 24072 KB Output is correct
7 Correct 88 ms 23860 KB Output is correct
8 Correct 78 ms 26188 KB Output is correct
9 Correct 64 ms 22432 KB Output is correct
10 Correct 74 ms 24280 KB Output is correct
11 Correct 206 ms 25768 KB Output is correct
12 Correct 243 ms 30164 KB Output is correct
13 Correct 247 ms 30676 KB Output is correct
14 Correct 417 ms 26964 KB Output is correct
15 Correct 387 ms 27104 KB Output is correct
16 Correct 393 ms 29912 KB Output is correct
17 Correct 314 ms 33176 KB Output is correct
18 Correct 353 ms 29260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1967 ms 129884 KB Output is correct
2 Correct 2029 ms 164284 KB Output is correct
3 Correct 2140 ms 168588 KB Output is correct
4 Correct 2036 ms 168488 KB Output is correct
5 Correct 1789 ms 178220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 886 ms 44120 KB Output is correct
2 Correct 969 ms 41420 KB Output is correct
3 Correct 794 ms 38056 KB Output is correct
4 Correct 832 ms 42100 KB Output is correct
5 Correct 713 ms 43960 KB Output is correct
6 Correct 1062 ms 38736 KB Output is correct
7 Correct 982 ms 44288 KB Output is correct
8 Correct 794 ms 38192 KB Output is correct
9 Correct 731 ms 36456 KB Output is correct
10 Correct 688 ms 37672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 22560 KB Output is correct
2 Correct 55 ms 28204 KB Output is correct
3 Correct 74 ms 22112 KB Output is correct
4 Correct 58 ms 26488 KB Output is correct
5 Correct 53 ms 26500 KB Output is correct
6 Correct 84 ms 24072 KB Output is correct
7 Correct 88 ms 23860 KB Output is correct
8 Correct 78 ms 26188 KB Output is correct
9 Correct 64 ms 22432 KB Output is correct
10 Correct 74 ms 24280 KB Output is correct
11 Correct 206 ms 25768 KB Output is correct
12 Correct 243 ms 30164 KB Output is correct
13 Correct 247 ms 30676 KB Output is correct
14 Correct 417 ms 26964 KB Output is correct
15 Correct 387 ms 27104 KB Output is correct
16 Correct 393 ms 29912 KB Output is correct
17 Correct 314 ms 33176 KB Output is correct
18 Correct 353 ms 29260 KB Output is correct
19 Correct 1099 ms 55988 KB Output is correct
20 Correct 1085 ms 62540 KB Output is correct
21 Correct 1089 ms 54616 KB Output is correct
22 Correct 1141 ms 61420 KB Output is correct
23 Correct 1233 ms 57680 KB Output is correct
24 Correct 916 ms 59704 KB Output is correct
25 Correct 920 ms 59588 KB Output is correct
26 Correct 922 ms 59148 KB Output is correct
27 Correct 911 ms 61276 KB Output is correct
28 Correct 838 ms 59280 KB Output is correct
29 Correct 834 ms 60224 KB Output is correct
30 Correct 784 ms 60196 KB Output is correct
31 Correct 937 ms 58752 KB Output is correct
32 Correct 961 ms 64540 KB Output is correct
33 Correct 981 ms 58624 KB Output is correct
34 Correct 1220 ms 60388 KB Output is correct
35 Correct 1128 ms 64180 KB Output is correct
36 Correct 1062 ms 59848 KB Output is correct
37 Correct 1096 ms 64468 KB Output is correct
38 Correct 1138 ms 60340 KB Output is correct
39 Correct 965 ms 63776 KB Output is correct
40 Correct 972 ms 59976 KB Output is correct
41 Correct 816 ms 51988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 22560 KB Output is correct
2 Correct 55 ms 28204 KB Output is correct
3 Correct 74 ms 22112 KB Output is correct
4 Correct 58 ms 26488 KB Output is correct
5 Correct 53 ms 26500 KB Output is correct
6 Correct 84 ms 24072 KB Output is correct
7 Correct 88 ms 23860 KB Output is correct
8 Correct 78 ms 26188 KB Output is correct
9 Correct 64 ms 22432 KB Output is correct
10 Correct 74 ms 24280 KB Output is correct
11 Correct 206 ms 25768 KB Output is correct
12 Correct 243 ms 30164 KB Output is correct
13 Correct 247 ms 30676 KB Output is correct
14 Correct 417 ms 26964 KB Output is correct
15 Correct 387 ms 27104 KB Output is correct
16 Correct 393 ms 29912 KB Output is correct
17 Correct 314 ms 33176 KB Output is correct
18 Correct 353 ms 29260 KB Output is correct
19 Correct 1967 ms 129884 KB Output is correct
20 Correct 2029 ms 164284 KB Output is correct
21 Correct 2140 ms 168588 KB Output is correct
22 Correct 2036 ms 168488 KB Output is correct
23 Correct 1789 ms 178220 KB Output is correct
24 Correct 886 ms 44120 KB Output is correct
25 Correct 969 ms 41420 KB Output is correct
26 Correct 794 ms 38056 KB Output is correct
27 Correct 832 ms 42100 KB Output is correct
28 Correct 713 ms 43960 KB Output is correct
29 Correct 1062 ms 38736 KB Output is correct
30 Correct 982 ms 44288 KB Output is correct
31 Correct 794 ms 38192 KB Output is correct
32 Correct 731 ms 36456 KB Output is correct
33 Correct 688 ms 37672 KB Output is correct
34 Correct 1099 ms 55988 KB Output is correct
35 Correct 1085 ms 62540 KB Output is correct
36 Correct 1089 ms 54616 KB Output is correct
37 Correct 1141 ms 61420 KB Output is correct
38 Correct 1233 ms 57680 KB Output is correct
39 Correct 916 ms 59704 KB Output is correct
40 Correct 920 ms 59588 KB Output is correct
41 Correct 922 ms 59148 KB Output is correct
42 Correct 911 ms 61276 KB Output is correct
43 Correct 838 ms 59280 KB Output is correct
44 Correct 834 ms 60224 KB Output is correct
45 Correct 784 ms 60196 KB Output is correct
46 Correct 937 ms 58752 KB Output is correct
47 Correct 961 ms 64540 KB Output is correct
48 Correct 981 ms 58624 KB Output is correct
49 Correct 1220 ms 60388 KB Output is correct
50 Correct 1128 ms 64180 KB Output is correct
51 Correct 1062 ms 59848 KB Output is correct
52 Correct 1096 ms 64468 KB Output is correct
53 Correct 1138 ms 60340 KB Output is correct
54 Correct 965 ms 63776 KB Output is correct
55 Correct 972 ms 59976 KB Output is correct
56 Correct 816 ms 51988 KB Output is correct
57 Correct 1993 ms 165140 KB Output is correct
58 Correct 1939 ms 166444 KB Output is correct
59 Correct 1972 ms 168996 KB Output is correct
60 Correct 2082 ms 165284 KB Output is correct
61 Correct 2044 ms 165188 KB Output is correct
62 Correct 2016 ms 164016 KB Output is correct
63 Correct 1797 ms 177928 KB Output is correct
64 Correct 1715 ms 178040 KB Output is correct
65 Correct 1800 ms 181956 KB Output is correct
66 Correct 1676 ms 181756 KB Output is correct
67 Correct 1708 ms 185564 KB Output is correct
68 Correct 1755 ms 175236 KB Output is correct
69 Correct 1767 ms 175464 KB Output is correct
70 Correct 1801 ms 175544 KB Output is correct
71 Correct 1814 ms 175656 KB Output is correct
72 Correct 1839 ms 175580 KB Output is correct
73 Correct 1780 ms 176420 KB Output is correct
74 Correct 1933 ms 177576 KB Output is correct
75 Correct 1825 ms 172660 KB Output is correct
76 Correct 1835 ms 172980 KB Output is correct
77 Correct 1712 ms 172644 KB Output is correct
78 Correct 1911 ms 180540 KB Output is correct
79 Correct 1786 ms 168164 KB Output is correct
80 Correct 1528 ms 160400 KB Output is correct