Submission #1005718

#TimeUsernameProblemLanguageResultExecution timeMemory
1005718Username_taken12Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
Compilation error
0 ms0 KiB
import java.io.*; import java.util.*; public class BookSwap { 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][3]; 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--){ int[] it = new int[]{-1,-1}; while(a[i]>stack.peek()[0]){ it=stack.pop(); while(true){ int next=map.ceilingKey(it[1]); if(map.get(next)<=it[0]+a[i]) map.remove(it[1]); else break; } map.put(i,it[0]+a[i]); } 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][i])); 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]); } }

Compilation message (stderr)

sortbooks.cpp:2:1: error: 'import' does not name a type
    2 | import java.io.*;
      | ^~~~~~
sortbooks.cpp:3:1: error: 'import' does not name a type
    3 | import java.util.*;
      | ^~~~~~
sortbooks.cpp:5:1: error: expected unqualified-id before 'public'
    5 | public class BookSwap {
      | ^~~~~~
sortbooks.cpp:60:23: error: expected initializer before 'Comparator'
   60 | class Comp implements Comparator<int[]>{
      |                       ^~~~~~~~~~