Submission #1337603

#TimeUsernameProblemLanguageResultExecution timeMemory
1337603pomaksikWorst Reporter 3 (JOI18_worst_reporter3)C++20
19 / 100
2094 ms11260 KiB
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int long long
const int max_n = 5e5;
int gain_pol[max_n + 7];
int slownes[max_n + 7];
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n , q;
    cin >> n >> q;
    bool podz1 = true;
    for(int i = 1; i <= n; i++)
    {
        cin >> slownes[i];
        if(slownes[i] > 1)podz1 = false;
    }
    gain_pol[1] = slownes[1];
    for(int i = 2; i <= n; i++)
    {
        gain_pol[i] = (slownes[i] + gain_pol[i - 1] - 1) / gain_pol[i - 1] * gain_pol[i - 1];
    }
    //for(int i = 1; i <= n; ++i)cout << co_ile[i] << ' ' << gain_pol[i] << '\n';
    //return 0;
    while(q--)
    {
        int t , l , r;
        cin >> t >> l >> r;
        if(podz1)
        {
            int right = min(t , r);
            int left = max(t - n , l);
            cout << max(right - left + 1 , (int)0) << '\n';
            continue;
        }
        int ans = 0;
        for(int i = 1; i <= n; i++)
        {
            int place = (t / gain_pol[i]) * gain_pol[i] - i;
            if(l <= place && place <= r)ans++;
        }
        if(l <= t && t <= r)ans++;
        cout << ans <<  '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...