Submission #361820

#TimeUsernameProblemLanguageResultExecution timeMemory
361820dolphingarlicWorst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
380 ms25512 KiB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

struct Group {
    int l, r;
    ll period;
};

ll d[500001];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    vector<Group> groups = {{0, 0, 1}};
    for (int i = 1; i <= n; i++) {
        cin >> d[i];
        ll p = groups.back().period;
        if (d[i] <= p) groups.back().l--;
        else groups.push_back({-i, -i, (d[i] + p - 1) / p * p});
    }
    while (q--) {
        ll l, r, t;
        cin >> t >> l >> r;
        int ans = 0;
        for (Group i : groups) {
            ll mv = t / i.period * i.period;
            ans += max(0ll, min(r, i.r + mv) - max(l, i.l + mv) + 1);
        }
        cout << ans << '\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...