#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 100005
#define LOGN 17
#define L(node) node * 2
#define R(node) node * 2 + 1
#define int long long
int tree[4 * N], lazy[4 * N];
void push(int node, int l, int r){
if (lazy[node] == -1) return;
tree[node] = lazy[node] * (r - l + 1);
if (l != r){
lazy[L(node)] = lazy[node];
lazy[R(node)] = lazy[node];
}
lazy[node] = -1;
}
void update(int node, int l, int r, int sl, int sr, int val){
push(node, l, r);
if (l > sr || r < sl || r < l) return;
if (l >= sl && r <= sr){
lazy[node] = val;
push(node, l, r);
return;
}
int mid = (l + r) / 2;
update(L(node), l, mid, sl, sr, val);
update(R(node), mid + 1, r, sl, sr, val);
tree[node] = tree[L(node)] + tree[R(node)];
}
int query(int node, int l, int r, int sl, int sr){
push(node, l, r);
if (l > r || l > sr || r < sl) return 0;
if (l >= sl && r <= sr) return tree[node];
int mid = (l + r) / 2;
return query(L(node), l, mid, sl, sr) + query(R(node), mid + 1, r, sl, sr);
}
int sq(int x){
int ans = 0;
for (int i = LOGN; i >= 0; i--){
int tmp = ans + (1<<i);
if (tmp * tmp <= x) ans = tmp;
}
return ans;
}
int32_t main(){
#ifndef ONLINE_JUDGE
//fileio();
#endif
fastio();
memset(lazy, -1, sizeof(lazy));
int n, m;
cin>>n>>m;
int k;
cin>>k;
vector<array<int, 4>> v;
for (int i = 1; i <= k; i++){
int x, y, r;
cin>>x>>y>>r;
v.pb({x, y, r, i});
}
reverse(v.begin(), v.end());
int res = 0;
for (int i = 1; i <= n; i++){
update(1, 1, m, 1, m, 1);
for (auto j : v){
int x = j[0], y = j[1], r = j[2], timee = j[3];
if ((x - i) * (x - i) > r * r)
{
continue;
}
int a = (x - i) * (x - i);
int b = r * r;
int t = sq(b - a);
int k = query(1, 1, m, y - t, y + t);
res += k * timee;
update(1, 1, m, y - t, y + t, 0);
}
}
cout<<n * m * k - res<<endl;
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
3412 KB |
Output is correct |
2 |
Correct |
23 ms |
3488 KB |
Output is correct |
3 |
Correct |
21 ms |
3468 KB |
Output is correct |
4 |
Correct |
172 ms |
3688 KB |
Output is correct |
5 |
Correct |
169 ms |
4476 KB |
Output is correct |
6 |
Correct |
1260 ms |
4480 KB |
Output is correct |
7 |
Correct |
500 ms |
5496 KB |
Output is correct |
8 |
Correct |
2811 ms |
5488 KB |
Output is correct |
9 |
Correct |
974 ms |
5504 KB |
Output is correct |
10 |
Execution timed out |
3052 ms |
5480 KB |
Time limit exceeded |