Submission #45473

# Submission time Handle Problem Language Result Execution time Memory
45473 2018-04-14T10:18:17 Z choikiwon Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
825 ms 262144 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MN = 500010;

int N, Q;
int D[MN];
vector<pair<pii, int> > seg;

int main() {
    scanf("%d %d", &N, &Q);

    for(int i = 0; i < N; i++) {
        scanf("%d", &D[i]);
    }

    int d = D[0];
    int s = 0;
    int c = 1;
    int pos = 0;
    while(1) {
        while(pos < N && D[pos] <= d) pos++;
        seg.push_back({ {s, pos - 1}, c });
        if(pos == N) break;
        s = pos;
        int k = 1;
        while(D[pos] > k * d) k++;
        d = k * d;
        c = k * c;
    }

    for(int i = 0; i < Q; i++) {
        int t, l, r; scanf("%d %d %d", &t, &l, &r);

        int ans = l <= t && t <= r;
        t /= D[0];

        for(int j = 0; j < seg.size(); j++) {
            pii s = seg[j].first;
            int m = seg[j].second;

            int x = (t / m) * m;

            //cout << m << ' ' << x << ' ' << s.first << ' ' << s.second << endl;

            if(x * D[0] - s.first - 1 < l || r < x * D[0] - s.second - 1) continue;
            int tl = max(x * D[0] - s.second - 1, l);
            int tr = min(x * D[0] - s.first - 1, r);
            ans += tr - tl + 1;
        }

        printf("%d\n", ans);
    }
}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:41:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < seg.size(); j++) {
                        ~~^~~~~~~~~~~~
worst_reporter3.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &Q);
     ~~~~~^~~~~~~~~~~~~~~~~
worst_reporter3.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &D[i]);
         ~~~~~^~~~~~~~~~~~~
worst_reporter3.cpp:36:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int t, l, r; scanf("%d %d %d", &t, &l, &r);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 436 ms 20852 KB Output is correct
2 Correct 446 ms 36252 KB Output is correct
3 Correct 399 ms 51732 KB Output is correct
4 Correct 458 ms 67308 KB Output is correct
5 Correct 449 ms 82808 KB Output is correct
6 Correct 420 ms 98348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 98348 KB Output is correct
2 Correct 2 ms 98348 KB Output is correct
3 Correct 2 ms 98348 KB Output is correct
4 Correct 3 ms 98348 KB Output is correct
5 Correct 3 ms 98348 KB Output is correct
6 Correct 3 ms 98348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 436 ms 20852 KB Output is correct
2 Correct 446 ms 36252 KB Output is correct
3 Correct 399 ms 51732 KB Output is correct
4 Correct 458 ms 67308 KB Output is correct
5 Correct 449 ms 82808 KB Output is correct
6 Correct 420 ms 98348 KB Output is correct
7 Correct 3 ms 98348 KB Output is correct
8 Correct 2 ms 98348 KB Output is correct
9 Correct 2 ms 98348 KB Output is correct
10 Correct 3 ms 98348 KB Output is correct
11 Correct 3 ms 98348 KB Output is correct
12 Correct 3 ms 98348 KB Output is correct
13 Correct 410 ms 112600 KB Output is correct
14 Correct 421 ms 129132 KB Output is correct
15 Correct 395 ms 144340 KB Output is correct
16 Correct 458 ms 160252 KB Output is correct
17 Correct 507 ms 180276 KB Output is correct
18 Correct 525 ms 198788 KB Output is correct
19 Correct 506 ms 217316 KB Output is correct
20 Correct 507 ms 236236 KB Output is correct
21 Correct 511 ms 254732 KB Output is correct
22 Correct 523 ms 262144 KB Output is correct
23 Correct 514 ms 262144 KB Output is correct
24 Correct 565 ms 262144 KB Output is correct
25 Correct 440 ms 262144 KB Output is correct
26 Correct 454 ms 262144 KB Output is correct
27 Correct 594 ms 262144 KB Output is correct
28 Correct 547 ms 262144 KB Output is correct
29 Correct 593 ms 262144 KB Output is correct
30 Correct 792 ms 262144 KB Output is correct
31 Correct 574 ms 262144 KB Output is correct
32 Correct 825 ms 262144 KB Output is correct
33 Correct 458 ms 262144 KB Output is correct