#include<bits/stdc++.h>
#define mp make_pair
#define fs first
#define sc second
#define pb push_back
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mod 998244353
#define INF 1e18
using namespace std;
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/
int n,q;
long long a[500005];
long long mov[500005];
long long t,l,r;
bool cek(long long dist,int idx){
long long nyak = t / mov[idx];
nyak = nyak * mov[idx];
nyak = nyak - idx;
if(nyak <= dist){
return true;
}
return false;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> q;
mov[0] = 1;
for(int i = 1; i <= n; i++){
cin >> a[i];
long long nyak = a[i] / mov[i - 1];
if(a[i] % mov[i - 1] != 0){
nyak++;
}
mov[i] = mov[i - 1] * nyak;
// cout << i << " " << mov[i] << " here\n";
}
for(int i = 1; i <= q; i++){
cin >> t >> l >> r;
int kiri,kanan,ansL,ansR;
l--;
kiri = 1, kanan = n;
ansL = n + 1;
while(kiri <= kanan){
int mid = (kiri + kanan) / 2;
if(cek(l,mid)){
ansL = mid;
kanan = mid - 1;
}else{
kiri = mid + 1;
}
}
kiri = 1; kanan = n;
ansR = n + 1;
while(kiri <= kanan){
int mid = (kiri + kanan) / 2;
if(cek(r,mid)){
ansR = mid;
kanan = mid - 1;
}else{
kiri = mid + 1;
}
}
int tamb = 0;
if(t > l && t <= r) tamb = 1;
cout << ansL - ansR + tamb << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1107 ms |
19580 KB |
Output is correct |
2 |
Correct |
1230 ms |
27324 KB |
Output is correct |
3 |
Correct |
1174 ms |
27324 KB |
Output is correct |
4 |
Correct |
1415 ms |
27424 KB |
Output is correct |
5 |
Correct |
1222 ms |
27424 KB |
Output is correct |
6 |
Correct |
1055 ms |
27424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27424 KB |
Output is correct |
2 |
Correct |
5 ms |
27424 KB |
Output is correct |
3 |
Correct |
3 ms |
27424 KB |
Output is correct |
4 |
Correct |
4 ms |
27424 KB |
Output is correct |
5 |
Correct |
3 ms |
27424 KB |
Output is correct |
6 |
Correct |
3 ms |
27424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1107 ms |
19580 KB |
Output is correct |
2 |
Correct |
1230 ms |
27324 KB |
Output is correct |
3 |
Correct |
1174 ms |
27324 KB |
Output is correct |
4 |
Correct |
1415 ms |
27424 KB |
Output is correct |
5 |
Correct |
1222 ms |
27424 KB |
Output is correct |
6 |
Correct |
1055 ms |
27424 KB |
Output is correct |
7 |
Correct |
4 ms |
27424 KB |
Output is correct |
8 |
Correct |
5 ms |
27424 KB |
Output is correct |
9 |
Correct |
3 ms |
27424 KB |
Output is correct |
10 |
Correct |
4 ms |
27424 KB |
Output is correct |
11 |
Correct |
3 ms |
27424 KB |
Output is correct |
12 |
Correct |
3 ms |
27424 KB |
Output is correct |
13 |
Correct |
584 ms |
27424 KB |
Output is correct |
14 |
Correct |
667 ms |
27424 KB |
Output is correct |
15 |
Correct |
671 ms |
27424 KB |
Output is correct |
16 |
Correct |
606 ms |
27424 KB |
Output is correct |
17 |
Correct |
805 ms |
27424 KB |
Output is correct |
18 |
Correct |
758 ms |
27424 KB |
Output is correct |
19 |
Correct |
786 ms |
27424 KB |
Output is correct |
20 |
Correct |
838 ms |
27424 KB |
Output is correct |
21 |
Correct |
784 ms |
27424 KB |
Output is correct |
22 |
Correct |
729 ms |
27424 KB |
Output is correct |
23 |
Correct |
945 ms |
45508 KB |
Output is correct |
24 |
Correct |
844 ms |
64216 KB |
Output is correct |
25 |
Correct |
1161 ms |
80268 KB |
Output is correct |
26 |
Correct |
1033 ms |
95624 KB |
Output is correct |
27 |
Correct |
1028 ms |
113244 KB |
Output is correct |
28 |
Correct |
877 ms |
131148 KB |
Output is correct |
29 |
Correct |
926 ms |
147856 KB |
Output is correct |
30 |
Correct |
1043 ms |
165360 KB |
Output is correct |
31 |
Correct |
944 ms |
182480 KB |
Output is correct |
32 |
Correct |
859 ms |
196168 KB |
Output is correct |
33 |
Correct |
3 ms |
196168 KB |
Output is correct |