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 <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <iomanip>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define endl '\n'
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 5e5+10;
int D[maxn];
int T[maxn];
inline int get_at(int i, int t)
{
return -i + ( (t/T[i]) * T[i] );
}
int n;
inline int bisect(int x, int t)
{
int down = -1;
int up = n+1;
while(up-down > 1)
{
int mid = (up+down) / 2;
if(get_at(mid, t) <= x)
up = mid;
else
down = mid;
}
return up;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int q; cin >> n >> q;
for(int i = 1; i <= n; i++)
cin >> D[i];
T[0] = 1;
for(int i = 1; i <= n; i++)
{
T[i] = ((D[i] + T[i-1] - 1) / T[i-1]) * T[i-1];
}
while(q--)
{
int t, l, r; cin >> t >> l >> r;
int a = bisect(r, t);
int b = bisect(l-1, t);
cout << b-a << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |