Submission #691490

# Submission time Handle Problem Language Result Execution time Memory
691490 2023-01-31T07:50:55 Z Sohsoh84 Measures (CEOI22_measures) C++17
100 / 100
431 ms 83604 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 4e6 + 10;
const ll INF = 1e18;
const pll SG_D = {INF, -INF};

ll n, m, d, ans, lz[MAXN];
pll sg[MAXN];
vector<pll> X, Q;

namespace fenwick {
	int fen[MAXN];

	inline void update(int ind, int val) {
		for (++ind; ind < MAXN; ind += ind & -ind)
			fen[ind] += val;
	}

	inline int query(int ind) {
		int ans = 1;
		for (++ind; ind > 0; ind -= ind & -ind)
			ans += fen[ind];

		return ans;
	}
}

inline pll merge(pll a, pll b) {
	return pll(min(a.X, b.X), max(a.Y, b.Y));
}

inline void push(ll v) {
	sg[v].X += lz[v];
	sg[v].Y += lz[v];

	if ((v << 1 | 1) < MAXN) {
		lz[v << 1] += lz[v];
		lz[v << 1 | 1] += lz[v];
	}

	lz[v] = 0;
}

void point_set(int ind, ll val, int l = 1, int r = n, int v = 1) {
	push(v);
	if (l == r) sg[v] = {val, val};
	else {
		int mid = (l + r) >> 1;
		if (ind <= mid) point_set(ind, val, l, mid, v << 1), push(v << 1 | 1);
		else point_set(ind, val, mid + 1, r, v << 1 | 1), push(v << 1);

		sg[v] = merge(sg[v << 1], sg[v << 1 | 1]);
	}
}

void update(int ql, int qr, ll val, int l = 1, int r = n, int v = 1) {
	push(v);
	if (ql > r || qr < l) return;
	if (ql <= l && qr >= r) {
		lz[v] += val;
		push(v);
		return;
	}

	int mid = (l + r) >> 1;
	update(ql, qr, val, l, mid, v << 1);
	update(ql, qr, val, mid + 1, r, v << 1 | 1);
	sg[v] = merge(sg[v << 1], sg[v << 1 | 1]);
}

pll query(int ql, int qr, int l = 1, int r = n, int v = 1) {
	push(v);
	if (ql > r || qr < l) return SG_D;
	if (ql <= l && qr >= r) return sg[v];

	int mid = (l + r) >> 1;
	return merge(query(ql, qr, l, mid, v << 1),
			query(ql, qr, mid + 1, r, v << 1 | 1));
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m >> d;
	n += m;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		X.push_back({x, i});
		Q.push_back({i, x});
	}

	fill(sg, sg + MAXN, SG_D);

	sort(all(X));
	for (pll e : Q) {
		auto [i, x] = e;
		auto ind = lower_bound(all(X), pll(x, i)) - X.begin() + 1;

		int f_ind = fenwick::query(ind);
		fenwick::update(ind, 1);

		ll f = d * f_ind - x;

		point_set(ind, f);
		if (ind < n) update(ind + 1, n, d);
		ans = max(ans, query(ind, n).Y - query(1, ind).X);
		
		if (i > n - m) {
			cout << ans / 2;
			if (ans % 2) cout << ".5";
			cout << endl;
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 27 ms 63092 KB Output is correct
2 Correct 26 ms 63060 KB Output is correct
3 Correct 28 ms 63168 KB Output is correct
4 Correct 27 ms 63104 KB Output is correct
5 Correct 31 ms 63064 KB Output is correct
6 Correct 30 ms 63196 KB Output is correct
7 Correct 27 ms 63068 KB Output is correct
8 Correct 27 ms 63060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 63092 KB Output is correct
2 Correct 26 ms 63060 KB Output is correct
3 Correct 28 ms 63168 KB Output is correct
4 Correct 27 ms 63104 KB Output is correct
5 Correct 31 ms 63064 KB Output is correct
6 Correct 30 ms 63196 KB Output is correct
7 Correct 27 ms 63068 KB Output is correct
8 Correct 27 ms 63060 KB Output is correct
9 Correct 337 ms 80392 KB Output is correct
10 Correct 336 ms 80336 KB Output is correct
11 Correct 252 ms 80368 KB Output is correct
12 Correct 264 ms 80276 KB Output is correct
13 Correct 239 ms 79904 KB Output is correct
14 Correct 259 ms 80300 KB Output is correct
15 Correct 343 ms 79712 KB Output is correct
16 Correct 238 ms 80384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 256 ms 79644 KB Output is correct
2 Correct 263 ms 83280 KB Output is correct
3 Correct 266 ms 83256 KB Output is correct
4 Correct 242 ms 81152 KB Output is correct
5 Correct 259 ms 82412 KB Output is correct
6 Correct 269 ms 81552 KB Output is correct
7 Correct 272 ms 82480 KB Output is correct
8 Correct 272 ms 81256 KB Output is correct
9 Correct 250 ms 81116 KB Output is correct
10 Correct 256 ms 83516 KB Output is correct
11 Correct 255 ms 81972 KB Output is correct
12 Correct 253 ms 82912 KB Output is correct
13 Correct 264 ms 81252 KB Output is correct
14 Correct 248 ms 83140 KB Output is correct
15 Correct 279 ms 82868 KB Output is correct
16 Correct 296 ms 80788 KB Output is correct
17 Correct 257 ms 82660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 256 ms 79644 KB Output is correct
2 Correct 263 ms 83280 KB Output is correct
3 Correct 266 ms 83256 KB Output is correct
4 Correct 242 ms 81152 KB Output is correct
5 Correct 259 ms 82412 KB Output is correct
6 Correct 269 ms 81552 KB Output is correct
7 Correct 272 ms 82480 KB Output is correct
8 Correct 272 ms 81256 KB Output is correct
9 Correct 250 ms 81116 KB Output is correct
10 Correct 256 ms 83516 KB Output is correct
11 Correct 255 ms 81972 KB Output is correct
12 Correct 253 ms 82912 KB Output is correct
13 Correct 264 ms 81252 KB Output is correct
14 Correct 248 ms 83140 KB Output is correct
15 Correct 279 ms 82868 KB Output is correct
16 Correct 296 ms 80788 KB Output is correct
17 Correct 257 ms 82660 KB Output is correct
18 Correct 373 ms 81576 KB Output is correct
19 Correct 419 ms 83284 KB Output is correct
20 Correct 265 ms 83276 KB Output is correct
21 Correct 294 ms 81240 KB Output is correct
22 Correct 312 ms 81616 KB Output is correct
23 Correct 273 ms 81536 KB Output is correct
24 Correct 351 ms 81928 KB Output is correct
25 Correct 253 ms 81156 KB Output is correct
26 Correct 349 ms 81060 KB Output is correct
27 Correct 431 ms 83604 KB Output is correct
28 Correct 328 ms 81480 KB Output is correct
29 Correct 385 ms 83032 KB Output is correct
30 Correct 301 ms 81180 KB Output is correct
31 Correct 326 ms 83148 KB Output is correct
32 Correct 267 ms 82932 KB Output is correct
33 Correct 362 ms 80740 KB Output is correct
34 Correct 304 ms 82468 KB Output is correct