Submission #437958

# Submission time Handle Problem Language Result Execution time Memory
437958 2021-06-27T10:40:23 Z blue Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
861 ms 27252 KB
#include <iostream>
using namespace std;

/*
Let P(i, t) be the position of the person i at the time t

P(0, t) = t
P(1, t) = -1 + P(0, t)

Every contestant i jumps J[i] units to the right every J[i] seconds.
*/
const int maxN = 500000;

int N, Q;
int D[1+maxN];
long long J[1+maxN]; //jump distance/time

long long loc(int i, long long t)
{
    return J[i] * (t/J[i]) - i;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, Q;
    cin >> N >> Q;

    for(int i = 1; i <= N; i++) cin >> D[i];

    J[0] = 1;

    for(int i = 1; i <= N; i++)
    {
        J[i] = min(((D[i] / J[i-1]) + bool(D[i] % J[i-1])) * J[i-1], 1'000'000'001LL);
        // cerr << "JT[" << i << "] = " << JT[i] << ", J[" << i << "] = " << J[i] << '\n';
    }

    for(int j = 1; j <= Q; j++)
    {
        long long T, L, R;
        cin >> T >> L >> R;

        // for(int i = 0; i <= N; i++) cerr << loc(i, T) << ' ';
        // cerr << '\n';

        int rm = -1;
        for(int bit = 20; bit >= 0; bit--)
        {
            int p = rm + (1 << bit);
            if(p > N) continue;
            if(loc(p, T) <= R) continue;
            rm = p;
        }
        rm++;

        if(rm > N || loc(rm, T) < L || R < loc(rm, T))
        {
            cout << 0 << '\n';
            continue;
        }

        int lm = -1;
        for(int bit = 20; bit >= 0; bit--)
        {
            int p = lm + (1 << bit);
            if(p > N) continue;
            if(L <= loc(p, T)) lm = p;
        }

        cout << lm-rm+1 << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 861 ms 11908 KB Output is correct
2 Correct 827 ms 24496 KB Output is correct
3 Correct 806 ms 24560 KB Output is correct
4 Correct 726 ms 24520 KB Output is correct
5 Correct 779 ms 24568 KB Output is correct
6 Correct 841 ms 24532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 861 ms 11908 KB Output is correct
2 Correct 827 ms 24496 KB Output is correct
3 Correct 806 ms 24560 KB Output is correct
4 Correct 726 ms 24520 KB Output is correct
5 Correct 779 ms 24568 KB Output is correct
6 Correct 841 ms 24532 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 489 ms 23000 KB Output is correct
14 Correct 481 ms 23632 KB Output is correct
15 Correct 443 ms 22372 KB Output is correct
16 Correct 482 ms 22888 KB Output is correct
17 Correct 598 ms 27188 KB Output is correct
18 Correct 569 ms 27192 KB Output is correct
19 Correct 571 ms 27252 KB Output is correct
20 Correct 588 ms 27104 KB Output is correct
21 Correct 561 ms 27076 KB Output is correct
22 Correct 572 ms 27120 KB Output is correct
23 Correct 568 ms 27016 KB Output is correct
24 Correct 565 ms 27232 KB Output is correct
25 Correct 784 ms 24628 KB Output is correct
26 Correct 743 ms 24652 KB Output is correct
27 Correct 664 ms 26640 KB Output is correct
28 Correct 612 ms 27012 KB Output is correct
29 Correct 684 ms 26652 KB Output is correct
30 Correct 662 ms 26692 KB Output is correct
31 Correct 639 ms 26880 KB Output is correct
32 Correct 642 ms 23228 KB Output is correct
33 Correct 1 ms 204 KB Output is correct