#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;
#define int long long
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
return tm/v[x]*v[x]-x;
}
main(){
sf("%lld%lld",&n,&q);
for(int i=0;i<n;++i)sf("%lld",&d[i]);
v.pb(1);
int cur=d[0];
v.pb(d[0]);
for(int i=1;i<n;++i){
int nx=(d[i]+cur-1)/cur;
if(cur*nx>1e9)break;
cur*=nx;v.pb(cur);
}
n=sz(v);
//earlier has further position
for(int i=0;i<q;++i){
sf("%lld%lld%lld",&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(rlo<rhi)pf("0\n");
else pf("%lld\n",rlo-rhi+1);
}
}
Compilation message
worst_reporter3.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
52 | main(){
| ^~~~
worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:53:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | sf("%lld%lld",&n,&q);
| ^
worst_reporter3.cpp:54:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | for(int i=0;i<n;++i)sf("%lld",&d[i]);
| ^
worst_reporter3.cpp:66:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | sf("%lld%lld%lld",&t,&l,&r);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
654 ms |
11416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
654 ms |
11416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |