Submission #146969

# Submission time Handle Problem Language Result Execution time Memory
146969 2019-08-27T01:51:31 Z jun6873 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
226 ms 32888 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1<<19;
int h, w, d, k, qn;
string s[500004];

struct query {
    query() {}
    query(int x, int y) : t(2), x(x), y(y) {}
    query(int x, int y1, int y2, int d) : t(1), x(x), y1(y1), y2(y2), d(d) {}
    int t, x, y1, y2, y, d;
} q[1000004];

struct segt {
    int t[maxn*2];
    int merge(int a, int b) { return a+b; }
    void update(int s, int e, int x, int p, int v) {
        if (s==e) t[x] += v;
        else {
            int m = (s+e)/2;
            if (p<=m) update(s, m, 2*x, p, v);
            else update(m+1, e, 2*x+1, p, v);
            t[x] = merge(t[2*x], t[2*x+1]);
        }
    }
    void update(int p, int v) { return update(0, maxn-1, 1, p, v); }
    int query(int s, int e, int x, int l, int r) {
        if (l<=s and e<=r) return t[x];
        else if (l<=e and s<=r) {
            int m = (s+e)/2;
            return merge(query(s, m, 2*x, l, r), query(m+1, e, 2*x+1, l, r));
        } else return 0;
    }
    int query(int l, int r) { return query(0, maxn-1, 1, l, r); }

    void range_update(int l, int r, int v) {
        update(l, v);
        update(r+1, -v);
    }

    int point_query(int p) {
        return query(0, p);
    }
} t;
int main() {
    cin >> h >> w >> d >> k;

    for (int i=0; i<h; i++) cin >> s[i];

    for (int y=0; y<h; y++) for (int x=0; x<w; x++) {
        if (s[y][x] == 'S') {
            int x1 = max(0, x-d), x2 = min(w-1, x+d), y1 = max(0, y-d), y2 = min(h-1, y+d);
            q[qn++] = query(x1, y1, y2, 1);
            q[qn++] = query(x2+1, y1, y2, -1);
        }
        if (s[y][x] == 'M') {
            q[qn++] = query(x, y);
        }
    }

    sort(q, q+qn, [](query x, query y) { return x.x < y.x or (x.x == y.x and x.t < y.t); });

    int ans = 0;
    for (int i=0; i<qn; i++) {
        if (q[i].t == 1) {
            int y1 = q[i].y1, y2 = q[i].y2, d = q[i].d;
            t.range_update(y1, y2, d);
        }

        if (q[i].t == 2) {
            int y = q[i].y;
            ans += t.point_query(y) >= k;
        }
    }

    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15992 KB Output is correct
2 Correct 18 ms 16376 KB Output is correct
3 Correct 16 ms 16120 KB Output is correct
4 Correct 16 ms 16120 KB Output is correct
5 Correct 16 ms 16048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15992 KB Output is correct
2 Correct 18 ms 16376 KB Output is correct
3 Correct 16 ms 16120 KB Output is correct
4 Correct 16 ms 16120 KB Output is correct
5 Correct 16 ms 16048 KB Output is correct
6 Correct 15 ms 16120 KB Output is correct
7 Correct 15 ms 16124 KB Output is correct
8 Correct 19 ms 16376 KB Output is correct
9 Correct 17 ms 16120 KB Output is correct
10 Correct 15 ms 15992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 15992 KB Output is correct
2 Correct 17 ms 16092 KB Output is correct
3 Correct 18 ms 16248 KB Output is correct
4 Correct 15 ms 16120 KB Output is correct
5 Correct 16 ms 16120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 16248 KB Output is correct
2 Correct 27 ms 16248 KB Output is correct
3 Correct 31 ms 16504 KB Output is correct
4 Correct 30 ms 16504 KB Output is correct
5 Correct 29 ms 16248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 25264 KB Output is correct
2 Correct 135 ms 27908 KB Output is correct
3 Correct 124 ms 25648 KB Output is correct
4 Correct 226 ms 32888 KB Output is correct
5 Correct 177 ms 29872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15992 KB Output is correct
2 Correct 18 ms 16376 KB Output is correct
3 Correct 16 ms 16120 KB Output is correct
4 Correct 16 ms 16120 KB Output is correct
5 Correct 16 ms 16048 KB Output is correct
6 Correct 15 ms 16120 KB Output is correct
7 Correct 15 ms 16124 KB Output is correct
8 Correct 19 ms 16376 KB Output is correct
9 Correct 17 ms 16120 KB Output is correct
10 Correct 15 ms 15992 KB Output is correct
11 Correct 16 ms 15992 KB Output is correct
12 Correct 17 ms 16092 KB Output is correct
13 Correct 18 ms 16248 KB Output is correct
14 Correct 15 ms 16120 KB Output is correct
15 Correct 16 ms 16120 KB Output is correct
16 Correct 27 ms 16248 KB Output is correct
17 Correct 27 ms 16248 KB Output is correct
18 Correct 31 ms 16504 KB Output is correct
19 Correct 30 ms 16504 KB Output is correct
20 Correct 29 ms 16248 KB Output is correct
21 Correct 126 ms 25264 KB Output is correct
22 Correct 135 ms 27908 KB Output is correct
23 Correct 124 ms 25648 KB Output is correct
24 Correct 226 ms 32888 KB Output is correct
25 Correct 177 ms 29872 KB Output is correct
26 Correct 120 ms 24952 KB Output is correct
27 Correct 112 ms 23672 KB Output is correct
28 Correct 150 ms 27896 KB Output is correct
29 Correct 100 ms 22520 KB Output is correct
30 Correct 113 ms 24252 KB Output is correct