#include <iostream>
#include <fstream>
using namespace std;
const int nmax=500005;
long long d[nmax],fv[nmax],val[nmax];
int n,q,p,i,l,r,t;
string s;
int num,ch;
int getnum()
{
num=0;
while(s[ch]>='0'&&s[ch]<='9')
num=num*10+s[ch]-'0',ch++;
ch++;
return num;
}
int calc(int x,int t)
{
int ret=0;
int vv;
if(t<x)
return 0;
for(int p=18;p>=0;p--)
{
vv=ret+(1<<p);
if(vv<=n&&(t/fv[vv])*(val[vv])-vv>=x)
ret+=(1<<p);
}
return ret+1;
}
int main()
{
//freopen("data.in","r",stdin);
ios_base::sync_with_stdio(false);
cin>>n>>q;getline(cin,s);
for(i=1;i<=n;i++)
{
getline(cin,s);
ch=0;d[i]=getnum();
if(i==1) fv[i]=d[i],val[i]=d[i];
else
{
if(val[i-1]<d[i])
{
fv[i]=(1LL*fv[i-1]*((d[i]+val[i-1]-1)/val[i-1]));
val[i]=(d[i]+val[i-1]-(d[i]%val[i-1]));
if(!(d[i]%val[i-1]))
val[i]=d[i];
}
else
{
fv[i]=fv[i-1];
val[i]=val[i-1];
}
fv[i]=min(fv[i],1LL*(1000*1000*1000+1));
}
}
for(i=1;i<=q;i++)
{
getline(cin,s);ch=0;
t=getnum();l=getnum();r=getnum();
cout<<calc(l,t)-calc(r+1,t)<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1968 ms |
16480 KB |
Output is correct |
2 |
Correct |
1960 ms |
31684 KB |
Output is correct |
3 |
Correct |
1833 ms |
36340 KB |
Output is correct |
4 |
Correct |
1868 ms |
36340 KB |
Output is correct |
5 |
Correct |
1829 ms |
36360 KB |
Output is correct |
6 |
Correct |
1806 ms |
36360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
36360 KB |
Output is correct |
2 |
Correct |
4 ms |
36360 KB |
Output is correct |
3 |
Correct |
4 ms |
36360 KB |
Output is correct |
4 |
Correct |
4 ms |
36360 KB |
Output is correct |
5 |
Correct |
4 ms |
36360 KB |
Output is correct |
6 |
Correct |
4 ms |
36360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1968 ms |
16480 KB |
Output is correct |
2 |
Correct |
1960 ms |
31684 KB |
Output is correct |
3 |
Correct |
1833 ms |
36340 KB |
Output is correct |
4 |
Correct |
1868 ms |
36340 KB |
Output is correct |
5 |
Correct |
1829 ms |
36360 KB |
Output is correct |
6 |
Correct |
1806 ms |
36360 KB |
Output is correct |
7 |
Correct |
4 ms |
36360 KB |
Output is correct |
8 |
Correct |
4 ms |
36360 KB |
Output is correct |
9 |
Correct |
4 ms |
36360 KB |
Output is correct |
10 |
Correct |
4 ms |
36360 KB |
Output is correct |
11 |
Correct |
4 ms |
36360 KB |
Output is correct |
12 |
Correct |
4 ms |
36360 KB |
Output is correct |
13 |
Correct |
1243 ms |
36360 KB |
Output is correct |
14 |
Correct |
1309 ms |
36360 KB |
Output is correct |
15 |
Correct |
1197 ms |
36360 KB |
Output is correct |
16 |
Correct |
1234 ms |
36360 KB |
Output is correct |
17 |
Correct |
1490 ms |
36360 KB |
Output is correct |
18 |
Correct |
1458 ms |
37052 KB |
Output is correct |
19 |
Correct |
1491 ms |
37052 KB |
Output is correct |
20 |
Correct |
1441 ms |
37052 KB |
Output is correct |
21 |
Correct |
1475 ms |
37052 KB |
Output is correct |
22 |
Correct |
1513 ms |
37064 KB |
Output is correct |
23 |
Correct |
1446 ms |
37064 KB |
Output is correct |
24 |
Correct |
1454 ms |
37064 KB |
Output is correct |
25 |
Correct |
1905 ms |
37596 KB |
Output is correct |
26 |
Correct |
1886 ms |
37624 KB |
Output is correct |
27 |
Correct |
1606 ms |
37624 KB |
Output is correct |
28 |
Correct |
1582 ms |
37624 KB |
Output is correct |
29 |
Correct |
1550 ms |
55036 KB |
Output is correct |
30 |
Correct |
1635 ms |
72652 KB |
Output is correct |
31 |
Correct |
1555 ms |
82172 KB |
Output is correct |
32 |
Correct |
1580 ms |
82172 KB |
Output is correct |
33 |
Correct |
2 ms |
82172 KB |
Output is correct |