Submission #22880

# Submission time Handle Problem Language Result Execution time Memory
22880 2017-04-30T07:58:57 Z Lazy Against The Machine(#969, unused, celicath, Paruelain) Donut-shaped Enclosure (KRIII5_DE) C++14
2 / 7
1500 ms 80552 KB
#include <bits/stdc++.h>
using namespace std;

// example implementation of sum tree
constexpr int TSIZE = 2097152; // always 2^k form && n <= TSIZE
int segtree[TSIZE * 2];
int prop[TSIZE * 2];
void seg_relax(int nod, int l, int r) {
    if (prop[nod] == 0) return;
    if (l < r) {
        int m = (l + r) >> 1;
        segtree[nod << 1] += prop[nod];
        prop[nod << 1] += prop[nod];
        segtree[nod << 1 | 1] += prop[nod];
        prop[nod << 1 | 1] += prop[nod];
    }
    prop[nod] = 0;
}
void seg_update(int nod, int l, int r, int s, int e, int val) {
    if (r < s || e < l) return;
    if (s <= l && r <= e) {
        segtree[nod] += val;
        prop[nod] += val;
        return;
    }
    seg_relax(nod, l, r);
    int m = (l + r) >> 1;
    seg_update(nod << 1, l, m, s, e, val);
    seg_update(nod << 1 | 1, m + 1, r, s, e, val);
    segtree[nod] = max(segtree[nod << 1], segtree[nod << 1 | 1]);
}
// usage:
// seg_update(1, 0, n - 1, qs, qe, val);
// seg_query(1, 0, n - 1, qs, qe);

vector<int> xcrd;
int n, l, r;
map<pair<int, int>, vector<tuple<int, int, int>>> events;

void add_seg(int x, int val, int big, int sub)
{
    int L = (lower_bound(xcrd.begin(), xcrd.end(), x - (big ? r : l)) - xcrd.begin()) * 3 + 1;
    int R = (lower_bound(xcrd.begin(), xcrd.end(), x + (big ? r : l)) - xcrd.begin()) * 3 + 1;

    if (big)
    {
        seg_update(1, 0, TSIZE - 1, L, R, val * (sub ? -1 : 1));
    }
    else
    {
        seg_update(1, 0, TSIZE - 1, L + 1, R - 1, val * (sub ? -1 : 1));
    }
}

int main()
{
    scanf("%d%d%d",&n,&l,&r);

    for (int i = 0; i < n; i++)
    {
        int x, y, val;
        scanf("%d%d%d",&x,&y,&val);
        xcrd.push_back(x - l);
        xcrd.push_back(x + l);
        xcrd.push_back(x - r);
        xcrd.push_back(x + r);
        events[{y - r, 0}].emplace_back(x, val, 1);
        events[{y - l, 1}].emplace_back(x, val, 0);
        events[{y + l, 0}].emplace_back(x, val, 0);
        events[{y + r, 1}].emplace_back(x, val, 1);
    }

    sort(xcrd.begin(), xcrd.end());
    xcrd.erase(unique(xcrd.begin(), xcrd.end()), xcrd.end());

    int ans = 0;

    for (auto &&e : events)
    {
        for (auto &&elem : e.second)
        {
            int x, val, big;
            tie(x, val, big) = elem;
            add_seg(x, val, big, e.first.second);
        }

        ans = max(ans, segtree[1]);
    }

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

Compilation message

DE.cpp: In function 'void seg_relax(int, int, int)':
DE.cpp:11:13: warning: unused variable 'm' [-Wunused-variable]
         int m = (l + r) >> 1;
             ^
DE.cpp: In function 'int main()':
DE.cpp:57:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&l,&r);
                             ^
DE.cpp:62:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&x,&y,&val);
                                   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 34796 KB Output is correct
