답안 #903970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
903970 2024-01-11T15:48:01 Z Hakiers Measures (CEOI22_measures) C++17
0 / 100
226 ms 36864 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<ll, int>> event;
set<int> S;
ll 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++){
		ll 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() << " ";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Incorrect 2 ms 10844 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Incorrect 2 ms 10844 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 35220 KB Output is correct
2 Incorrect 226 ms 36864 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 35220 KB Output is correct
2 Incorrect 226 ms 36864 KB Output isn't correct
3 Halted 0 ms 0 KB -