Submission #105474

#TimeUsernameProblemLanguageResultExecution timeMemory
105474igziNLO (COCI18_nlo)C++17
0 / 110
305 ms13880 KiB
#include <bits/stdc++.h> using namespace::std; set <pair<int,int>> s[100005]; long long n,m,k,i,j,a[100005],x[100005],y[100005],r[100005],ans; long long dodaj(int p,int l,int d){ long long ans,a,b; ans=d-l+1; set<pair<int,int>>::iterator it; while(true){ it=s[p].lower_bound({l,d}); if(it==s[p].end()) break; if((*it).second<=d) {ans-=(*it).second-(*it).first+1; s[p].erase(it);} else break; } it=s[p].lower_bound({l,d}); a=l; b=d; if(it!=s[p].end() && d+1>=(*it).first){ b=(*it).second; ans-=d+1-(*it).first; s[p].erase(it); } it=s[p].lower_bound({l,d}); if(it!=s[p].begin()){ it--; if((*it).second+1>=l){ a=(*it).first; ans-=(*it).second+1-l; s[p].erase(it); } } s[p].insert({a,b}); return ans; } int main(){ std::ios_base::sync_with_stdio(0); cin>>n>>m>>k; for(i=0;i<k;i++){ cin>>x[i]>>y[i]>>r[i]; } ans=n*m*k; for(i=k-1;i>=0;i--){ a[i]=0; for(j=y[i]-r[i];j<=y[i]+r[i];j++){ long long d; d=sqrt(r[i]*r[i]-(j-y[i])*(j-y[i])); if(d*d>r[i]*r[i]-(j-y[i])*(j-y[i])) d--; a[i]+=dodaj(j,x[i]-d,x[i]+d); } ans-=(i+1)*a[i]; } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...