이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
 
#define int long long
 
using namespace std;
 
struct period {
    int per, l, r;
};
 
const int MAX_N = 5e5 + 1;
const int MAX_T = 2e9;
int d[MAX_N], per[MAX_N];
 
int higher( int x, int n ) {
    return ((int)ceil( (double)n / x )) * x;
}
 
int lower( int x, int n ) {
    return ((int)floor( (double)n / x )) * x;
}
 
vector<period> periods;
 
signed main() {
    int n, q;
 
    cin >> n >> q;
    d[0] = 1;
    for ( int i = 1; i <= n; i++ )
        cin >> d[i];
 
    per[0] = 1;
    for ( int i = 1; i <= n; i++ )
        per[i] = higher( per[i - 1], d[i] );
 
    int i = 0;
    while ( i <= n ) {
        int j = i;
        while ( j + 1 <= n && per[i] == per[j + 1] )
            j++;
        periods.push_back( { per[i], i, j } );
        i = j + 1;
    }
 
    while ( q-- ) {
        int t, l, r, ans = 0;
        cin >> t >> l >> r;
        for ( period p: periods ) {
            int lp = lower( p.per, t ) - p.r, rp = lower( p.per, t ) - p.l;
            ans += max( 0LL, min( rp, r ) - max( lp, l ) + 1 );
        }
        cout << ans << "\n";
    }
 
    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... |