답안 #1105216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105216 2024-10-25T18:11:05 Z vako_p Measures (CEOI22_measures) C++14
0 / 100
254 ms 49132 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

const int mxN = 1e6 + 5;
ll n,a[mxN],b[mxN],d,n1,m,idx[mxN];
map<ll,ll> idx1;
set<ll> ss;

struct segtree{
	vector<ll> v,p,s,cnt;	
	ll sz = 1;
	
	void init(){
		while(sz < n) sz *= 2;
		v.assign(2 * sz, 0LL);
		p.assign(2 * sz, 0LL);
		s.assign(2 * sz, 0LL);
		cnt.assign(2 * sz, 0LL);
	}
	
	void set(ll i, ll x, ll lx, ll rx){
		if(rx - lx == 1){
			s[x] = -idx[min(i + 1, n - 1)] + idx[i] + cnt[x] * d;
			p[x] = cnt[x] * d; 
			v[x] = cnt[x] * d;
			cnt[x]++;
//			cout << i << ' ' << lx << ' ' << rx << "---> " << p[x] << ' ' << s[x] << '\n';
			return;
		}
		ll mid = lx + (rx - lx) / 2;
		if(i < mid) set(i, 2 * x + 1, lx, mid);
		else set(i, 2 * x + 2, mid, rx);
		cnt[x] = cnt[2 * x + 1] + cnt[2 * x + 2];
		v[x] = max(v[2 * x + 1] , v[2 * x + 2]);
		s[x] = s[2 * x + 2];
		p[x] = p[2 * x + 1];
		if(cnt[2 * x + 1] and cnt[2 * x + 2]) v[x] = max(v[x], d + s[2 * x + 1] + p[2 * x + 2]);
		if(cnt[2 * x + 2]) p[x] = max(p[x], p[2 * x + 2] - (idx[mid] - idx[lx]) + cnt[2 * x + 1] * d);
		if(cnt[2 * x  + 1]) s[x] = max(s[x], s[2 * x + 1] - (idx[min(rx, n - 1)] - idx[mid]) + cnt[2 * x + 2] * d);
//		cout << i << ' ' << lx << ' ' << rx << "---> " << p[x] << ' ' << s[x] << '\n';
	}
	
	void set(ll i){
		set(i, 0, 0, sz);
	}
	
	ll find(){
		return v[0]; 
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n1 >> m >> d;
	for(int i = 0; i < n1; i++){
		cin >> a[i];
		ss.insert(a[i]);
	}
	for(int i = 0; i < m; i++){
		cin >> b[i];
		ss.insert(b[i]);
	}
	ll cc = 0;
	for(auto it : ss){
		idx1[it] = cc;
		idx[cc++] = it;
	}
//	idx[cc] = 2e9;
	n = ss.size();
	segtree s;
	s.init();
	for(int i = 0; i < n1; i++){
		s.set(idx1[a[i]]);
//		cout << a[i] << ' ' << idx1[a[i]] << ' ' << s.find() << '\n'; 	
	}
	for(int i = 0; i < m; i++){
		s.set(idx1[b[i]]);
		cout << (double)s.find() / 2 << ' ';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 237 ms 46200 KB Output is correct
2 Incorrect 254 ms 49132 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 237 ms 46200 KB Output is correct
2 Incorrect 254 ms 49132 KB Output isn't correct
3 Halted 0 ms 0 KB -