Submission #230432

# Submission time Handle Problem Language Result Execution time Memory
230432 2020-05-10T06:44:27 Z VEGAnn NLO (COCI18_nlo) C++14
0 / 110
414 ms 65540 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pii 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<pii> events[N];
set<int> st;
int n, m, k;
ll ans = 0;

ll sqr(ll x) { return (x * x); }

ll dist(ll x1, ll x2, ll y1, ll 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[ro].PB(MP(lf, i + 1));
            events[ro].PB(MP(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[ro].PB(MP(lf, i + 1));
            events[ro].PB(MP(rt + 1, -(i + 1)));
            ro--;
        }
    }

    for (int i = 1; i <= n; i++){
        int lst = 0;
        sort(all(events[i]));

        st.clear();
        st.insert(0);

        for (int it = 0; it < sz(events[i]); ){
            int j = it;

            ans += (ll(events[i][j].ft) - ll(lst) - 1) * (ll(k) - ll(*(--st.end())));

            lst = events[i][j].ft - 1;

            while (j < sz(events[i]) && events[i][j].ft == events[i][it].ft){
                if (events[i][j].sd < 0)
                    st.erase(-events[i][j].sd);
                else st.insert(events[i][j].sd);

                j++;
            }

            it = j;
        }

        if (lst < m)
            ans += (ll(m) - ll(lst)) * ll(k);
    }

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 2944 KB Output isn't correct
2 Incorrect 19 ms 3840 KB Output isn't correct
3 Incorrect 14 ms 3712 KB Output isn't correct
4 Incorrect 73 ms 9592 KB Output isn't correct
5 Incorrect 54 ms 8444 KB Output isn't correct
6 Incorrect 414 ms 47608 KB Output isn't correct
7 Incorrect 151 ms 20984 KB Output isn't correct
8 Runtime error 176 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Incorrect 270 ms 35192 KB Output isn't correct
10 Runtime error 178 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)