Submission #92798

#TimeUsernameProblemLanguageResultExecution timeMemory
92798fbosnjakNLO (COCI18_nlo)C++14
88 / 110
551 ms66560 KiB
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y, r; long long sol, val, mid, pl; vector <pair <int,int> > v[100100]; class cmp { public: bool operator ()(pair <int,int> a, pair <int,int> b) { if (a.second!=b.second) return a.second>b.second; return a.first<b.first; } }; void sweep(int x) { long long sol1=sol; set <pair <int,int>, cmp> s; set <pair <int,int>, cmp>::iterator it; bool aktiv=0; int last=v[x][0].first; s.insert(v[x][0]); if (v[x][0].second==0) aktiv=1; for (int i=1;i<v[x].size();i++) { if (aktiv) { it=s.begin(); sol+=(long long)((v[x][i].first-last)*(k-it->second)); } if (v[x][i].second==0) { if (aktiv) { aktiv=0; s.erase(make_pair(1,0)); } else { aktiv=1; s.insert(make_pair(1,0)); } } else { if (v[x][i].second<0) s.erase(s.lower_bound(make_pair(-1e9,-v[x][i].second))); else s.insert(v[x][i]); } last=v[x][i].first; } } int bs(int x, int lou, int haj) { while (haj-lou>1) { int mid=(lou+haj)/2; if (pl+(y-mid)*(y-mid)<=val) haj=mid; else lou=mid; } if ((y-lou)*(y-lou)+pl<=val) return lou; else return haj; } int bs2(int x, int lou, int haj) { while (haj-lou>1) { int mid=(lou+haj)/2; if (pl+(y-mid)*(y-mid)<=val) lou=mid; else haj=mid; } if ((y-haj)*(y-haj)+pl<=val) return haj; else return lou; } int main() { ios_base::sync_with_stdio(false); cin.tie(); cin >> n >> m >> k; for (int i=1;i<=k;i++) { cin >> x >> y >> r; for (int j=max(1,x-r);j<=min(n,x+r);j++) { pl=(x-j)*(x-j); val=(long long)r*r; v[j].push_back(make_pair(bs(j,0,y),i)); v[j].push_back(make_pair(bs2(j,y,m+1)+1,-i)); } } for (int i=1;i<=n;i++) {v[i].push_back(make_pair(1,0)); v[i].push_back(make_pair(m+1,0));} for (int i=1;i<=n;i++) { sort(v[i].begin(),v[i].end()); } for (int i=1;i<=n;i++) sweep(i); cout << sol; }

Compilation message (stderr)

nlo.cpp: In function 'void sweep(int)':
nlo.cpp:26:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=1;i<v[x].size();i++) {
                  ~^~~~~~~~~~~~
nlo.cpp:19:15: warning: unused variable 'sol1' [-Wunused-variable]
     long long sol1=sol;
               ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...