結果

問題 No.2592 おでぶなおばけさん 2
ユーザー shojin_proshojin_pro
提出日時 2023-12-20 17:59:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 608 ms / 2,500 ms
コード長 4,899 bytes
コンパイル時間 3,438 ms
コンパイル使用メモリ 80,256 KB
実行使用メモリ 64,312 KB
最終ジャッジ日時 2024-09-27 09:56:06
合計ジャッジ時間 47,232 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
46,380 KB
testcase_01 AC 253 ms
52,024 KB
testcase_02 AC 340 ms
54,140 KB
testcase_03 AC 227 ms
51,628 KB
testcase_04 AC 247 ms
53,012 KB
testcase_05 AC 361 ms
48,584 KB
testcase_06 AC 338 ms
46,884 KB
testcase_07 AC 389 ms
50,220 KB
testcase_08 AC 346 ms
47,180 KB
testcase_09 AC 244 ms
45,164 KB
testcase_10 AC 323 ms
47,456 KB
testcase_11 AC 363 ms
47,220 KB
testcase_12 AC 197 ms
43,876 KB
testcase_13 AC 489 ms
52,164 KB
testcase_14 AC 500 ms
52,728 KB
testcase_15 AC 439 ms
50,364 KB
testcase_16 AC 480 ms
52,064 KB
testcase_17 AC 499 ms
52,132 KB
testcase_18 AC 455 ms
51,804 KB
testcase_19 AC 430 ms
49,568 KB
testcase_20 AC 448 ms
51,304 KB
testcase_21 AC 390 ms
48,520 KB
testcase_22 AC 417 ms
49,164 KB
testcase_23 AC 493 ms
52,928 KB
testcase_24 AC 485 ms
52,160 KB
testcase_25 AC 418 ms
49,488 KB
testcase_26 AC 432 ms
51,096 KB
testcase_27 AC 522 ms
56,384 KB
testcase_28 AC 535 ms
64,312 KB
testcase_29 AC 556 ms
56,644 KB
testcase_30 AC 550 ms
56,556 KB
testcase_31 AC 559 ms
56,560 KB
testcase_32 AC 541 ms
56,564 KB
testcase_33 AC 539 ms
56,520 KB
testcase_34 AC 535 ms
56,592 KB
testcase_35 AC 528 ms
56,504 KB
testcase_36 AC 535 ms
56,460 KB
testcase_37 AC 542 ms
56,560 KB
testcase_38 AC 597 ms
56,628 KB
testcase_39 AC 608 ms
56,668 KB
testcase_40 AC 568 ms
56,592 KB
testcase_41 AC 544 ms
56,592 KB
testcase_42 AC 527 ms
56,524 KB
testcase_43 AC 529 ms
56,564 KB
testcase_44 AC 524 ms
56,604 KB
testcase_45 AC 523 ms
56,636 KB
testcase_46 AC 557 ms
56,520 KB
testcase_47 AC 506 ms
53,652 KB
testcase_48 AC 515 ms
53,356 KB
testcase_49 AC 514 ms
53,644 KB
testcase_50 AC 493 ms
53,804 KB
testcase_51 AC 491 ms
53,728 KB
testcase_52 AC 568 ms
56,600 KB
testcase_53 AC 538 ms
56,576 KB
testcase_54 AC 538 ms
56,532 KB
testcase_55 AC 522 ms
56,536 KB
testcase_56 AC 553 ms
56,696 KB
testcase_57 AC 237 ms
47,188 KB
testcase_58 AC 548 ms
56,484 KB
testcase_59 AC 565 ms
56,824 KB
testcase_60 AC 539 ms
56,196 KB
testcase_61 AC 534 ms
56,560 KB
testcase_62 AC 528 ms
56,600 KB
testcase_63 AC 544 ms
56,216 KB
testcase_64 AC 526 ms
56,332 KB
testcase_65 AC 538 ms
53,860 KB
testcase_66 AC 566 ms
53,896 KB
testcase_67 AC 536 ms
53,860 KB
testcase_68 AC 551 ms
53,804 KB
testcase_69 AC 523 ms
53,788 KB
testcase_70 AC 548 ms
53,460 KB
testcase_71 AC 516 ms
53,752 KB
testcase_72 AC 524 ms
53,832 KB
testcase_73 AC 485 ms
53,760 KB
testcase_74 AC 46 ms
37,344 KB
testcase_75 AC 532 ms
56,584 KB
testcase_76 AC 566 ms
56,472 KB
testcase_77 AC 520 ms
56,608 KB
testcase_78 AC 544 ms
56,328 KB
testcase_79 AC 544 ms
56,364 KB
testcase_80 AC 533 ms
56,388 KB
testcase_81 AC 562 ms
56,540 KB
testcase_82 AC 551 ms
56,420 KB
testcase_83 AC 559 ms
56,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static FastScanner sc = new FastScanner(System.in);
    static PrintWriter pw = new PrintWriter(System.out);
    static StringBuilder sb = new StringBuilder();
    static long mod = (long)1e9+7;
    static long mod2 = (long)1e9+9;
    static long mod3 = 998244353;
    static long mod4 = 998244853;

    public static void main(String[] args) throws Exception {
        solve();
        pw.flush();
    }
    
    public static void solve(){
        int N = sc.nextInt();
        int Q = sc.nextInt();
        long K = sc.nextLong();
        long[] A = sc.nextLongArray(N);
        ArrayList<int[]> Query = new ArrayList<>();
        for(int i = 0; i < Q; i++){
            Query.add(new int[]{sc.nextInt(),sc.nextInt()});
        }
        boolean[] check1 = check(A,Query,K,mod,N);
        boolean[] check2 = check(A,Query,K,mod2,N);
        boolean[] check3 = check(A,Query,K,mod3,N);
        boolean[] check4 = check(A,Query,K,mod4,N);
        for(int i = 0; i < Q; i++){
            if(check1[i] || check2[i] || check3[i] || check4[i]){
                pw.println("Yes");
            }else{
                pw.println("No");
            }
        }
    }
    
    static boolean[] check(long[] A, ArrayList<int[]> Query, long K, long mod, int N){
        int Q = Query.size();
        boolean[] ret = new boolean[Q];
        K %= mod;
        long[] sum = new long[N+1];
        long now = 1;
        for(int i = 0; i < N; i++){
            long v = A[i];
            if(v < 0){
                long p = (Math.abs(v)+mod-1)/mod;
                v += p*mod;
                v %= mod;
            }else{
                v %= mod;
            }
            sum[i+1] += (sum[i]+(v*now))%mod;
            now *= K;
            now %= mod;
        }
        for(int i = 0; i < Q; i++){
            int l = Query.get(i)[0]-1;
            int r = Query.get(i)[1];
            if(sum[r] - sum[l] != 0){
                ret[i] = true;
            }else{
                ret[i] = false;
            }
        }
        return ret;
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }

        public static void save_sort(long[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static long[] shuffle(long[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                long randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }

    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public FastScanner(FileReader in) {
        reader = new BufferedReader(in);
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}
0