Submission #230501

#TimeUsernameProblemLanguageResultExecution timeMemory
230501kartelNLO (COCI18_nlo)C++14
110 / 110
786 ms512 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...