Submission #724051

# Submission time Handle Problem Language Result Execution time Memory
724051 2023-04-14T16:16:58 Z stage Measures (CEOI22_measures) C++14
100 / 100
543 ms 44096 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

map<pair<int,int>,int> to;

struct node{
	int max,min,ans;
};

const int N = 2e5, inf = 1e17;

node segt[4*N+5];
int lazy[4*N+5];

node merge(node a, node b){
	node c;
	c.ans = max({a.ans,b.ans,a.max-b.min});
	c.max = max(a.max,b.max);
	c.min = min(a.min,b.min);
	return c;
}

void update(int idx, int l, int r, int L, int R, int val){
	if (l > R or r < L) return;
	if (l >= L and r <= R){
		if (L == R) segt[idx] = {val+lazy[idx],val+lazy[idx],0};
		else{
			segt[idx].max += val;
			segt[idx].min += val;
			lazy[idx] += val;
		}
		return;
	}
	for (int k:{2*idx,2*idx+1}){
		segt[k].min += lazy[idx];
		segt[k].max += lazy[idx];
		lazy[k] += lazy[idx];
	}
	lazy[idx] = 0;
	int mid = (l+r)/2;
	update(2*idx,l,mid,L,R,val);
	update(2*idx+1,mid+1,r,L,R,val);
	segt[idx] = merge(segt[2*idx],segt[2*idx+1]);
}

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,d;
	cin >> n >> m >> d;
	fill_n(segt,4*N+5,node{-inf,inf,-inf});
	vector<int> init;
	vector<pair<int,int>> a(n+m);
	for (int i=0; i<n; ++i){
		int pos;
		cin >> pos;
		a[i] = {pos,i};
		init.emplace_back(pos);
	}
	vector<int> req;
	for (int k=0; k<m; ++k){
		int pos;
		cin >> pos;
		a[n+k] = {pos,n+k};
		req.emplace_back(pos);
	}
	sort(a.begin(),a.end());
	for (int i=0; i<n+m; ++i) to[a[i]] = i;
	for (int i=0; i<n; ++i){
		int pos = to[make_pair(init[i],i)];
		update(1,0,n+m+4,pos,pos,init[i]);
		update(1,0,n+m+4,pos+1,n+m+4,-d);
	}
	for (int i=0; i<m; ++i){
		int pos = to[make_pair(req[i],i+n)];
		update(1,0,n+m+4,pos,pos,req[i]);
		update(1,0,n+m+4,pos+1,n+m+4,-d);
		int ans = segt[1].ans;
		cout << ans/2;
		if (ans&1) cout << ".5";
		cout << ' ';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19284 KB Output is correct
2 Correct 9 ms 19284 KB Output is correct
3 Correct 9 ms 19284 KB Output is correct
4 Correct 10 ms 19284 KB Output is correct
5 Correct 9 ms 19264 KB Output is correct
6 Correct 10 ms 19284 KB Output is correct
7 Correct 10 ms 19284 KB Output is correct
8 Correct 10 ms 19284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19284 KB Output is correct
2 Correct 9 ms 19284 KB Output is correct
3 Correct 9 ms 19284 KB Output is correct
4 Correct 10 ms 19284 KB Output is correct
5 Correct 9 ms 19264 KB Output is correct
6 Correct 10 ms 19284 KB Output is correct
7 Correct 10 ms 19284 KB Output is correct
8 Correct 10 ms 19284 KB Output is correct
9 Correct 491 ms 40640 KB Output is correct
10 Correct 455 ms 40592 KB Output is correct
11 Correct 273 ms 40664 KB Output is correct
12 Correct 290 ms 40644 KB Output is correct
13 Correct 253 ms 40620 KB Output is correct
14 Correct 261 ms 40708 KB Output is correct
15 Correct 473 ms 40616 KB Output is correct
16 Correct 263 ms 40680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 279 ms 41764 KB Output is correct
2 Correct 288 ms 43568 KB Output is correct
3 Correct 299 ms 43728 KB Output is correct
4 Correct 279 ms 41416 KB Output is correct
5 Correct 325 ms 42692 KB Output is correct
6 Correct 279 ms 41820 KB Output is correct
7 Correct 318 ms 42840 KB Output is correct
8 Correct 279 ms 41540 KB Output is correct
9 Correct 285 ms 41540 KB Output is correct
10 Correct 280 ms 43856 KB Output is correct
11 Correct 301 ms 42312 KB Output is correct
12 Correct 325 ms 43288 KB Output is correct
13 Correct 288 ms 41456 KB Output is correct
14 Correct 289 ms 43368 KB Output is correct
15 Correct 286 ms 43328 KB Output is correct
16 Correct 290 ms 41432 KB Output is correct
17 Correct 311 ms 42764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 279 ms 41764 KB Output is correct
2 Correct 288 ms 43568 KB Output is correct
3 Correct 299 ms 43728 KB Output is correct
4 Correct 279 ms 41416 KB Output is correct
5 Correct 325 ms 42692 KB Output is correct
6 Correct 279 ms 41820 KB Output is correct
7 Correct 318 ms 42840 KB Output is correct
8 Correct 279 ms 41540 KB Output is correct
9 Correct 285 ms 41540 KB Output is correct
10 Correct 280 ms 43856 KB Output is correct
11 Correct 301 ms 42312 KB Output is correct
12 Correct 325 ms 43288 KB Output is correct
13 Correct 288 ms 41456 KB Output is correct
14 Correct 289 ms 43368 KB Output is correct
15 Correct 286 ms 43328 KB Output is correct
16 Correct 290 ms 41432 KB Output is correct
17 Correct 311 ms 42764 KB Output is correct
18 Correct 543 ms 41892 KB Output is correct
19 Correct 540 ms 43540 KB Output is correct
20 Correct 369 ms 43592 KB Output is correct
21 Correct 324 ms 41672 KB Output is correct
22 Correct 392 ms 42240 KB Output is correct
23 Correct 287 ms 41912 KB Output is correct
24 Correct 491 ms 42476 KB Output is correct
25 Correct 276 ms 41592 KB Output is correct
26 Correct 473 ms 41604 KB Output is correct
27 Correct 494 ms 44096 KB Output is correct
28 Correct 386 ms 42036 KB Output is correct
29 Correct 453 ms 43364 KB Output is correct
30 Correct 315 ms 41588 KB Output is correct
31 Correct 296 ms 43476 KB Output is correct
32 Correct 287 ms 43400 KB Output is correct
33 Correct 500 ms 41556 KB Output is correct
34 Correct 310 ms 42912 KB Output is correct