結果

問題 No.2592 おでぶなおばけさん 2
ユーザー 👑 chro_96chro_96
提出日時 2023-12-20 22:04:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 380 ms / 2,500 ms
コード長 2,370 bytes
コンパイル時間 1,147 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 14,728 KB
最終ジャッジ日時 2023-12-20 22:05:31
合計ジャッジ時間 31,863 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,960 KB
testcase_01 AC 57 ms
12,680 KB
testcase_02 AC 117 ms
12,680 KB
testcase_03 AC 46 ms
10,216 KB
testcase_04 AC 54 ms
10,088 KB
testcase_05 AC 162 ms
14,728 KB
testcase_06 AC 120 ms
12,680 KB
testcase_07 AC 167 ms
12,680 KB
testcase_08 AC 127 ms
12,680 KB
testcase_09 AC 45 ms
10,472 KB
testcase_10 AC 74 ms
10,088 KB
testcase_11 AC 127 ms
12,680 KB
testcase_12 AC 29 ms
10,216 KB
testcase_13 AC 307 ms
12,680 KB
testcase_14 AC 286 ms
12,680 KB
testcase_15 AC 257 ms
12,680 KB
testcase_16 AC 287 ms
12,680 KB
testcase_17 AC 332 ms
12,680 KB
testcase_18 AC 256 ms
12,680 KB
testcase_19 AC 220 ms
12,680 KB
testcase_20 AC 251 ms
12,680 KB
testcase_21 AC 241 ms
12,680 KB
testcase_22 AC 291 ms
12,680 KB
testcase_23 AC 313 ms
12,680 KB
testcase_24 AC 266 ms
12,680 KB
testcase_25 AC 237 ms
10,472 KB
testcase_26 AC 206 ms
10,472 KB
testcase_27 AC 345 ms
14,728 KB
testcase_28 AC 350 ms
14,728 KB
testcase_29 AC 379 ms
14,728 KB
testcase_30 AC 351 ms
14,728 KB
testcase_31 AC 351 ms
14,728 KB
testcase_32 AC 379 ms
14,728 KB
testcase_33 AC 351 ms
14,728 KB
testcase_34 AC 351 ms
14,728 KB
testcase_35 AC 380 ms
14,728 KB
testcase_36 AC 350 ms
14,728 KB
testcase_37 AC 356 ms
14,728 KB
testcase_38 AC 380 ms
14,728 KB
testcase_39 AC 354 ms
14,728 KB
testcase_40 AC 357 ms
14,728 KB
testcase_41 AC 353 ms
14,728 KB
testcase_42 AC 376 ms
14,728 KB
testcase_43 AC 353 ms
14,728 KB
testcase_44 AC 352 ms
14,728 KB
testcase_45 AC 380 ms
14,728 KB
testcase_46 AC 348 ms
14,728 KB
testcase_47 AC 343 ms
14,728 KB
testcase_48 AC 370 ms
14,728 KB
testcase_49 AC 346 ms
14,728 KB
testcase_50 AC 350 ms
14,728 KB
testcase_51 AC 379 ms
14,728 KB
testcase_52 AC 332 ms
14,728 KB
testcase_53 AC 330 ms
14,728 KB
testcase_54 AC 330 ms
14,728 KB
testcase_55 AC 337 ms
14,728 KB
testcase_56 AC 330 ms
14,728 KB
testcase_57 AC 105 ms
14,728 KB
testcase_58 AC 349 ms
14,728 KB
testcase_59 AC 355 ms
14,728 KB
testcase_60 AC 353 ms
14,728 KB
testcase_61 AC 350 ms
14,728 KB
testcase_62 AC 375 ms
14,728 KB
testcase_63 AC 353 ms
14,728 KB
testcase_64 AC 347 ms
14,728 KB
testcase_65 AC 374 ms
14,728 KB
testcase_66 AC 341 ms
14,728 KB
testcase_67 AC 344 ms
14,728 KB
testcase_68 AC 371 ms
14,728 KB
testcase_69 AC 342 ms
14,728 KB
testcase_70 AC 342 ms
14,728 KB
testcase_71 AC 355 ms
14,728 KB
testcase_72 AC 339 ms
14,728 KB
testcase_73 AC 348 ms
14,728 KB
testcase_74 AC 4 ms
9,960 KB
testcase_75 AC 353 ms
14,728 KB
testcase_76 AC 351 ms
14,728 KB
testcase_77 AC 347 ms
14,728 KB
testcase_78 AC 351 ms
14,728 KB
testcase_79 AC 349 ms
14,728 KB
testcase_80 AC 350 ms
14,728 KB
testcase_81 AC 349 ms
14,728 KB
testcase_82 AC 376 ms
14,728 KB
testcase_83 AC 346 ms
14,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define NUM_PRIME 4

