# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
230459 |
2020-05-10T07:29:04 Z |
VEGAnn |
NLO (COCI18_nlo) |
C++14 |
|
944 ms |
62332 KB |
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define pis pair<int,short>
#define ft first
#define sd second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int oo = 2e9;
const int N = 100100;
vector<int> events[N];
set<int> st;
int n, m, k;
ll ans = 0;
ll sqr(ll x) { return (x * x); }
ll dist(int &x1, int &x2, int &y1, int y2){
return sqr(x1 - x2) + sqr(y1 - y2);
}
int make(int fi, int se){
int res = fi;
res <<= 7;
res += abs(se);
res <<= 1;
if (se < 0)
res += 1;
return res;
}
pis get(int vl){
int fi = 0, se = 0;
bool ot = bool(vl & 1);
vl >>= 1;
se = vl % (1 << 7);
fi = (vl >> 7);
if (ot)
se = -se;
return MP(fi, se);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m >> k;
for (int i = 0; i < k; i++){
int x, y, r;
cin >> x >> y >> r;
int ro = max(1, x - r), lf = y, rt = y;
ll rr = sqr(r);
while (ro <= x){
while (lf > 1 && dist(x, ro, y, lf - 1) <= rr)
lf--;
while (rt < m && dist(x, ro, y, rt + 1) <= rr)
rt++;
events[ro].PB(make(lf, i + 1));
events[ro].PB(make(rt + 1, -(i + 1)));
ro++;
}
ro = min(n, x + r), lf = y, rt = y;
while (ro > x){
while (lf > 1 && dist(x, ro, y, lf - 1) <= rr)
lf--;
while (rt < m && dist(x, ro, y, rt + 1) <= rr)
rt++;
events[ro].PB(make(lf, i + 1));
events[ro].PB(make(rt + 1, -(i + 1)));
ro--;
}
}
for (int i = 1; i <= n; i++){
int lst = 0;
if (!sz(events[i])){
ans += ll(k) * ll(m);
continue;
}
sort(all(events[i]));
st.clear();
st.insert(0);
for (int it = 0; it < sz(events[i]); ){
int j = it;
pis cur = get(events[i][j]);
ans += (ll(cur.ft) - ll(lst) - 1) * (ll(k) - ll(*(--st.end())));
lst = cur.ft - 1;
while (j < sz(events[i]) && lst + 1 == cur.ft){
if (cur.sd < 0)
st.erase(-cur.sd);
else st.insert(cur.sd);
j++;
if (j < sz(events[i]))
cur = get(events[i][j]);
}
it = j;
}
if (lst < m)
ans += (ll(m) - ll(lst)) * ll(k);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2816 KB |
Output is correct |
2 |
Correct |
18 ms |
3200 KB |
Output is correct |
3 |
Correct |
13 ms |
3328 KB |
Output is correct |
4 |
Correct |
65 ms |
6144 KB |
Output is correct |
5 |
Correct |
46 ms |
5632 KB |
Output is correct |
6 |
Correct |
367 ms |
25700 KB |
Output is correct |
7 |
Correct |
137 ms |
12408 KB |
Output is correct |
8 |
Correct |
711 ms |
46204 KB |
Output is correct |
9 |
Correct |
236 ms |
19704 KB |
Output is correct |
10 |
Correct |
944 ms |
62332 KB |
Output is correct |