This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |