結果

問題 No.2592 おでぶなおばけさん 2
ユーザー 👑 chro_96chro_96
提出日時 2023-12-20 22:12:48
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 375 ms / 2,500 ms
コード長 2,463 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 32,000 KB
実行使用メモリ 14,732 KB
最終ジャッジ日時 2023-12-20 22:13:21
合計ジャッジ時間 31,427 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,960 KB
testcase_01 AC 57 ms
12,684 KB
testcase_02 AC 116 ms
12,684 KB
testcase_03 AC 45 ms
10,216 KB
testcase_04 AC 55 ms
10,088 KB
testcase_05 AC 160 ms
14,732 KB
testcase_06 AC 122 ms
12,684 KB
testcase_07 AC 167 ms
12,684 KB
testcase_08 AC 126 ms
12,684 KB
testcase_09 AC 44 ms
10,472 KB
testcase_10 AC 73 ms
10,088 KB
testcase_11 AC 126 ms
12,684 KB
testcase_12 AC 29 ms
10,216 KB
testcase_13 AC 286 ms
12,684 KB
testcase_14 AC 286 ms
12,684 KB
testcase_15 AC 253 ms
12,684 KB
testcase_16 AC 288 ms
12,684 KB
testcase_17 AC 315 ms
12,684 KB
testcase_18 AC 251 ms
12,684 KB
testcase_19 AC 219 ms
12,684 KB
testcase_20 AC 249 ms
12,684 KB
testcase_21 AC 205 ms
12,684 KB
testcase_22 AC 289 ms
12,684 KB
testcase_23 AC 313 ms
12,684 KB
testcase_24 AC 275 ms
12,684 KB
testcase_25 AC 202 ms
10,472 KB
testcase_26 AC 204 ms
10,472 KB
testcase_27 AC 341 ms
14,732 KB
testcase_28 AC 349 ms
14,732 KB
testcase_29 AC 348 ms
14,732 KB
testcase_30 AC 345 ms
14,732 KB
testcase_31 AC 348 ms
14,732 KB
testcase_32 AC 346 ms
14,732 KB
testcase_33 AC 347 ms
14,732 KB
testcase_34 AC 349 ms
14,732 KB
testcase_35 AC 360 ms
14,732 KB
testcase_36 AC 351 ms
14,732 KB
testcase_37 AC 352 ms
14,732 KB
testcase_38 AC 357 ms
14,732 KB
testcase_39 AC 354 ms
14,732 KB
testcase_40 AC 352 ms
14,732 KB
testcase_41 AC 350 ms
14,732 KB
testcase_42 AC 354 ms
14,732 KB
testcase_43 AC 347 ms
14,732 KB
testcase_44 AC 353 ms
14,732 KB
testcase_45 AC 357 ms
14,732 KB
testcase_46 AC 354 ms
14,732 KB
testcase_47 AC 347 ms
14,732 KB
testcase_48 AC 344 ms
14,732 KB
testcase_49 AC 343 ms
14,732 KB
testcase_50 AC 350 ms
14,732 KB
testcase_51 AC 375 ms
14,732 KB
testcase_52 AC 329 ms
14,732 KB
testcase_53 AC 332 ms
14,732 KB
testcase_54 AC 330 ms
14,732 KB
testcase_55 AC 327 ms
14,732 KB
testcase_56 AC 331 ms
14,732 KB
testcase_57 AC 104 ms
14,732 KB
testcase_58 AC 351 ms
14,732 KB
testcase_59 AC 349 ms
14,732 KB
testcase_60 AC 352 ms
14,732 KB
testcase_61 AC 355 ms
14,732 KB
testcase_62 AC 355 ms
14,732 KB
testcase_63 AC 349 ms
14,732 KB
testcase_64 AC 360 ms
14,732 KB
testcase_65 AC 365 ms
14,732 KB
testcase_66 AC 342 ms
14,732 KB
testcase_67 AC 347 ms
14,732 KB
testcase_68 AC 347 ms
14,732 KB
testcase_69 AC 345 ms
14,732 KB
testcase_70 AC 346 ms
14,732 KB
testcase_71 AC 347 ms
14,732 KB
testcase_72 AC 347 ms
14,732 KB
testcase_73 AC 347 ms
14,732 KB
testcase_74 AC 4 ms
9,960 KB
testcase_75 AC 354 ms
14,732 KB
testcase_76 AC 351 ms
14,732 KB
testcase_77 AC 352 ms
14,732 KB
testcase_78 AC 351 ms
14,732 KB
testcase_79 AC 352 ms
14,732 KB
testcase_80 AC 349 ms
14,732 KB
testcase_81 AC 348 ms
14,732 KB
testcase_82 AC 348 ms
14,732 KB
testcase_83 AC 352 ms
14,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

#define NUM_PRIME 4

long long p[NUM_PRIME] = {};
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;
  
  srand(1);
  
  res = scanf("%d", &n);
  res = scanf("%d", &q);
  res = scanf("%lld", &k);
  for (int i = 0; i < NUM_PRIME; i++) {
    p[i] = (long long)(rand()%1000000000+1000000000);
  }
  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