Submission #1337595

#TimeUsernameProblemLanguageResultExecution timeMemory
1337595pomaksikWorst Reporter 3 (JOI18_worst_reporter3)C++20
0 / 100
2092 ms12176 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 co_ile[max_n + 7];
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;
    for(int i = 1; i <= n; i++)
    {
        cin >> slownes[i];
    }
    co_ile[1] = slownes[1];
    gain_pol[1] = slownes[1];
    for(int i = 2; i <= n; i++)
    {
        int t = 1 , pocz = 1 , kon = 1000000000;
        while(pocz <= kon)
        {
            int mid = (pocz + kon) / 2;
            if(mid * gain_pol[i - 1] > slownes[i])
            {
                t = mid;
                kon = mid - 1;
            }
            else pocz = mid + 1;
        }
        co_ile[i] = t * co_ile[i - 1];
        gain_pol[i] = t * gain_pol[i - 1];
        if(co_ile[i] > 1000000000)break;
    }
    //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;
        int ans = 0;
        for(int i = 1; i <= n; i++)
        {
            if(co_ile[i] > 1000000000)break;
            int place = (t / co_ile[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...