Codeforces Round 900 (Div. 3) A. How Much Does Daytona Cost?
import java.io.*;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int T = Integer.parseInt(bf.readLine());
while (T-- > 0) {
String[] str = bf.readLine().split(" ");
int n = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
str = bf.readLine().split(" ");
ArrayList<Integer> a = new ArrayList<>();
for (int i = 0; i < n; i++) {
a.add(Integer.parseInt(str[i]));
}
if (a.contains(k)) bw.write("YES\n");
else bw.write("NO\n");
}
bw.close();
}
}
Codeforces Round 900 (Div. 3) B. Aleksa and Stack
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int T = Integer.parseInt(bf.readLine());
while (T-- > 0) {
int n = Integer.parseInt(bf.readLine());
for (int i = 1; i <= n; i++) {
bw.write(2 * i - 1 + " ");
}
bw.write("\n");
}
bw.close();
}
}
Codeforces Round 900 (Div. 3) C. Vasilije in Cacak
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int T = Integer.parseInt(bf.readLine());
while (T-- > 0) {
String[] str = bf.readLine().split(" ");
int n = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
long x = Long.parseLong(str[2]);
long l = (long) (k + 1) * k / 2;
long r = (2L * n - k + 1) * k / 2;
if (l <= x && x <= r) bw.write("YES\n");
else bw.write("NO\n");
}
bw.close();
}
}
Codeforces Round 900 (Div. 3) D. Reverse Madness
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int T = Integer.parseInt(bf.readLine());
while (T-- > 0) {
String[] str = bf.readLine().split(" ");
int n = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
char[] s = bf.readLine().toCharArray();
str = bf.readLine().split(" ");
int[] l = new int[k];
for (int i = 0; i < k; i++) {
l[i] = Integer.parseInt(str[i]);
l[i]--;
}
str = bf.readLine().split(" ");
int[] r = new int[k];
for (int i = 0; i < k; i++) {
r[i] = Integer.parseInt(str[i]);
r[i]--;
}
int q = Integer.parseInt(bf.readLine());
int[] f = new int[n];
str = bf.readLine().split(" ");
for (int i = 0; i < q; i++) {
int x = Integer.parseInt(str[i]);
x--;
f[x] ^= 1;
}
for (int i = 0; i < k; i++) {
int rev = 0;
for (int j = l[i]; j <= l[i] + r[i] - j; j++) {
rev ^= f[j] ^ f[l[i] + r[i] - j];
if (rev != 0) {
char temp = s[j];
s[j] = s[l[i] + r[i] - j];
s[l[i] + r[i] - j] = temp;
}
}
}
for (int i = 0; i < s.length; i++) bw.write(s[i]);
bw.write("\n");
}
bw.close();
}
}
Codeforces Round 900 (Div. 3) E. Iva & Pav
import java.io.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int T = Integer.parseInt(bf.readLine());
while (T-- > 0) {
int n = Integer.parseInt(bf.readLine());
int[] a = new int[n];
String[] str = bf.readLine().split(" ");
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(str[i]);
}
int[][] nxt = new int[n + 1][30];
for (int i = 0; i <= n; i++) Arrays.fill(nxt[i], n);
for (int i = n - 1; i >= 0; i--) {
System.arraycopy(nxt[i + 1], 0, nxt[i], 0, 30);
for (int j = 0; j < 30; j++) {
if ((~a[i] >> j & 1) == 1) {
nxt[i][j] = i;
}
}
}
int q = Integer.parseInt(bf.readLine());
while (q-- > 0) {
str = bf.readLine().split(" ");
int l = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
l--;
int ans = l;
int res = n;
for (int i = 29; i >= 0; i--) {
if ((k >> i & 1) == 1) {
res = Math.min(res, nxt[l][i]);
} else {
ans = Math.max(ans, Math.min(res, nxt[l][i]));
}
}
ans = Math.max(ans, res);
if (ans <= l) {
ans = -1;
}
bw.write(ans + " ");
}
bw.write("\n");
}
bw.close();
}
}
/*
1
5
15 14 17 42 34
1
4 5
*/