# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92218 | IvanC | NLO (COCI18_nlo) | C++17 | 522 ms | 476 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>
using namespace std;
typedef long long ll;
typedef tuple<int,int,int> trinca;
int N,M,K,lastx;
ll somatorio;
set<int> pq;
vector<trinca> circulos,sweep;
void build_sweep(int X){
lastx = 0;
sweep.clear();
pq.clear();
for(int i = 0;i<K;i++){
int x = get<0>(circulos[i]), y = get<1>(circulos[i]),r = get<2>(circulos[i]);
if(abs(X - x) > r) continue;
int sobra = (int)floor(sqrt(1LL*r*r - 1LL*(X-x)*(X-x)));
int y0 = max(1,y - sobra), y1 = min(M,y + sobra) + 1;
sweep.push_back(make_tuple(y0,1,i+1));
sweep.push_back(make_tuple(y1,-1,i+1));
}
sort(sweep.begin(),sweep.end());
}
void sweepline(){
somatorio += 1LL*M*K;
for(int i = 0;i<sweep.size();i++){
int y = get<0>(sweep[i]), delta = get<1>(sweep[i]),idx = get<2>(sweep[i]);
if(!pq.empty()) somatorio += 1LL*(y - lastx)*(*pq.begin());
lastx = y;
if(delta == 1) pq.insert(-idx);
else pq.erase(-idx);
}
}
int main(){
scanf("%d %d",&N,&M);
scanf("%d",&K);
for(int i = 0;i<K;i++){
int x,y,r;
scanf("%d %d %d",&x,&y,&r);
circulos.push_back(make_tuple(x,y,r));
}
for(int i = 1;i<=N;i++){
build_sweep(i);
sweepline();
}
printf("%lld\n",somatorio);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |