Submission #92218

#TimeUsernameProblemLanguageResultExecution timeMemory
92218IvanCNLO (COCI18_nlo)C++17
110 / 110
522 ms476 KiB
#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)

nlo.cpp: In function 'void sweepline()':
nlo.cpp:35:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<sweep.size();i++){
                ~^~~~~~~~~~~~~
nlo.cpp: In function 'int main()':
nlo.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&M);
  ~~~~~^~~~~~~~~~~~~~~
nlo.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&K);
  ~~~~~^~~~~~~~~
nlo.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&x,&y,&r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...