Submission #379274

#TimeUsernameProblemLanguageResultExecution timeMemory
379274nafis_shifatWorst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
700 ms29420 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> using namespace std; const int mxn=1e5+5; const int inf=1e9; int main() { int n,q; cin >> n >> q; ll d[n + 1]; for(int i = 1; i <= n; i++) scanf("%lld",&d[i]); ll jump[n + 2]; jump[0] = 1; for(int i = 1; i <= n; i++) { jump[i] = jump[i - 1] * ((d[i] + jump[i - 1] - 1) / jump[i - 1]); } while(q--) { ll t,l,r; scanf("%lld %lld %lld",&t,&l,&r); ll lo = 0; ll hi = n; ll upb = -1,lwb = -1; while(lo <= hi) { ll mid = lo + hi >> 1; ll x = t / jump[mid]; ll p = -mid + x * jump[mid]; if(p <= r) { upb = mid; hi = mid - 1; } else { lo = mid + 1; } } lo = 0; hi = n; while(lo <= hi) { ll mid = lo + hi >> 1; ll x = t / jump[mid]; ll p = -mid + x * jump[mid]; if(p >= l) { lwb = mid; lo = mid + 1; } else { hi = mid - 1; } } ll ans; if(lwb < upb || lwb == -1 || upb == -1) ans = 0; else ans = lwb - upb + 1; printf("%lld\n",ans ); } }

Compilation message (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:30:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |    ll mid = lo + hi >> 1;
      |             ~~~^~~~
worst_reporter3.cpp:45:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |    ll mid = lo + hi >> 1;
      |             ~~~^~~~
worst_reporter3.cpp:12:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |  for(int i = 1; i <= n; i++) scanf("%lld",&d[i]);
      |                              ~~~~~^~~~~~~~~~~~~~
worst_reporter3.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |   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...