Submission #627396

#TimeUsernameProblemLanguageResultExecution timeMemory
627396MilosMilutinovicWorst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
684 ms25060 KiB
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i ++) #define rep1(i, n) for(int i = 1; i <= (int)(n); i ++) #define MP make_pair using namespace std; typedef long long LL; typedef pair<int, int> PII; #define int long long int n, q, d[500005]; int calc(int i, int T) { int coeff = T / d[i]; return coeff * d[i] - i - 1; } signed main() { scanf("%lld%lld", &n, &q); rep(i, n) scanf("%lld", &d[i]); rep(i, n) { if(i == 0) continue; d[i] = d[i - 1] * ((d[i] + d[i - 1] - 1) / d[i - 1]); } while(q--) { int T, L, R; scanf("%lld%lld%lld", &T, &L, &R); int l = -1, r = -1; { int low = 0, high = n - 1; while(low <= high) { int mid = low + high >> 1; if(calc(mid, T) <= R) l = mid, high = mid - 1; else low = mid + 1; } } { int low = 0, high = n - 1; while(low <= high) { int mid = low + high >> 1; if(calc(mid, T) >= L) r = mid, low = mid + 1; else high = mid - 1; } } int ans; if(l == -1 || calc(l, T) > R) ans = 0; else ans = r - l + 1; if(L <= T && T <= R) ans ++; printf("%lld\n", ans); } return 0; }

Compilation message (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:33:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     int mid = low + high >> 1;
      |               ~~~~^~~~~~
worst_reporter3.cpp:41:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |     int mid = low + high >> 1;
      |               ~~~~^~~~~~
worst_reporter3.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  scanf("%lld%lld", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:21:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  rep(i, n) scanf("%lld", &d[i]);
      |            ~~~~~^~~~~~~~~~~~~~~
worst_reporter3.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   scanf("%lld%lld%lld", &T, &L, &R);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...