#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=d[0];
v.pb(d[0]);
for(int i=1;i<n;++i){
int nx=(d[i]+cur-1)/cur;
if(cur>1e9/nx)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(rlo<rhi)pf("0\n");
else pf("%d\n",rlo-rhi+1);
}
}
Compilation message
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:65:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | sf("%d%d%d",&t,&l,&r);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
637 ms |
22888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
316 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
312 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
637 ms |
22888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |