답안 #230501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
230501 2020-05-10T08:47:01 Z kartel NLO (COCI18_nlo) C++14
110 / 110
786 ms 512 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +100500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

int n, m, q, i, x[101], y[101], R[101], l, r, row, ri[101][N];
ll ans;
vector <pii> ev;

ll Sqrt(ll x)
{
    ll sq = sqrt(x);
    while (sq * sq < x) sq++;
    while (sq * sq > x) sq--;
    return sq;
}

int main()
{
    srand(time(0));
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

//    in("input.txt");
//    out("output.txt");

    cin >> n >> m >> q;
    for (i = 1; i <= q; i++) cin >> x[i] >> y[i] >> R[i];

    for (i = 1; i <= n; i++)
    {

        ev.clear();

        for (int j = 1; j <= q; j++)
        {
            if (x[j] - R[j] > i || x[j] + R[j] < i) continue;
            ll dst = Sqrt(R[j] * 1ll * R[j] - pow((x[j] - i), 2));
            int l = y[j] - dst;
            int r = y[j] + dst + 1;
            ev.pb({l, j});
            ev.pb({r, -j});
        }

        sort(ev.begin(), ev.end());

        set < int > times;

//        cerr << ev[0].F << " " << ev[0].S << el;

        for (int j = 0; j < sz(ev); j++)
        {
//            cerr << ev[i][j].F << " " << ev[i][j].S << el;

            if (sz(times))
                 ans += (ev[j].F - ev[j - 1].F) * 1ll * (*times.begin());

            if (ev[j].S < 0) times.erase(ev[j].S);
                        else times.insert(-ev[j].S);
        }
//        cerr << el;
    }
    cout << n * 1ll * m * q + ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 16 ms 384 KB Output is correct
3 Correct 11 ms 384 KB Output is correct
4 Correct 60 ms 384 KB Output is correct
5 Correct 39 ms 384 KB Output is correct
6 Correct 312 ms 512 KB Output is correct
7 Correct 106 ms 504 KB Output is correct
8 Correct 601 ms 504 KB Output is correct
9 Correct 198 ms 392 KB Output is correct
10 Correct 786 ms 504 KB Output is correct