Submission #230452

#TimeUsernameProblemLanguageResultExecution timeMemory
230452VEGAnnNLO (COCI18_nlo)C++14
88 / 110
757 ms65540 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define pii pair<int,int> #define pis pair<int,int> #define ft first #define sd second #define MP make_pair #define PB push_back #define all(x) x.begin(),x.end() using namespace std; typedef long long ll; const int oo = 2e9; const int N = 100100; vector<array<int, 3> > events; set<int> st; int n, m, k; ll ans = 0; ll sqr(ll x) { return (x * x); } ll dist(int &x1, int &x2, int &y1, int y2){ return sqr(x1 - x2) + sqr(y1 - y2); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> n >> m >> k; for (int i = 0; i < k; i++){ int x, y, r; cin >> x >> y >> r; int ro = max(1, x - r), lf = y, rt = y; ll rr = sqr(r); while (ro <= x){ while (lf > 1 && dist(x, ro, y, lf - 1) <= rr) lf--; while (rt < m && dist(x, ro, y, rt + 1) <= rr) rt++; events.PB({ro, lf, i + 1}); events.PB({ro, rt + 1, -(i + 1)}); ro++; } ro = min(n, x + r), lf = y, rt = y; while (ro > x){ while (lf > 1 && dist(x, ro, y, lf - 1) <= rr) lf--; while (rt < m && dist(x, ro, y, rt + 1) <= rr) rt++; events.PB({ro, lf, i + 1}); events.PB({ro, rt + 1, -(i + 1)}); ro--; } } sort(all(events)); for (int i = 1, ptr = 0; i <= n; i++){ int lst = 0; if (ptr == sz(events) || events[ptr][0] > i){ ans += ll(k) * ll(m); continue; } int nw_ptr = ptr; while (nw_ptr < sz(events) && events[nw_ptr][0] == i) nw_ptr++; st.clear(); st.insert(0); for (int it = ptr; it < nw_ptr; ){ int j = it; ans += (ll(events[j][1]) - ll(lst) - 1) * (ll(k) - ll(*(--st.end()))); lst = events[j][1] - 1; while (j < sz(events) && events[j][1] == events[it][1]){ if (events[j][2] < 0) st.erase(-events[j][2]); else st.insert(events[j][2]); j++; } it = j; } ans += (ll(m) - ll(lst)) * ll(k); ptr = nw_ptr; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...