This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1;
int n, q;
long long d[N], t[N], l[N];
int f(int x, int ti)
{
int le = 0, ri = n;
int res = n + 1;
while (le <= ri)
{
int mid = (le + ri)/2;
int k = floor((double)ti/(double)t[mid]);
long long y = -mid + k*l[mid];
if (y <= x)
{
res = mid;
ri = mid - 1;
}
else le = mid + 1;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; ++i) cin >> d[i];
t[0] = 1;
l[0] = 1;
t[1] = d[1];
l[1] = d[1];
for (int i = 2; i <= n; ++i)
if (d[i] < d[i - 1])
t[i] = t[i - 1], l[i] = l[i - 1];
else
{
int k = trunc(ceil((double)d[i]/(double)l[i - 1]));
// cout << ceil(5/2) << endl;
//cout << k <<' ' << t[i - 1] <<' ' << l[i - 1] << endl;
t[i] = k*t[i - 1];
l[i] = k*l[i - 1];
}
for (int i = 1; i <= n; ++i) cout << t[i] <<' ' << l[i] << endl;
int ti, le, ri;
for (int i = 1; i <= q; ++i)
{
cin >> ti >> le >> ri;
//cout << f(le - 1, ti) <<' ' << f(ri, ti) << '\n';
cout << f(le - 1, ti) - f(ri, ti) << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |