-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl1t1.java
More file actions
46 lines (45 loc) · 1.35 KB
/
l1t1.java
File metadata and controls
46 lines (45 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Arrays;
import java.util.Scanner;
public class l1t1 {
public static void main(String[] args) {
int n, q,t;
Scanner input = new Scanner(System.in);
n = input.nextInt();
q = input.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = input.nextInt();
// for(int i=0;i<n;i++)
// for(int j=n-1;j>i;j--)
// if(a[j]<a[j-1]){
// t=a[j];
// a[j]=a[j-1];
// a[j-1]=t;1
// }
int x, y, l, r, m, b,c;
for (int k = 1; k <= q; k++) {
x = input.nextInt();
y = input.nextInt();
l = 0;
r = n - 1;
while (l <= r) {
m = (l + r) / 2;
if (x < a[m]) r = m - 1;
else l = m + 1;
}
//System.out.println(r);
b = r + 1;
l = 0;
r = n - 1;
while (l <= r) {
m = (l + r) / 2;
if (y <= a[m]) r = m - 1;
else l = m + 1;
}
c=r;
//while (a[b] < y && b < n) b++;
// System.out.printf("%d %d %d %d\n", n, l, b,c);
if(c-b+1>0)System.out.printf("YES %d\n", c-b+1);
else System.out.printf("NO\n");
}
}
}