이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1 << 19, INF = 1e18 + 42;
int n, q, period[N];
int dicho(int t, int obj) {
    int ans = -1;
    for(int i = 18; i >= 0; i--)
        if(period[ans + (1 << i)] * (t / period[ans + (1 << i)]) - ans - (1 << i) >= obj)
            ans += (1 << i);
    return ans;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> q;
    
    n++;
    period[0] = 1;
    for(int i = 1; i < n; i++) {
        cin >> period[i];
        period[i] = ((period[i] + period[i-1] - 1) / period[i-1]) * period[i-1];
    }
    for(int i = n; i < N; i++)
        period[i] = INF;
    for(int i = 0; i < q; i++) {
        int t, l, r; cin >> t >> l >> r;
        cout << dicho(t, l) - dicho(t, r+1) << '\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... |