Submission #47603

# Submission time Handle Problem Language Result Execution time Memory
47603 2018-05-05T13:39:37 Z qoo2p5 Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
1239 ms 7572 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;

#define rep(i, s, t) for (auto i = (s); i < (t); ++(i))
#define per(i, s, t) for (auto i = (s); i >= (t); --(i))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back

bool mini(auto &x, const auto &y) {
    if (y < x) {
        x = y;
        return 1;
    }
    return 0;
}

bool maxi(auto &x, const auto &y) {
    if (y > x) {
        x = y;
        return 1;
    }
    return 0;
}

void run();

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
    return 0;
}

#define int long long
const int N = (int) 5e5 + 123;

int n, q;
int d[N];

void run() {
    cin >> n >> q;
    rep(i, 1, n + 1) {
        cin >> d[i];
    }
    rep(i, 2, n + 1) {
        d[i] = (d[i] + d[i - 1] - 1) / d[i - 1] * d[i - 1];
    }
    rep(i, 0, q) {
        int t, l, r;
        cin >> t >> l >> r;
        
        int L, R;
        
        {
            int left = 0;
            int right = n + 1;
            while (right - left > 1) {
                int mid = (left + right) / 2;
                int dist = l + mid;
                int k = (dist + d[mid] - 1) / d[mid];
                if (d[mid] * k <= t) {
                    left = mid;
                } else {
                    right = mid;
                }
            }
            L = left;
        }
        
        {
            int left = 0;
            int right = (n + 1);
            while (right - left > 1) {
                int mid = (left + right) / 2;
                int dist = r + mid + 1;
                int k = (dist + d[mid] - 1) / d[mid];
                if (d[mid] * k <= t) {
                    left = mid;
                } else {
                    right = mid;
                }
            }
            R = left;
        }
        
        cout << (L - R + (l <= t && t <= r)) << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1086 ms 7252 KB Output is correct
2 Correct 1101 ms 7392 KB Output is correct
3 Correct 1069 ms 7484 KB Output is correct
4 Correct 1061 ms 7484 KB Output is correct
5 Correct 1063 ms 7484 KB Output is correct
6 Correct 1020 ms 7484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7484 KB Output is correct
2 Correct 3 ms 7484 KB Output is correct
3 Correct 3 ms 7484 KB Output is correct
4 Correct 3 ms 7484 KB Output is correct
5 Correct 3 ms 7484 KB Output is correct
6 Correct 3 ms 7484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1086 ms 7252 KB Output is correct
2 Correct 1101 ms 7392 KB Output is correct
3 Correct 1069 ms 7484 KB Output is correct
4 Correct 1061 ms 7484 KB Output is correct
5 Correct 1063 ms 7484 KB Output is correct
6 Correct 1020 ms 7484 KB Output is correct
7 Correct 4 ms 7484 KB Output is correct
8 Correct 3 ms 7484 KB Output is correct
9 Correct 3 ms 7484 KB Output is correct
10 Correct 3 ms 7484 KB Output is correct
11 Correct 3 ms 7484 KB Output is correct
12 Correct 3 ms 7484 KB Output is correct
13 Correct 783 ms 7484 KB Output is correct
14 Correct 815 ms 7484 KB Output is correct
15 Correct 763 ms 7484 KB Output is correct
16 Correct 797 ms 7484 KB Output is correct
17 Correct 923 ms 7484 KB Output is correct
18 Correct 914 ms 7484 KB Output is correct
19 Correct 908 ms 7484 KB Output is correct
20 Correct 894 ms 7484 KB Output is correct
21 Correct 898 ms 7484 KB Output is correct
22 Correct 924 ms 7484 KB Output is correct
23 Correct 894 ms 7484 KB Output is correct
24 Correct 930 ms 7484 KB Output is correct
25 Correct 1235 ms 7484 KB Output is correct
26 Correct 1239 ms 7572 KB Output is correct
27 Correct 999 ms 7572 KB Output is correct
28 Correct 955 ms 7572 KB Output is correct
29 Correct 952 ms 7572 KB Output is correct
30 Correct 969 ms 7572 KB Output is correct
31 Correct 935 ms 7572 KB Output is correct
32 Correct 887 ms 7572 KB Output is correct
33 Correct 2 ms 7572 KB Output is correct