답안 #642916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
642916 2022-09-20T19:02:18 Z valerikk Worst Reporter 3 (JOI18_worst_reporter3) C++17
19 / 100
2000 ms 27332 KB
#include <cstdio>

#define MAXN 500005
#define MAXT 1000000001
#define MAXK 65

int N, Q;
int D[MAXN];
int W[MAXN], C[MAXN];
int Z[MAXK], K;

int count(int T, int L) {
  if (T < L)
    return 0;

  int low = 0, high = N + 1;
  while (high - low > 1) {
    int mid = (low + high) / 2;

    int X = T - mid;
    for (int i = 0, t = T; i < K && Z[i] <= mid; ++i) {
      int r = t % C[Z[i]];
      t /= C[Z[i]];
      X -= r * W[Z[i]];
    }

    if (X >= L) 
      low = mid;
    else
      high = mid;
  }
  
  return low + 1;
}

int main() {
  scanf("%d%d", &N, &Q);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &D[i]);
  }

  W[1] = 1;
  C[1] = D[1];
  for (int i = 2; i <= N; ++i) {
    if (MAXT / C[i - 1] < W[i - 1])
      W[i] = MAXT;
    else
      W[i] = C[i - 1] * W[i - 1];
    
    C[i] = (D[i] + W[i] - 1) / W[i];
    if (C[i] > MAXT)
      C[i] = MAXT;
  }

  for (int i = 1; i <= N; ++i) {
    if (C[i] != 1) 
      Z[K++] = i;
  }

  while (Q--) {
    int T, L, R;
    scanf("%d%d%d", &T, &L, &R);
    printf("%d\n", count(T, L) - count(T, R + 1));
  }
}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d%d", &N, &Q);
      |   ~~~~~^~~~~~~~~~~~~~~~
worst_reporter3.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d", &D[i]);
      |     ~~~~~^~~~~~~~~~~~~
worst_reporter3.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d%d%d", &T, &L, &R);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 9156 KB Output is correct
2 Correct 327 ms 9156 KB Output is correct
3 Correct 302 ms 9144 KB Output is correct
4 Correct 311 ms 9088 KB Output is correct
5 Correct 297 ms 9032 KB Output is correct
6 Correct 287 ms 9080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 9156 KB Output is correct
2 Correct 327 ms 9156 KB Output is correct
3 Correct 302 ms 9144 KB Output is correct
4 Correct 311 ms 9088 KB Output is correct
5 Correct 297 ms 9032 KB Output is correct
6 Correct 287 ms 9080 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 450 ms 18124 KB Output is correct
14 Correct 469 ms 23828 KB Output is correct
15 Correct 364 ms 22328 KB Output is correct
16 Correct 466 ms 22876 KB Output is correct
17 Correct 1846 ms 27104 KB Output is correct
18 Correct 1694 ms 27116 KB Output is correct
19 Correct 1924 ms 27200 KB Output is correct
20 Correct 1776 ms 27076 KB Output is correct
21 Correct 1683 ms 27200 KB Output is correct
22 Correct 1702 ms 27232 KB Output is correct
23 Correct 1661 ms 27156 KB Output is correct
24 Correct 1671 ms 27332 KB Output is correct
25 Correct 385 ms 24624 KB Output is correct
26 Correct 360 ms 24528 KB Output is correct
27 Correct 1742 ms 26676 KB Output is correct
28 Correct 1977 ms 27120 KB Output is correct
29 Correct 1991 ms 26632 KB Output is correct
30 Correct 1917 ms 26676 KB Output is correct
31 Execution timed out 2050 ms 26888 KB Time limit exceeded
32 Halted 0 ms 0 KB -