Submission #653277

# Submission time Handle Problem Language Result Execution time Memory
653277 2022-10-26T11:02:56 Z Antekb Measures (CEOI22_measures) C++14
100 / 100
271 ms 22308 KB
#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 time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 3 ms 732 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 708 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 3 ms 732 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 708 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 704 KB Output is correct
9 Correct 144 ms 18540 KB Output is correct
10 Correct 148 ms 18588 KB Output is correct
11 Correct 144 ms 17948 KB Output is correct
12 Correct 150 ms 18232 KB Output is correct
13 Correct 129 ms 17832 KB Output is correct
14 Correct 138 ms 17940 KB Output is correct
15 Correct 132 ms 17924 KB Output is correct
16 Correct 131 ms 17720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 19900 KB Output is correct
2 Correct 160 ms 22052 KB Output is correct
3 Correct 161 ms 21588 KB Output is correct
4 Correct 166 ms 19132 KB Output is correct
5 Correct 158 ms 21176 KB Output is correct
6 Correct 155 ms 20080 KB Output is correct
7 Correct 159 ms 21296 KB Output is correct
8 Correct 166 ms 20336 KB Output is correct
9 Correct 159 ms 19712 KB Output is correct
10 Correct 160 ms 22100 KB Output is correct
11 Correct 156 ms 20372 KB Output is correct
12 Correct 155 ms 21464 KB Output is correct
13 Correct 162 ms 19536 KB Output is correct
14 Correct 158 ms 21904 KB Output is correct
15 Correct 162 ms 21312 KB Output is correct
16 Correct 146 ms 19632 KB Output is correct
17 Correct 157 ms 21048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 19900 KB Output is correct
2 Correct 160 ms 22052 KB Output is correct
3 Correct 161 ms 21588 KB Output is correct
4 Correct 166 ms 19132 KB Output is correct
5 Correct 158 ms 21176 KB Output is correct
6 Correct 155 ms 20080 KB Output is correct
7 Correct 159 ms 21296 KB Output is correct
8 Correct 166 ms 20336 KB Output is correct
9 Correct 159 ms 19712 KB Output is correct
10 Correct 160 ms 22100 KB Output is correct
11 Correct 156 ms 20372 KB Output is correct
12 Correct 155 ms 21464 KB Output is correct
13 Correct 162 ms 19536 KB Output is correct
14 Correct 158 ms 21904 KB Output is correct
15 Correct 162 ms 21312 KB Output is correct
16 Correct 146 ms 19632 KB Output is correct
17 Correct 157 ms 21048 KB Output is correct
18 Correct 258 ms 20520 KB Output is correct
19 Correct 266 ms 21760 KB Output is correct
20 Correct 164 ms 22308 KB Output is correct
21 Correct 216 ms 20044 KB Output is correct
22 Correct 201 ms 20536 KB Output is correct
23 Correct 207 ms 20440 KB Output is correct
24 Correct 261 ms 20616 KB Output is correct
25 Correct 153 ms 20192 KB Output is correct
26 Correct 271 ms 19992 KB Output is correct
27 Correct 271 ms 21752 KB Output is correct
28 Correct 227 ms 20604 KB Output is correct
29 Correct 234 ms 20376 KB Output is correct
30 Correct 201 ms 19368 KB Output is correct
31 Correct 205 ms 21780 KB Output is correct
32 Correct 213 ms 20880 KB Output is correct
33 Correct 248 ms 18600 KB Output is correct
34 Correct 206 ms 20836 KB Output is correct