# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
894382 |
2023-12-28T08:01:37 Z |
vjudge1 |
NLO (COCI18_nlo) |
C++17 |
|
2692 ms |
6740 KB |
#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"
const ld PI = 3.1415926535;
const int N = 1e5 + 2;
const int M = 7e6 + 1;
int mod = 1e9+7;
const int infi = INT_MAX;
const ll infl = LLONG_MAX;
const int P = 31;
int mult(int a, int b) {
return a * 1LL * b % mod;
}
int sum(int a, int b) {
a %= mod;
if (a + b < 0)
return a + b + mod;
if (a + b >= mod)
return a + b - mod;
return a + b;
}
ll binpow(ll a, ll n) {
if (n == 0)
return 1;
if (n % 2 == 1) {
return binpow(a, n - 1) * a % mod;
} else {
ll b = binpow(a, n / 2);
return b * b % mod;
}
}
struct kazakhskayazadachapizdec{
int lz[4 * N], sm[4 * N];
void init(int n){
for(int i = 0; i < 4 * N; i++)
lz[i] = -1;
build(1, 1, n);
}
void build(int v, int tl, int tr){
if(tl == tr){
sm[v] = 1;
}else{
int tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm + 1, tr);
sm[v] = sm[2 * v] + sm[2 * v + 1];
}
}
void push(int v, int tl, int tr){
if(tl == tr || lz[v] == -1)
return;
int tm = (tl + tr) / 2;
lz[2 * v] = lz[v];
lz[2 * v + 1] = lz[v];
sm[2 * v] = (lz[v] * (tm - tl + 1));
sm[2 * v + 1] = (lz[v] * (tr - tm));
lz[v] = -1;
}
int get(int v, int tl, int tr, int l, int r){
push(v, tl, tr);
if(tl > r || l > tr)
return 0;
if(l <= tl && tr <= r)
return sm[v];
int tm = (tl + tr) / 2;
return get(2 * v, tl, tm, l, r) + get(2 * v + 1, tm + 1, tr, l, r);
}
void sett(int v, int tl, int tr, int l, int r, int x){
push(v, tl, tr);
if(tl > r || l > tr)
return;
if(l <= tl && tr <= r){
sm[v] = x * (tr - tl + 1);
lz[v] = x;
}else{
int tm = (tl + tr) / 2;
sett(2 * v, tl, tm, l, r, x);
sett(2 * v + 1, tm + 1, tr, l, r, x);
sm[v] = sm[2 * v] + sm[2 * v + 1];
}
}
};
void solve(){
int n, m;
cin >> n >> m;
kazakhskayazadachapizdec ts;
ts.init(n);
int q;
cin >> q;
pair<pii, int> qs[q];
for(int i = 0; i < q; i++){
int xi, yi, ri;
cin >> yi >> xi >> ri;
qs[i] = {{yi, xi}, ri};
}
int ans = 0;
for(int x = 1; x <= m; x++){
vector<pair<int, pii>> v = {{0, {1, n}}};
for(int i = 0; i < q; i++){
int yi = qs[i].F.F, xi = qs[i].F.S, ri = qs[i].S;
if(abs(x - xi) <= ri){
ld b = -2 * yi, c = yi * yi - ri * ri + (xi - x) * (xi - x);
if(b * b - 4 * c < 0)
continue;
int y1 = max((int)(ceil((-b - sqrtl(b * b - 4 * c)) / 2.0)), 1LL);
int y2 = min((int)(floor((-b + sqrtl(b * b - 4 * c)) / 2.0)), n);
v.pb({i + 1, {y1, y2}});
}
}
sort(all(v));
reverse(all(v));
for(auto e : v){
ans += (ts.get(1, 1, n, e.S.F, e.S.S) * (q - e.F));
ts.sett(1, 1, n, e.S.F, e.S.S, 0);
}
ts.sett(1, 1, n, 1, n, 1);
}
cout << ans << '\n';
}
signed main() {
mispertion;
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
6492 KB |
Output is correct |
2 |
Correct |
25 ms |
6720 KB |
Output is correct |
3 |
Correct |
19 ms |
6492 KB |
Output is correct |
4 |
Correct |
119 ms |
6492 KB |
Output is correct |
5 |
Correct |
128 ms |
6696 KB |
Output is correct |
6 |
Correct |
966 ms |
6696 KB |
Output is correct |
7 |
Correct |
388 ms |
6692 KB |
Output is correct |
8 |
Correct |
1895 ms |
6700 KB |
Output is correct |
9 |
Correct |
760 ms |
6700 KB |
Output is correct |
10 |
Correct |
2692 ms |
6740 KB |
Output is correct |