제출 #1122235

#제출 시각아이디문제언어결과실행 시간메모리
1122235IcelastMeasures (CEOI22_measures)C++17
0 / 100
945 ms40520 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; void sub1(ll n, ll m, ll d){ vector<ll> a(n+1); for(int i = 1; i <= n; i++){ cin >> a[i]; } auto check = [&](ll x) -> bool{ long double y = x; vector<long double> cur(a.size(), 0); cur[0] = -1e15; for(int i = 1; i < (int)a.size(); i++){ long double diff = cur[i-1]+d-a[i]; if(diff < 0){ cur[i] = (long double)a[i]-min(fabs(diff), y/2); }else{ if(y/2 < diff) return false; cur[i] = (long double)a[i]+diff; } } return true; }; for(int i = 1; i <= m; i++){ ll x; cin >> x; a.push_back(x); sort(a.begin()+1, a.end()); ll l = 0, r = 1e12, mid; while(l <= r){ mid = (l+r)/2; if(check(mid)){ r = mid-1; }else{ l = mid+1; } } cout << ((long double)l/2) << " "; } } void sub3(ll n, ll m, ll d){ vector<ll> a(n+1); for(int i = 1; i <= n; i++){ cin >> a[i]; } ll mx = 0, mnv = INF; for(int i = 1; i <= n; i++){ mx = max(mx, d*i-a[i] - mnv); mnv = min(mnv, d*i-a[i]); } for(int i = 1; i <= m; i++){ ll x; cin >> x; n++; mx = max(mx, d*n-x - mnv); mnv = min(mnv, d*n-x); cout << (long double)mx/2 << " "; } } struct normalize{ vector<ll> poi, pot; void add(ll x){ poi.push_back(x); } void start(){ sort(poi.begin(), poi.end()); if(poi.size() > 0) pot.push_back(poi[0]); for(int i = 1; i < (int)poi.size(); i++){ if(poi[i] != poi[i-1]){ pot.push_back(poi[i]); } } } int encode(ll x){ return lower_bound(pot.begin(), pot.end(), x) - pot.begin()+1; } }; template<class Info, class Tag> struct LazySegmentTree { int n; vector<Info> info; vector<Tag> tag; LazySegmentTree() : n(0) {} LazySegmentTree(int n_, Info v_ = Info()) { init(n_, v_); } template<class T> LazySegmentTree(vector<T> init_) { init(init_); } void init(int n_, Info v_ = Info()) { init(vector<Info>(n_, v_)); } template<class T> void init(vector<T> init_) { n = init_.size(); info.assign(4 << __lg(n), Info()); tag.assign(4 << __lg(n), Tag()); function<void(int, int, int)> build = [&](int p, int l, int r) { if (r - l == 1) { info[p] = init_[l]; return; } int m = (l + r) / 2; build(2 * p, l, m); build(2 * p + 1, m, r); pull(p); }; build(1, 0, n); } void pull(int p) { info[p] = info[2 * p] + info[2 * p + 1]; } void apply(int p, const Tag &v) { info[p].apply(v); tag[p].apply(v); } void push(int p) { apply(2 * p, tag[p]); apply(2 * p + 1, tag[p]); tag[p] = Tag(); } void modify(int p, int l, int r, int x, const Info &v) { if (r - l == 1) { info[p] = v; return; } int m = (l + r) / 2; push(p); if (x < m) { modify(2 * p, l, m, x, v); } else { modify(2 * p + 1, m, r, x, v); } pull(p); } void modify(int p, const Info &v) { modify(1, 0, n, p, v); } Info rangeQuery(int p, int l, int r, int x, int y) { if (l >= y || r <= x) { return Info(); } if (l >= x && r <= y) { return info[p]; } int m = (l + r) / 2; push(p); return rangeQuery(2 * p, l, m, x, y) + rangeQuery(2 * p + 1, m, r, x, y); } Info rangeQuery(int l, int r) { return rangeQuery(1, 0, n, l, r); } void rangeApply(int p, int l, int r, int x, int y, const Tag &v) { if (l >= y || r <= x) { return; } if (l >= x && r <= y) { apply(p, v); return; } int m = (l + r) / 2; push(p); rangeApply(2 * p, l, m, x, y, v); rangeApply(2 * p + 1, m, r, x, y, v); pull(p); } void rangeApply(int l, int r, const Tag &v) { return rangeApply(1, 0, n, l, r, v); } template<class F> int findFirst(int p, int l, int r, int x, int y, F &&pred) { if (l >= y || r <= x) { return -1; } if (l >= x && r <= y && !pred(info[p])) { return -1; } if (r - l == 1) { return l; } int m = (l + r) / 2; push(p); int res = findFirst(2 * p, l, m, x, y, pred); if (res == -1) { res = findFirst(2 * p + 1, m, r, x, y, pred); } return res; } template<class F> int findFirst(int l, int r, F &&pred) { return findFirst(1, 0, n, l, r, pred); } template<class F> int findLast(int p, int l, int r, int x, int y, F &&pred) { if (l >= y || r <= x) { return -1; } if (l >= x && r <= y && !pred(info[p])) { return -1; } if (r - l == 1) { return l; } int m = (l + r) / 2; push(p); int res = findLast(2 * p + 1, m, r, x, y, pred); if (res == -1) { res = findLast(2 * p, l, m, x, y, pred); } return res; } template<class F> int findLast(int l, int r, F &&pred) { return findLast(1, 0, n, l, r, pred); } }; struct Tag { ll add = 0, alive = 0, smn = INF, smx = -INF; void apply(const Tag &t) & { add += t.add; alive += t.alive; smn = min(smn, t.smn); smx = max(smx, t.smx); } }; struct Info { ll cnt = 0, mn = INF, mx = -INF; void apply(const Tag &t) & { mn += t.add; mx += t.add; cnt += t.alive; mn = min(mn, t.smn); mx = max(mx, t.smx); } Info operator+(const Info &b) { return {cnt + b.cnt, min(mn, b.mn), max(mx, b.mx)}; } }; void subfull(ll n, ll m, ll d){ vector<ll> a(n+1); normalize norm; for(int i = 1; i <= n; i++){ cin >> a[i]; norm.add(a[i]); } vector<ll> q(m+1); for(int i = 1; i <= m; i++){ cin >> q[i]; norm.add(q[i]); } norm.start(); ll ans = 0; int N = norm.pot.size(); LazySegmentTree<Info, Tag> T(N+5); for(int i = 1; i <= n; i++){ ll cur = d*(T.rangeQuery(1, norm.encode(a[i])+1).cnt+1)-a[i]; ans = max(ans, cur - T.rangeQuery(1, norm.encode(a[i])+1).mn); T.rangeApply(norm.encode(a[i])+1, N+1, {d, 0, INF, -INF}); ans = max(ans, T.rangeQuery(norm.encode(a[i])+1, N+1).mx - cur); ans = max(ans, T.rangeQuery(norm.encode(a[i])+1, N+1).mx - T.rangeQuery(1, norm.encode(a[i])+1).mn); T.rangeApply(norm.encode(a[i]), norm.encode(a[i])+1, {0, 1, cur, cur}); } for(int i = 1; i <= m; i++){ ll cur = d*(T.rangeQuery(1, norm.encode(q[i])+1).cnt+1)-q[i]; ans = max(ans, cur - T.rangeQuery(1, norm.encode(q[i])+1).mn); T.rangeApply(norm.encode(q[i])+1, N+1, {d, 0, INF, -INF}); ans = max(ans, T.rangeQuery(norm.encode(q[i])+1, N+1).mx - cur); ans = max(ans, T.rangeQuery(norm.encode(q[i])+1, N+1).mx - T.rangeQuery(1, norm.encode(q[i])+1).mn); T.rangeApply(norm.encode(q[i]), norm.encode(q[i])+1, {0, 1, cur, cur}); cout << (long double)ans/2 << " "; } } void solve(){ ll n, m, d; cin >> n >> m >> d; if(n <= 2e5 && m <= 10){ subfull(n, m, d); return; } subfull(n, m, d); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("APPLICATION.inp", "r", stdin); //freopen("APPLICATION.out", "w", stdout); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...