Submission #903964

# Submission time Handle Problem Language Result Execution time Memory
903964 2024-01-11T15:44:31 Z Hakiers Measures (CEOI22_measures) C++17
0 / 100
228 ms 36304 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
struct node{
	ll pref, suf, inf, sum;
};
constexpr int BASE = 1<<18;
constexpr ll oo = 1e16;
node TREE[BASE<<1];
pair<ll, int> Queries[BASE];
int who[BASE];
vector<pair<int, int>> event;
set<int> S;
int n, m, D;

void update(int v, ll val){
	v+=BASE;
	TREE[v].pref = TREE[v].suf = TREE[v].inf = TREE[v].sum = val;
	v/=2;
	
	while(v>0){
		int l = 2*v, r = 2*v+1;
		TREE[v].pref = max(TREE[l].pref, TREE[l].sum+TREE[r].pref);
		TREE[v].suf = max(TREE[r].suf, TREE[l].suf+TREE[r].sum);
		TREE[v].sum = TREE[l].sum + TREE[r].sum;
		TREE[v].inf = max({TREE[l].inf, TREE[r].inf, TREE[l].suf+TREE[r].pref});
		v/=2;
	}
}

void compute(){
	sort(event.begin(), event.end());
	int pos = 0;
	for(auto [a, i] : event){
		Queries[i] = {a, ++pos};
		who[pos] = i;
	}
	who[BASE-1] = BASE-1;
	Queries[BASE-1] = {oo, BASE-1};
	S.insert((BASE-1));
}

void add(pair<ll, int> x){
	auto it = S.lower_bound(x.second);
	update(x.second, x.first - Queries[who[*it]].first + D);
	
	if(it != S.begin()){
		it--;
		update(Queries[who[*it]].second, Queries[who[*it]].first - x.first + D);
	}
	S.insert(x.second);
}

ld quer(){
	ld out = 0;
	out = max({TREE[1].pref, TREE[1].suf, TREE[1].inf, TREE[1].sum});
	
	return out/(ld)2;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> D;
	for(int i = 1; i <= n+m; i++){
		int a;
		cin >> a;
		event.push_back({a, i});
	}
	compute();
	
	for(int i = 1; i <= n; i++)
		add(Queries[i]);
	
	for(int i = n+1; i <= n+m; i++){
		add(Queries[i]);
		cout << quer() << " ";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10848 KB Output is correct
2 Incorrect 2 ms 10844 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10848 KB Output is correct
2 Incorrect 2 ms 10844 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 197 ms 34908 KB Output is correct
2 Incorrect 228 ms 36304 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 197 ms 34908 KB Output is correct
2 Incorrect 228 ms 36304 KB Output isn't correct
3 Halted 0 ms 0 KB -