이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    vector<int> d(n + 1), f(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> d[i];
        if(i == 1) {
            f[i] = d[i];
        }
        else {
            f[i] = (d[i] + f[i - 1] - 1) / f[i - 1] * f[i - 1];
        }
    }
    auto licz = [&](int t, int x) {
        int lo = 1, hi = n, ans = 0;
        while(lo <= hi) {
            int mid = (lo + hi) / 2;
            if(t / f[mid] * f[mid] - mid >= x) {
                lo = mid + 1;
                ans = mid;
            }
            else {
                hi = mid - 1;
            }
        }
        return ans;
    };
    for(int i = 1; i <= q; i++) {
        int t, l, r;
        cin >> t >> l >> r;
        cout << licz(t, l) - licz(t, r + 1) + (l <= t && t <= r) << '\n';
    }
}
// (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), ...
// (-1, 0), (d_1 - 1, d_1), (2 * d_1 - 1, 2 * d_1), ...
// (-2, 0), ()
// k*d_1 - 1 >= -2 + d_2 - 1
// k >= d_2/d_1
// (k * ceil(d_2, d_1) * d_1 - 2)
//...
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |