Codeforces Round 900 (Div. 3)

Codeforces Round 900 (Div. 3)

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
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wa_Automata

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值