# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
894372 | vjudge1 | NLO (COCI18_nlo) | C++11 | 812 ms | 10576 KiB |
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>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e5 + 10;
const ll mod = 1e9 + 7;
ll um(ll a, ll b){
return ((1LL * a * b) % mod + mod) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
ll add(ll a, ll b){
return ((1LL * a + b) % mod + mod) % mod;
}
ll binpow(ll x, ll step){
ll res = 1LL;
while(step){
if(step & 1) res = um(res, x);
x = um(x, x);
step /= 2;
}
return res;
}
/*
Восемь восемьсот пять пять пять
три пять три пять
Проще кому то позвонить
чем у кого-то деньги занимать
*/
ll x[N], y[N], rd[N];
vector <pll> vec[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n, m, q, ans = 0;
cin >> n >> m >> q;
for(ll i = 0; i < q; i++){
cin >> x[i] >> y[i] >> rd[i];
rd[i] *= rd[i];
}
for(ll i = 1; i <= n; i++){
vec[i].pb({1, m});
}
for(ll i = q - 1; i >= 0; i--){
for(ll j = 1; j <= n; j++){
if((j - x[i]) * (j - x[i]) > rd[i]) continue;
ll l = y[i], r = m + 1, ansl, ansr;
while(r - l > 1){
ll mid = (r + l) / 2;
ll s1 = (mid - y[i]) * (mid - y[i]);
ll s2 = (j - x[i]) * (j - x[i]);
if(s1 + s2 <= rd[i]) l = mid;
else r = mid;
}
ansr = l;
l = 0;
r = y[i];
while(r - l > 1){
ll mid = (r + l) / 2;
ll s1 = (mid - y[i]) * (mid - y[i]);
ll s2 = (j - x[i]) * (j - x[i]);
if(s1 + s2 <= rd[i]) r = mid;
else l = mid;
}
ansl = r;
vector <pll> nw;
for(auto u : vec[j]){
if(ansl <= u.F && u.S <= ansr){
ans += (q - i - 1) * (u.S - u.F + 1);
continue;
}
if(u.F <= ansl && ansr <= u.S){
ans += (q - i - 1) * (ansr - ansl + 1);
if(u.F < ansl) nw.pb({u.F, ansl - 1});
if(ansr < u.S) nw.pb({ansr + 1, u.S});
continue;
}
if(u.F <= ansl && ansl <= u.S){
ans += (q - i - 1) * (u.S - ansl + 1);
if(u.F < ansl) nw.pb({u.F, ansl - 1});
continue;
}
if(u.F <= ansr && ansr <= u.S){
ans += (q - i - 1) * (ansr - u.F + 1);
if(ansr < u.S) nw.pb({ansr + 1, u.S});
continue;
}
nw.pb(u);
}
swap(nw, vec[j]);
}
}
for(ll i = 1; i <= n; i++){
for(auto u : vec[i]){
ans += q * (u.S - u.F + 1);
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |