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[]{2000000000, -100});
int N = Integer.parseInt(st.nextToken());
int Q = Integer.parseInt(st.nextToken());
map.put(N+1, 2000000001);
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(b[0],a[0]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
22248 KB |
Output is correct |
2 |
Correct |
56 ms |
21872 KB |
Output is correct |
3 |
Execution timed out |
3077 ms |
27448 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
22248 KB |
Output is correct |
2 |
Correct |
56 ms |
21872 KB |
Output is correct |
3 |
Execution timed out |
3077 ms |
27448 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3015 ms |
156796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
763 ms |
39580 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
22248 KB |
Output is correct |
2 |
Correct |
56 ms |
21872 KB |
Output is correct |
3 |
Execution timed out |
3077 ms |
27448 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
22248 KB |
Output is correct |
2 |
Correct |
56 ms |
21872 KB |
Output is correct |
3 |
Execution timed out |
3077 ms |
27448 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |