Submission #1039551

# Submission time Handle Problem Language Result Execution time Memory
1039551 2024-07-31T04:25:45 Z pcc Measures (CEOI22_measures) C++17
100 / 100
343 ms 50628 KB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 2e14;
const ll mxn = 3e5+10;

struct node{
	ll mx,mn,tag;
	node(){
		mx = -inf,mn = inf<<1,tag = 0;
	}
};

struct SEG{
#define ls now*2+1
#define rs now*2+2
#define mid ((l+r)>>1)
	node seg[mxn*4];
	node pull(node tl,node tr){
		node re;
		re.mx = max(tl.mx+tl.tag,tr.mx+tr.tag);
		re.mn = min(tl.mn+tl.tag,tr.mn+tr.tag);
		return re;
	}
	void push(int now,int l,int r){
		seg[ls].tag += seg[now].tag;
		seg[rs].tag += seg[now].tag;
		seg[now].tag = 0;
		seg[now] = pull(seg[ls],seg[rs]);
		return;
	}
	void modify(int now,int l,int r,int s,int e,ll v){
		if(l>=s&&e>=r){
			seg[now].tag += v;
			return;
		}
		push(now,l,r);
		if(mid>=s)modify(ls,l,mid,s,e,v);
		if(mid<e)modify(rs,mid+1,r,s,e,v);
		seg[now] = pull(seg[ls],seg[rs]);
		return;
	}
	void setval(int now,int l,int r,int p,ll v){
		if(l == r){
			seg[now].mx = seg[now].mn = v;
			seg[now].tag = 0;
			return;
		}
		push(now,l,r);
		if(mid>=p)setval(ls,l,mid,p,v);
		else setval(rs,mid+1,r,p,v);
		seg[now] = pull(seg[ls],seg[rs]);
	}
	ll getmx(int now,int l,int r,int s,int e){
		if(l>=s&&e>=r){
			return seg[now].mx+seg[now].tag;
		}
		push(now,l,r);
		if(mid>=e)return getmx(ls,l,mid,s,e);
		else if(mid<s)return getmx(rs,mid+1,r,s,e);
		else return max(getmx(ls,l,mid,s,e),getmx(rs,mid+1,r,s,e));
	}
	ll getmn(int now,int l,int r,int s,int e){
		if(l>=s&&e>=r){
			return seg[now].mn+seg[now].tag;
		}
		push(now,l,r);
		if(mid>=e)return getmn(ls,l,mid,s,e);
		else if(mid<s)return getmn(rs,mid+1,r,s,e);
		else return min(getmn(ls,l,mid,s,e),getmn(rs,mid+1,r,s,e));
	}
	SEG(){}
#undef ls
#undef rs
#undef mid
};

SEG seg;
ordered_set<int> st;
vector<ll> all;
int ids[mxn];
ll N,M,D;
ll ans;
ll arr[mxn];
ll req[mxn];

ll bis(ll x,ll y){
	ll l = ans,r = 3e15;
	while(l != r){
		ll mid = (l+r)>>1;
		if(x<=y+mid*2)r = mid;
		else l = mid+1;
	}
	return l;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	memset(ids,-1,sizeof(ids));
	cin>>N>>M>>D;
	D<<=1;
	for(int i = 0;i<N+M;i++){
		cin>>arr[i];
		arr[i]<<=1;
		all.push_back(arr[i]);
	}

	{
		sort(all.begin(),all.end());
		for(int i = 0;i<N+M;i++){
			auto pos = lower_bound(all.begin(),all.end(),arr[i])-all.begin();
			if(ids[pos] == -1)arr[i] = ids[pos] = pos;
			else arr[i] = ids[pos];
			ids[pos]++;
		}
	}

	for(int i = 0;i<N+M;i++){
		int pos = arr[i];
		seg.modify(0,0,N+M,pos,N+M,-D);
		ll sh = st.order_of_key(pos);
		seg.setval(0,0,N+M,pos,all[pos]-D*sh);
		ll x = seg.getmx(0,0,N+M,0,pos);
		ll y = seg.getmn(0,0,N+M,pos,N+M);
		ans = bis(x,y);
		req[i] = ans;
		st.insert(pos);
	}
	for(int i = N;i<N+M;i++)cout<<(req[i]>>1)<<(req[i]&1?".5 ":" ");
	cout<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 32348 KB Output is correct
2 Correct 6 ms 32224 KB Output is correct
3 Correct 6 ms 32344 KB Output is correct
4 Correct 6 ms 32300 KB Output is correct
5 Correct 6 ms 32348 KB Output is correct
6 Correct 6 ms 32348 KB Output is correct
7 Correct 6 ms 32344 KB Output is correct
8 Correct 6 ms 32344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 32348 KB Output is correct
2 Correct 6 ms 32224 KB Output is correct
3 Correct 6 ms 32344 KB Output is correct
4 Correct 6 ms 32300 KB Output is correct
5 Correct 6 ms 32348 KB Output is correct
6 Correct 6 ms 32348 KB Output is correct
7 Correct 6 ms 32344 KB Output is correct
8 Correct 6 ms 32344 KB Output is correct
9 Correct 343 ms 47256 KB Output is correct
10 Correct 306 ms 47348 KB Output is correct
11 Correct 260 ms 47412 KB Output is correct
12 Correct 250 ms 47176 KB Output is correct
13 Correct 243 ms 46792 KB Output is correct
14 Correct 255 ms 47300 KB Output is correct
15 Correct 316 ms 46532 KB Output is correct
16 Correct 274 ms 47300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 265 ms 48416 KB Output is correct
2 Correct 278 ms 50292 KB Output is correct
3 Correct 240 ms 50236 KB Output is correct
4 Correct 265 ms 47944 KB Output is correct
5 Correct 272 ms 49348 KB Output is correct
6 Correct 254 ms 48392 KB Output is correct
7 Correct 269 ms 49348 KB Output is correct
8 Correct 267 ms 48192 KB Output is correct
9 Correct 271 ms 47944 KB Output is correct
10 Correct 273 ms 50380 KB Output is correct
11 Correct 264 ms 48972 KB Output is correct
12 Correct 278 ms 49752 KB Output is correct
13 Correct 265 ms 47956 KB Output is correct
14 Correct 281 ms 50116 KB Output is correct
15 Correct 279 ms 49732 KB Output is correct
16 Correct 275 ms 47556 KB Output is correct
17 Correct 282 ms 49232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 265 ms 48416 KB Output is correct
2 Correct 278 ms 50292 KB Output is correct
3 Correct 240 ms 50236 KB Output is correct
4 Correct 265 ms 47944 KB Output is correct
5 Correct 272 ms 49348 KB Output is correct
6 Correct 254 ms 48392 KB Output is correct
7 Correct 269 ms 49348 KB Output is correct
8 Correct 267 ms 48192 KB Output is correct
9 Correct 271 ms 47944 KB Output is correct
10 Correct 273 ms 50380 KB Output is correct
11 Correct 264 ms 48972 KB Output is correct
12 Correct 278 ms 49752 KB Output is correct
13 Correct 265 ms 47956 KB Output is correct
14 Correct 281 ms 50116 KB Output is correct
15 Correct 279 ms 49732 KB Output is correct
16 Correct 275 ms 47556 KB Output is correct
17 Correct 282 ms 49232 KB Output is correct
18 Correct 341 ms 48568 KB Output is correct
19 Correct 324 ms 50116 KB Output is correct
20 Correct 268 ms 50120 KB Output is correct
21 Correct 260 ms 48196 KB Output is correct
22 Correct 321 ms 48588 KB Output is correct
23 Correct 252 ms 48276 KB Output is correct
24 Correct 341 ms 48836 KB Output is correct
25 Correct 263 ms 48072 KB Output is correct
26 Correct 330 ms 47908 KB Output is correct
27 Correct 331 ms 50628 KB Output is correct
28 Correct 282 ms 48584 KB Output is correct
29 Correct 272 ms 49864 KB Output is correct
30 Correct 265 ms 48072 KB Output is correct
31 Correct 257 ms 50064 KB Output is correct
32 Correct 254 ms 49828 KB Output is correct
33 Correct 336 ms 47564 KB Output is correct
34 Correct 264 ms 49352 KB Output is correct