Submission #513777

# Submission time Handle Problem Language Result Execution time Memory
513777 2022-01-17T15:38:56 Z wildturtle NLO (COCI18_nlo) C++14
99 / 110
3000 ms 4484 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define sc second
#define pb push_back
using namespace std;
ll a,b,c,d,i,e,f,g,n,m,k,l,minn,t,le,ri,ans,maxx,sz,cur,curr;
pair < pair <ll,ll> , ll> A[500005];
ll tree[500005],tree1[500005];
void update(ll node,ll le,ll ri,ll start,ll end,ll 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];
}
ll getSum(ll node,ll le,ll ri,ll start,ll 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() {
    cin>>n>>m;
    cin>>k;
    for(ll i=1;i<=k;i++) {
        cin>>A[i].f.f>>A[i].f.sc>>A[i].sc;
    }
    for(ll i=1;i<=n;i++) {
        for(ll 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;
            //cout<<le<<" "<<ri<<endl;
            sz=(ri-le+1);
            cur=sz-getSum(1,1,m,le,ri);
            ans+=(k-j)*cur;
           // cout<<i<<"_"<<le<<" "<<ri<<" "<<cur<<" "<<ans<<endl;
            update(1,1,m,le,ri,1);
        }
        cur=m-getSum(1,1,m,1,m);
        ans+=k*cur;
        curr=cur;
        //cout<<i<<"_"<<le<<" "<<ri<<" "<<cur<<" "<<ans<<endl;;
        update(1,1,m,1,m,2);
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 292 KB Output is correct
2 Correct 20 ms 276 KB Output is correct
3 Correct 18 ms 332 KB Output is correct
4 Correct 199 ms 928 KB Output is correct
5 Correct 153 ms 2356 KB Output is correct
6 Correct 1190 ms 2472 KB Output is correct
7 Correct 497 ms 4356 KB Output is correct
8 Correct 2566 ms 4464 KB Output is correct
9 Correct 936 ms 4392 KB Output is correct
10 Execution timed out 3050 ms 4484 KB Time limit exceeded