Submission #414682

#TimeUsernameProblemLanguageResultExecution timeMemory
414682jamezzzWorst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
725 ms25160 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #include <ext/rope> using namespace __gnu_cxx; typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds; //less_equal for identical elements //#define DEBUG #ifdef DEBUG #define debug(...) printf(__VA_ARGS__); #else #define debug(...) #endif #define sf scanf #define pf printf #define fi first #define se second #define pb emplace_back #define sz(x) (int)x.size() #define mnto(x,y) x=min(x,(__typeof__(x))y) #define mxto(x,y) x=max(x,(__typeof__(x))y) #define INF 1023456789 #define LINF 1023456789123456789 #define all(x) x.begin(), x.end() typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> ii; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<pll> vll; int n,q,d[500005],t,l,r; vector<int> v; int calc(int tm,int x){ //advance v[x] every v[x] seconds //starts at -x if(tm/v[x]>(1e9+x)/v[x])return INF; return tm/v[x]*v[x]-x; } int main(){ sf("%d%d",&n,&q); for(int i=0;i<n;++i)sf("%d",&d[i]); v.pb(1);int cur=1; for(int i=0;i<n;++i){ int nx=(d[i]+cur-1)/cur; if(nx>1e9/cur)break; cur*=nx;v.pb(cur); } n=sz(v); //earlier has further position for(int i=0;i<q;++i){ sf("%d%d%d",&t,&l,&r); int lo=0,hi=n-1,mid,rlo=-1,rhi=-1; while(lo<=hi){ mid=(lo+hi)/2; if(calc(t,mid)>=l){ rlo=mid; lo=mid+1; } else hi=mid-1; } lo=0,hi=n-1; while(lo<=hi){ mid=(lo+hi)/2; if(r>=calc(t,mid)){ rhi=mid; hi=mid-1; } else lo=mid+1; } if(rhi==-1||rlo<rhi)pf("0\n"); else pf("%d\n",rlo-rhi+1); } }

Compilation message (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:52:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  sf("%d%d",&n,&q);
      |    ^
worst_reporter3.cpp:53:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |  for(int i=0;i<n;++i)sf("%d",&d[i]);
      |                        ^
worst_reporter3.cpp:63:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |   sf("%d%d%d",&t,&l,&r);
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...