QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#439135 | #8768. Arrested Development | PetroTarnavskyi# | RE | 0ms | 0kb | C++20 | 2.3kb | 2024-06-11 16:42:52 | 2024-06-11 16:42:53 |
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const db SQRT2 = sqrt(2);
PII merge(const PII& a, const PII& b)
{
if (a.F != b.F)
return min(a, b);
return {a.F, a.S + b.S};
}
struct SegTree
{
int n;
vector<PII> t;
VI lazy;
void init(int _n)
{
n = 1;
while (n < _n)
n *= 2;
t.resize(2 * n - 1);
lazy.resize(2 * n - 1);
}
void build(int v, int tl, int tr, const VI& a)
{
if (tr - tl == 1)
{
t[v] = {0, a[tl + 1] - a[tl]};
return;
}
int tm = (tl + tr) / 2;
build(2 * v, tl, tm, a);
build(2 * v + 1, tm, tr, a);
t[v] = merge(t[2 * v], t[2 * v + 1]);
}
void push(int v, int tl, int tr)
{
if (tr - tl > 1)
{
lazy[2 * v] += lazy[v];
lazy[2 * v + 1] += lazy[v];
}
t[v].F += lazy[v];
lazy[v] = 0;
}
void upd(int v, int tl, int tr, int l, int r, int d)
{
push(v, tl, tr);
if (r <= tl || tr <= l)
return;
if (l <= tl && r <= tr)
{
lazy[v] = d;
push(v, tl, tr);
return;
}
int tm = (tl + tr) / 2;
upd(2 * v, tl, tm, l, r, d);
upd(2 * v + 1, tm, tr, l, r, d);
t[v] = merge(t[2 * v], t[2 * v + 1]);
}
} st;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int q, w;
cin >> q >> w;
vector<PII> points(q);
VI vec = {0, w};
for (auto& [x, y] : points)
{
cin >> x >> y;
int a = max(0, x - y), b = min(w, x + y);
vec.PB(a);
vec.PB(b);
}
sort(ALL(vec));
vec.erase(unique(ALL(vec)), vec.end());
st.init(SZ(vec) - 1);
st.build(0, 0, SZ(vec) - 1, vec);
map<PII, int> mp;
for (auto [x, y] : points)
{
mp[{x, y}] ^= 1;
int a = max(0, x - y), b = min(w, x + y);
int idxL = lower_bound(ALL(vec), a) - vec.begin();
int idxR = lower_bound(ALL(vec), b) - vec.begin();
int d = mp[{x, y}] == 1 ? 1 : -1;
st.upd(0, 0, SZ(vec) - 1, idxL, idxR, d);
auto [mn, cntMn] = st.t[0];
int ans = w;
if (mn == 0)
ans -= cntMn;
cout << SQRT2 * ans << "\n";
}
return 0;
}
详细
Test #1:
score: 0
Runtime Error
input:
4 100 1 1 90 1 20 1 20