답안 #894371

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894371 2023-12-28T07:28:04 Z vjudge1 NLO (COCI18_nlo) C++11
44 / 110
753 ms 10760 KB
#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);
  	int n, m, q, ans = 0;
  	cin >> n >> m >> q;
  	for(int i = 0; i < q; i++){
  		cin >> x[i] >> y[i] >> rd[i];
  		rd[i] *= rd[i];
  	}
  	for(int 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4696 KB Output is correct
2 Correct 6 ms 4700 KB Output is correct
3 Correct 7 ms 5212 KB Output is correct
4 Correct 38 ms 4956 KB Output is correct
5 Incorrect 50 ms 5980 KB Output isn't correct
6 Incorrect 276 ms 7212 KB Output isn't correct
7 Incorrect 159 ms 8252 KB Output isn't correct
8 Incorrect 565 ms 9180 KB Output isn't correct
9 Incorrect 252 ms 10760 KB Output isn't correct
10 Incorrect 753 ms 9736 KB Output isn't correct