Submission #513795

#TimeUsernameProblemLanguageResultExecution timeMemory
513795wildturtleNLO (COCI18_nlo)C++14
99 / 110
3082 ms2532 KiB
#include<bits/stdc++.h> #define ll long long #define f first #define sc second #define pb push_back using namespace std; int n,m,k,le,ri,sz,cur; ll ans; pair < pair <int,int> , int> A[105]; int tree[500005],tree1[500005]; void update(int node,int le,int ri,int start,int end,int val) { if(tree1[node]!=0) { if(tree1[node]==2) tree[node]=0; else tree[node]=ri-le+1; if(le!=ri) { tree1[2*node]=tree1[node]; tree1[2*node+1]=tree1[node]; } tree1[node]=0; } if(end<le || ri<start) return; if(start<=le && ri<=end) { if(val==2) tree[node]=0; else tree[node]=ri-le+1; if(le!=ri) { tree1[2*node]=val; tree1[2*node+1]=val; } return; } update(2*node,le,(le+ri)/2,start,end,val); update(2*node+1,(le+ri)/2+1,ri,start,end,val); tree[node]=tree[2*node]+tree[2*node+1]; } int getSum(int node,int le,int ri,int start,int end) { if(tree1[node]!=0) { if(tree1[node]==2) tree[node]=0; else tree[node]=ri-le+1; if(le!=ri) { tree1[2*node]=tree1[node]; tree1[2*node+1]=tree1[node]; } tree1[node]=0; } if(end<le || ri<start) return 0; if(start<=le && ri<=end) { return tree[node]; } return getSum(2*node,le,(le+ri)/2,start,end)+getSum(2*node+1,(le+ri)/2+1,ri,start,end); } int main() { std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n>>m; cin>>k; for(int i=1;i<=k;i++) { cin>>A[i].f.f>>A[i].f.sc>>A[i].sc; } for(int i=1;i<=n;i++) { for(int j=k;j>=1;j--) { if(abs(i-A[j].f.f)>A[j].sc) continue; sz=(A[j].sc*A[j].sc)-(abs(i-A[j].f.f)*abs(i-A[j].f.f)); sz=sqrtl(sz); le=A[j].f.sc-sz; ri=A[j].f.sc+sz; sz=(ri-le+1); cur=sz-getSum(1,1,m,le,ri); ans+=(k-j)*cur; update(1,1,m,le,ri,1); } cur=m-getSum(1,1,m,1,m); ans+=k*cur; update(1,1,m,1,m,2); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...