Submission #158172

# Submission time Handle Problem Language Result Execution time Memory
158172 2019-10-15T08:16:58 Z fedoseevtimofey Worst Reporter 3 (JOI18_worst_reporter3) C++14
100 / 100
542 ms 23608 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int K = 37;
int L[K], R[K];
const int N = 5e5 + 7;
int _time[N];
int _move[N];

const ll Inf = 1e9 + 7;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n, q;
    cin >> n >> q;
    vector <int> d(n + 1);
    for (int i = 1; i <= n; ++i) cin >> d[i];   
    d[0] = 1;
    ++n;
    int m;

    {
        vector <pair <int, int>> seg;
        ll mv = 1;
        int lst = 0;
        ll ct = 1;
        for (int i = 1; i < n; ++i) {
            if (mv < d[i]) {
                seg.push_back({lst, i - 1});
                _time[(int)seg.size() - 1] = ct;
                _move[(int)seg.size() - 1] = mv;
                ct *= (d[i] + mv - 1) / mv;
                ct = min(ct, Inf);
                mv *= (d[i] + mv - 1) / mv;
                mv = min(mv, Inf);
                lst = i;
            }
        }
        seg.push_back({lst, n - 1});
        _time[(int)seg.size() - 1] = ct;
        _move[(int)seg.size() - 1] = mv;
        for (int i = 0; i < (int)seg.size(); ++i) L[i] = seg[i].first, R[i] = seg[i].second;
        m = seg.size();
    }

    while (q--) {
        int t, l, r;
        cin >> t >> l >> r;
        int ans = 0;
        for (int i = 0; i < m; ++i) {
            int ps = t / _time[i];
            ll pl = -L[i] + (ll)ps * _move[i];
            ll pr = -R[i] + (ll)ps * _move[i];
            swap(pl, pr);
            pl = max(pl, (ll)l);
            pr = min(pr, (ll)r);
            ans += max(0LL, pr - pl + 1);
        }
        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 294 ms 6032 KB Output is correct
2 Correct 295 ms 6012 KB Output is correct
3 Correct 294 ms 5884 KB Output is correct
4 Correct 295 ms 5836 KB Output is correct
5 Correct 294 ms 5900 KB Output is correct
6 Correct 304 ms 5884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 294 ms 6032 KB Output is correct
2 Correct 295 ms 6012 KB Output is correct
3 Correct 294 ms 5884 KB Output is correct
4 Correct 295 ms 5836 KB Output is correct
5 Correct 294 ms 5900 KB Output is correct
6 Correct 304 ms 5884 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 308 ms 19252 KB Output is correct
14 Correct 316 ms 19932 KB Output is correct
15 Correct 300 ms 18720 KB Output is correct
16 Correct 310 ms 19168 KB Output is correct
17 Correct 394 ms 23372 KB Output is correct
18 Correct 392 ms 23280 KB Output is correct
19 Correct 411 ms 23404 KB Output is correct
20 Correct 404 ms 23288 KB Output is correct
21 Correct 395 ms 23376 KB Output is correct
22 Correct 391 ms 23456 KB Output is correct
23 Correct 401 ms 23228 KB Output is correct
24 Correct 393 ms 23608 KB Output is correct
25 Correct 542 ms 20856 KB Output is correct
26 Correct 302 ms 20728 KB Output is correct
27 Correct 383 ms 22904 KB Output is correct
28 Correct 403 ms 23256 KB Output is correct
29 Correct 399 ms 22904 KB Output is correct
30 Correct 407 ms 22928 KB Output is correct
31 Correct 400 ms 23212 KB Output is correct
32 Correct 304 ms 19412 KB Output is correct
33 Correct 2 ms 376 KB Output is correct