Submission #97458

#TimeUsernameProblemLanguageResultExecution timeMemory
97458KLPPNLO (COCI18_nlo)C++14
33 / 110
65 ms66560 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int lld; typedef pair<int,int> pii; class intervals{ vector<pair<int,pii > >v; public: void insert(int val, int x, int y){ v.push_back(pair<int,pii>(x,pii(val,0))); v.push_back(pair<int,pii>(y+1,pii(val,1))); } lld calculate(){ sort(v.begin(),v.end()); set<int> s; set<int>::iterator it; lld point=0; lld ans=0; for(int i=0;i<v.size();i++){ if(s.size()>0){ it=s.end(); it--; lld s=*it; ans+=s*(v[i].first-point); //cout<<s<<" "<<v[i].first-point<<endl; } point=v[i].first; //cout<<ans<<endl; if(v[i].second.second){ s.erase(v[i].second.first); }else s.insert(v[i].second.first); }return ans; } void print(){ for(int i=0;i<v.size();i++){ cout<<v[i].first<<" "<<v[i].second.first<<" "<<v[i].second.second<<endl; } } }; lld absol(lld a){ if(a>0)return a; return -a; } lld f(lld a, lld b){ if(a<b)return -1; lld lo=0; lld hi=1000000000; while(hi-lo>1){ lld mid=(hi+lo)/2; if(mid*mid+b*b<=a*a){ lo=mid; }else hi=mid; }return lo; } int main(){ int n,m; cin>>n>>m; int arr[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++)arr[i][j]=0; }int k; cin>>k; intervals *SETS[m]; for(int i=0;i<m;i++){ SETS[i]=new intervals(); } for(int i=1;i<=k;i++){ int x,y,r; cin>>x>>y>>r; x--;y--; //cout<<x<<" "<<y<<endl; for(int j=0;j<m;j++){ lld diff=absol(j-y); lld diff2=f(r,diff); if(diff2!=-1){ //cout<<r<<" "<<diff<<" "<<f(r,diff)<<endl; //cout<<j<<" "<<x-diff2<<" "<<x+diff2<<endl; SETS[j]->insert(i,x-diff2,x+diff2); } } }lld ans=0; for(int i=0;i<m;i++){ ans+=k*n-SETS[i]->calculate(); //SETS[i]->print(); }cout<<ans<<endl; return 0; }

Compilation message (stderr)

nlo.cpp: In member function 'lld intervals::calculate()':
nlo.cpp:19:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<v.size();i++){
               ~^~~~~~~~~
nlo.cpp: In member function 'void intervals::print()':
nlo.cpp:35:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<v.size();i++){
               ~^~~~~~~~~
nlo.cpp: In function 'int main()':
nlo.cpp:58:6: warning: variable 'arr' set but not used [-Wunused-but-set-variable]
  int arr[n][m];
      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...