#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
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);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
609 ms |
7276 KB |
Output is correct |
2 |
Correct |
620 ms |
22692 KB |
Output is correct |
3 |
Correct |
637 ms |
22840 KB |
Output is correct |
4 |
Correct |
659 ms |
22796 KB |
Output is correct |
5 |
Correct |
650 ms |
22912 KB |
Output is correct |
6 |
Correct |
725 ms |
22748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
609 ms |
7276 KB |
Output is correct |
2 |
Correct |
620 ms |
22692 KB |
Output is correct |
3 |
Correct |
637 ms |
22840 KB |
Output is correct |
4 |
Correct |
659 ms |
22796 KB |
Output is correct |
5 |
Correct |
650 ms |
22912 KB |
Output is correct |
6 |
Correct |
725 ms |
22748 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
299 ms |
19120 KB |
Output is correct |
14 |
Correct |
308 ms |
19712 KB |
Output is correct |
15 |
Correct |
339 ms |
18544 KB |
Output is correct |
16 |
Correct |
293 ms |
19016 KB |
Output is correct |
17 |
Correct |
486 ms |
24712 KB |
Output is correct |
18 |
Correct |
510 ms |
24636 KB |
Output is correct |
19 |
Correct |
478 ms |
24624 KB |
Output is correct |
20 |
Correct |
494 ms |
24864 KB |
Output is correct |
21 |
Correct |
481 ms |
24804 KB |
Output is correct |
22 |
Correct |
489 ms |
24604 KB |
Output is correct |
23 |
Correct |
494 ms |
24960 KB |
Output is correct |
24 |
Correct |
506 ms |
24612 KB |
Output is correct |
25 |
Correct |
700 ms |
22832 KB |
Output is correct |
26 |
Correct |
679 ms |
22792 KB |
Output is correct |
27 |
Correct |
538 ms |
24892 KB |
Output is correct |
28 |
Correct |
531 ms |
25156 KB |
Output is correct |
29 |
Correct |
516 ms |
23624 KB |
Output is correct |
30 |
Correct |
549 ms |
24216 KB |
Output is correct |
31 |
Correct |
544 ms |
25160 KB |
Output is correct |
32 |
Correct |
529 ms |
21392 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |