#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<cassert>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include<stack>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#define int long long
const int mod=998244353,mxn=1e5+5,lg=30,inf=1e18,minf=-1e9,Mxn=100000,root=700;
int n,m;
void setIO(string name){
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
pii cal(int x,int y,int d,int r){
d=(x-d)*(x-d);
r=(r*r)-d;
if(r<0)return {inf,inf};
r=sqrtl(r);
return {y-r,y+r};
}
struct seg{
ll v[4*mxn+10],add[4*mxn+10];
void init(){for(int i=0;i<=4*n;i++)v[i]=0,add[i]=-1;}
void push(int l,int r,int pos){
if(add[pos]==-1)return;
v[pos]=add[pos]*(r-l+1);
if(l!=r)add[pos*2]=add[pos*2+1]=add[pos];
add[pos]=-1;
}
void update(int l,int r,int ql,int qr,int pos,int val){
push(l,r,pos);
if(l>qr||r<ql)return;
if(l>=ql&&r<=qr){
add[pos]=val;
push(l,r,pos);
return;
}
int mid=l+(r-l)/2;
update(l,mid,ql,qr,pos*2,val);
update(mid+1,r,ql,qr,pos*2+1,val);
v[pos]=v[pos*2]+v[pos*2+1];
}
int qry(int l,int r,int ql,int qr,int pos){
push(l,r,pos);
if(l>qr||r<ql)return 0;
if(l>=ql&&r<=qr)return v[pos];
int mid=l+(r-l)/2;
return (qry(l,mid,ql,qr,pos*2)+qry(mid+1,r,ql,qr,pos*2+1));
}
}t;
int32_t main(){
//setIO("lifeguards");
cin>>n>>m;
int k;cin>>k;
vector<pair<pii,int>>v(k);
for(int i=0;i<k;i++)cin>>v[i].f.f>>v[i].f.s>>v[i].s;
int ans=0;
t.init();
for(int i=1;i<=n;i++){
for(int j=0;j<k;j++){
pii a=cal(v[j].f.f,v[j].f.s,i,v[j].s);
if(a.f!=inf)t.update(1,m,a.f,a.s,1,j+1);
}
ans+=(k*m)-t.qry(1,m,1,m,1);
t.update(1,m,1,m,1,0);
}
cout<<ans;
}
Compilation message
nlo.cpp: In function 'void setIO(std::string)':
nlo.cpp:36:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nlo.cpp:37:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2396 KB |
Output is correct |
2 |
Correct |
10 ms |
2536 KB |
Output is correct |
3 |
Correct |
9 ms |
4700 KB |
Output is correct |
4 |
Correct |
68 ms |
4700 KB |
Output is correct |
5 |
Correct |
65 ms |
4700 KB |
Output is correct |
6 |
Correct |
462 ms |
5212 KB |
Output is correct |
7 |
Correct |
199 ms |
5468 KB |
Output is correct |
8 |
Correct |
981 ms |
5660 KB |
Output is correct |
9 |
Correct |
369 ms |
6488 KB |
Output is correct |
10 |
Correct |
1354 ms |
6692 KB |
Output is correct |