답안 #105478

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
105478 2019-04-12T15:03:29 Z igzi NLO (COCI18_nlo) C++17
110 / 110
127 ms 13176 KB
#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;
it=s[p].lower_bound({l+1,d});
if(it!=s[p].begin()){
    it--;
    if((*it).first<=l && (*it).second>=d) return 0;
}
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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5120 KB Output is correct
2 Correct 11 ms 5120 KB Output is correct
3 Correct 11 ms 5504 KB Output is correct
4 Correct 25 ms 5504 KB Output is correct
5 Correct 24 ms 7808 KB Output is correct
6 Correct 51 ms 6776 KB Output is correct
7 Correct 49 ms 10232 KB Output is correct
8 Correct 127 ms 9848 KB Output is correct
9 Correct 113 ms 13176 KB Output is correct
10 Correct 125 ms 10616 KB Output is correct