Submission #1249369

#TimeUsernameProblemLanguageResultExecution timeMemory
1249369chikien2009Worst Reporter 3 (JOI18_worst_reporter3)C++20
100 / 100
298 ms7520 KiB
#include <bits/stdc++.h>

using namespace std;

long long n, q, d[1000001], a, b, c;

inline long long Pos(long long lim)
{
    long long l = 0, r = n, m, x = n + 1, p;
    while (l <= r)
    {
        m = (l + r) >> 1;
        p = (a / d[m]) * d[m] - m;
        if (p <= lim)
        {
            x = m;
            r = m - 1;
        }
        else
        {
            l = m + 1;
        }
    }
    return x;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  
    cin >> n >> q;
    d[0] = 1;
    for (long long i = 1; i <= n; ++i)
    {
        cin >> d[i];
        d[i] = max(d[i], d[i - 1]);
        d[i] = ((d[i] + d[i - 1] - 1) / d[i - 1]) * d[i - 1];
    }
    while (q--)
    {
        cin >> a >> b >> c;
        cout << Pos(b - 1) - Pos(c) << "\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...