Submission #653277

#TimeUsernameProblemLanguageResultExecution timeMemory
653277AntekbMeasures (CEOI22_measures)C++14
100 / 100
271 ms22308 KiB
#include<bits/stdc++.h>
 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
 
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
 
using namespace std;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~~
 
template <typename H, typename T> 
ostream& operator<<(ostream& os, pair<H, T> m){
	return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H> 
ostream& operator<<(ostream& os, vector<H> V){
	os<<"{";
	for(int i=0; i<V.size(); i++){
		if(i)os<<" ";
		os<<V[i];
	}
	os<<"}";
	return os;
}
 
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
 
///~~~~~~~~~~~~~~~~~~~~~~~~~
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;
 
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const int N=1<<18, INF=1e9+5, mod=1e9+7;
int d;
int tab[N+N], co[N];
ll sum[N+N], pre[N+N], suf[N+N], ans[N+N];
int lew(int i){
	i+=N;
	while(i>0){
		if((i&1) && tab[i-1]){
			i--;
			while(i<N){
				if(tab[i+i+1])i=i+i+1;
				else i=i+i;
			}
			return i-N;
		}
		i/=2;
	}
	return -1;
}
int pra(int i){
	i+=N;
	while(i>0){
		if(!(i&1) && tab[i+1]){
			i++;
			while(i<N){
				if(tab[i+i])i=i+i;
				else i=i+i+1;
			}
			return i-N;
		}
		i/=2;
	}
	return -1;
}
void ust(int i, int val){
	val=d-val;
	//deb(i, val);
	//cout<<i<<" "<<val<<"\n";
	for(i+=N, pre[i]=suf[i]=ans[i]=max(val, 0), sum[i]=val, i/=2; i>0; i>>=1){
		pre[i]=max(pre[i+i], pre[i+i+1]+sum[i+i]);
		suf[i]=max(suf[i+i+1], suf[i+i]+sum[i+i+1]);
		sum[i]=sum[i+i+1]+sum[i+i];
		ans[i]=max(ans[i+i], ans[i+i+1]);
		ans[i]=max(ans[i], pre[i+i+1]+suf[i+i]);
	}
}
void dodaj(int i){
	int a=lew(i), b=pra(i);
	//deb(i, a, b);
	if(a!=-1){
		ust(a, (co[i]-co[a]));
	}
	if(b!=-1){
		ust(i, (co[b]-co[i]));
	}
	i+=N;
	while(i>0)tab[i]=1, i/=2;
}
int main(){
	//BOOST;
	int n, m;
	cin>>n>>m>>d;
	vector<pair<int, int> > V;
	for(int i=0; i<n; i++){
		int x;
		cin>>x;
		V.pb(mp(x, -1));
	}
	for(int i=0; i<m; i++){
		int x;
		cin>>x;
		V.pb(mp(x, i));
	}
	sor(V);
	vector<int> gdzie(m);
	for(int i=0; i<n+m; i++){
		co[i]=V[i].st;
		if(V[i].nd!=-1)gdzie[V[i].nd]=i;
		else dodaj(i);
	}
	for(int i:gdzie){
		dodaj(i);
		cout<<ans[1]/2;
		if(ans[1]&1)cout<<".5";
		cout<<"\n";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...