Submission #1346208

#TimeUsernameProblemLanguageResultExecution timeMemory
1346208Jawad_Akbar_JJNLO (COCI18_nlo)C++20
110 / 110
93 ms14252 KiB
#include <iostream>
#include <set>

using namespace std;
int n, m, k;
long long Ans;
set<pair<int, int>> st[1<<17];

int get(int i, int l, int r){
	int ans = 0, L = l, R = r;
	auto u = st[i].upper_bound({l, 0});
	int lst = l-1;
	if (u != begin(st[i]) and (*prev(u)).second >= l)
		L = (*prev(u)).first, R = max(R, (*prev(u)).second), lst = (*prev(u)).second, st[i].erase(prev(u));

	while (u != st[i].end() and (*u).first <= r){
		ans += min(r, (*u).first) - lst - 1;
		lst = (*u).second;
		u = next(u);
		st[i].erase(prev(u));
		R = max(R, lst);
	}
	if (lst < r)
		ans += r - lst;
	st[i].insert({L, R});
	return ans;
}

void solve(int iter){
	if (iter == -1)
		return;
	int x, y, r;
	cin>>x>>y>>r;

	solve(iter - 1);

	for (int i=r, j = 0;i >= 0;i--){
		while (i * i + (j+1) * (j+1) <= r * r)
			j++;
		Ans += 1LL * get(x - i, y - j, y + j) * iter;
	}
	for (int i=1, j=r;i<=r;i++){
		while (i * i + j * j > r * r)
			j--;
		Ans += 1LL * get(x + i, y - j, y + j) * iter;
	}
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin>>n>>m>>k;

	solve(k-1);

	for (int i=1;i<=n;i++)
		Ans += 1LL * get(i, 1, m) * k;
	
	cout<<Ans<<'\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...