Submission #642917

#TimeUsernameProblemLanguageResultExecution timeMemory
642917valerikkWorst Reporter 3 (JOI18_worst_reporter3)C++17
100 / 100
663 ms23192 KiB
#include <cstdio> #define MAXN 500005 #define MAXT 1000000001 #define MAXK 65 int N, Q; int D[MAXN]; int W[MAXN], C[MAXN], S[MAXN]; int Z[MAXK], K; int count(int T, int L) { if (T < L) return 0; for (int i = 0, t = T; i < K; ++i) { S[i] = t % C[Z[i]] * W[Z[i]]; t /= C[Z[i]]; } int low = 0, high = N + 1; while (high - low > 1) { int mid = (low + high) / 2; int X = T - mid; for (int i = 0; i < K && Z[i] <= mid; ++i) { X -= S[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 (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d%d", &N, &Q);
      |   ~~~~~^~~~~~~~~~~~~~~~
worst_reporter3.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d", &D[i]);
      |     ~~~~~^~~~~~~~~~~~~
worst_reporter3.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     scanf("%d%d%d", &T, &L, &R);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...