Submission #206701

#TimeUsernameProblemLanguageResultExecution timeMemory
206701nvmdavaWorst Reporter 3 (JOI18_worst_reporter3)C++17
7 / 100
303 ms9852 KiB
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define ff first
#define ss second
#define N 500005
#define MOD 1000000007
#define INF 0x3f3f3f3f

int a[N];

vector<pair<int, pair<int, int> > > v;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin>>n>>q;
    
    for(int i = 1; i <= n; ++i)
        cin>>a[i];
    for(int i = 2; i <= n; ++i)
        a[i] = ((a[i] - 1) / a[i - 1] + 1) * a[i - 1];

    for(int i = 1; i <= n; ++i){
        if(a[i] != a[i - 1]){
            v.push_back({a[i], {-i, -i}});
        } else {
            v.back().ss.ff = -i;
        }
    }

    while(q--){
        int t, l, r;
        cin>>t>>l>>r;
        int m = t;
        int res = 0;
        if(l <= m && m <= r)
            ++res;
        for(auto& x : v){
            int L = x.ss.ff, R = x.ss.ss;
            int val = (m - R - 1) / x.ff * x.ff;
            L += val;
            R += val;
            res += max(0, min(R, r) - max(l, L) + 1);
            m = L;
            if(m >= l) break;
        }
        cout<<res<<'\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...