long long p[NUM_PRIME] = { 104711LL, 104717LL, 104723LL, 104729LL };
long long pow_k[200001][NUM_PRIME] = {};

void set_segt (long long t[][NUM_PRIME], int idx, long long val, int size) {
  int len = 1;
  idx = idx+size-1;
  for (int i = 0; i < NUM_PRIME; i++) {
    if (val < 0LL) {
      t[idx][i] = (p[i]-(val*(-1LL))%p[i])%p[i];
    } else {
      t[idx][i] = val%p[i];
    }
  }
  while (idx > 0) {
    idx = (idx-1)/2;
    for (int i = 0; i < NUM_PRIME; i++) {
      t[idx][i] = (t[2*idx+1][i]+pow_k[len][i]*t[2*idx+2][i])%p[i];
    }
    len *= 2;
  }
  
  return;
}

int sum_segt_rec (long long t[][NUM_PRIME], int a, int b, int k, int l, int r, long long *ans) {
  long long tmp[NUM_PRIME] = {};
  int len1 = 0;
  int len2 = 0;
  
  if (r <= a || b <= l) {
    for (int i = 0; i < NUM_PRIME; i++) {
      ans[i] = 0LL;
    }
    return 0;
  }
  
  if (a <= l && r <= b) {
    for (int i = 0; i < NUM_PRIME; i++) {
      ans[i] = t[k][i];
    }
    return r-l;
  }
  
  len1 = sum_segt_rec(t, a, b, 2*k+1, l, (l+r)/2, ans);
  len2 = sum_segt_rec(t, a, b, 2*k+2, (l+r)/2, r, tmp);
  
  for (int i = 0; i < NUM_PRIME; i++) {
    ans[i] += tmp[i]*pow_k[len1][i];
    ans[i] %= p[i];
  }
  
  return len1+len2;
}

int sum_segt (long long t[][NUM_PRIME], int a, int b, int size, long long *ans) {
  return sum_segt_rec(t, a, b, 0, 0, size, ans);
}

int main () {
  int n = 0;
  int q = 0;
  long long k = 0LL;
  long long a = 0LL;
  int l = 0;
  int r = 0;
  
  int res = 0;
  
  long long t[262143][NUM_PRIME] = {};
  int size = 1;
  
  res = scanf("%d", &n);
  res = scanf("%d", &q);
  res = scanf("%lld", &k);
  for (int i = 0; i < NUM_PRIME; i++) {
    pow_k[0][i] = 1LL;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < NUM_PRIME; j++) {
      pow_k[i+1][j] = (pow_k[i][j]*(k%p[j]))%p[j];
    }
  }
  while (size <= n) {
    size <<= 1;
  }
  for (int i = 0; i < n; i++) {
    res = scanf("%lld", &a);
    set_segt(t, i, a, size);
  }
  while (q > 0) {
    long long ans[4] = {};
    int is_ng = 1;
    res = scanf("%d", &l);
    res = scanf("%d", &r);
    res = sum_segt(t, l-1, r, size, ans);
    for (int i = 0; i < NUM_PRIME; i++) {
      if (ans[i] > 0LL) {
        is_ng = 0;
      }
    }
    if (is_ng > 0) {
      printf("No\n");
    } else {
      printf("Yes\n");
    }
    q--;
  }
  
  return 0;
}
0