2 Correct 0 ms 34796 KB Output is correct
3 Correct 0 ms 34796 KB Output is correct
4 Correct 0 ms 34796 KB Output is correct
5 Correct 0 ms 34928 KB Output is correct
6 Correct 0 ms 34928 KB Output is correct
7 Correct 0 ms 34928 KB Output is correct
8 Correct 3 ms 35060 KB Output is correct
9 Correct 0 ms 35060 KB Output is correct
10 Correct 3 ms 35068 KB Output is correct
11 Correct 3 ms 35060 KB Output is correct
12 Correct 6 ms 35072 KB Output is correct
13 Correct 3 ms 35060 KB Output is correct
14 Correct 3 ms 35072 KB Output is correct
15 Correct 3 ms 35072 KB Output is correct
16 Correct 6 ms 35060 KB Output is correct
17 Correct 3 ms 35060 KB Output is correct
18 Correct 6 ms 35060 KB Output is correct
19 Correct 6 ms 35072 KB Output is correct
20 Correct 6 ms 35060 KB Output is correct
21 Correct 6 ms 35072 KB Output is correct
22 Correct 3 ms 35072 KB Output is correct
23 Correct 9 ms 35060 KB Output is correct
24 Correct 6 ms 35060 KB Output is correct
25 Correct 6 ms 35072 KB Output is correct
26 Correct 6 ms 35072 KB Output is correct
27 Correct 3 ms 35064 KB Output is correct
28 Correct 6 ms 35060 KB Output is correct
29 Correct 3 ms 35064 KB Output is correct
30 Correct 6 ms 35072 KB Output is correct
31 Correct 3 ms 35060 KB Output is correct
32 Correct 3 ms 35060 KB Output is correct
33 Correct 3 ms 35060 KB Output is correct
34 Correct 3 ms 35060 KB Output is correct
35 Correct 3 ms 35060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 34796 KB Output is correct
2 Correct 0 ms 34796 KB Output is correct
3 Correct 0 ms 34796 KB Output is correct
4 Correct 0 ms 34796 KB Output is correct
5 Correct 0 ms 34928 KB Output is correct
6 Correct 0 ms 34928 KB Output is correct
7 Correct 0 ms 34928 KB Output is correct
8 Correct 3 ms 35060 KB Output is correct
9 Correct 0 ms 35060 KB Output is correct
10 Correct 3 ms 35068 KB Output is correct
11 Correct 3 ms 35060 KB Output is correct
12 Correct 6 ms 35072 KB Output is correct
13 Correct 3 ms 35060 KB Output is correct
14 Correct 3 ms 35072 KB Output is correct
15 Correct 3 ms 35072 KB Output is correct
16 Correct 6 ms 35060 KB Output is correct
17 Correct 3 ms 35060 KB Output is correct
18 Correct 6 ms 35060 KB Output is correct
19 Correct 6 ms 35072 KB Output is correct
20 Correct 6 ms 35060 KB Output is correct
21 Correct 6 ms 35072 KB Output is correct
22 Correct 3 ms 35072 KB Output is correct
23 Correct 9 ms 35060 KB Output is correct
24 Correct 6 ms 35060 KB Output is correct
25 Correct 6 ms 35072 KB Output is correct
26 Correct 6 ms 35072 KB Output is correct
27 Correct 3 ms 35064 KB Output is correct
28 Correct 6 ms 35060 KB Output is correct
29 Correct 3 ms 35064 KB Output is correct
30 Correct 6 ms 35072 KB Output is correct
31 Correct 3 ms 35060 KB Output is correct
32 Correct 3 ms 35060 KB Output is correct
33 Correct 3 ms 35060 KB Output is correct
34 Correct 3 ms 35060 KB Output is correct
35 Correct 3 ms 35060 KB Output is correct
36 Correct 0 ms 34928 KB Output is correct
37 Correct 3 ms 35060 KB Output is correct
38 Correct 6 ms 35324 KB Output is correct
39 Correct 13 ms 35720 KB Output is correct
40 Correct 23 ms 36260 KB Output is correct
41 Correct 36 ms 36920 KB Output is correct
42 Correct 59 ms 37580 KB Output is correct
43 Correct 83 ms 38504 KB Output is correct
44 Correct 103 ms 39556 KB Output is correct
45 Correct 136 ms 40480 KB Output is correct
46 Correct 173 ms 41668 KB Output is correct
47 Correct 209 ms 43244 KB Output is correct
48 Correct 256 ms 44564 KB Output is correct
49 Correct 789 ms 59596 KB Output is correct
50 Correct 883 ms 60124 KB Output is correct
51 Execution timed out 1500 ms 80552 KB Execution timed out
52 Halted 0 ms 0 KB -