102152024-03-29 16:04:56111Egyengetőcpp17Wrong answer 0/1004ms4140 KiB
#include <bits/stdc++.h>
using namespace std;

#include "grader.h"

#define int long long

int dbg=0;

struct Nd{
	int a,d;
	Nd*l,*r;
};

struct ST{
	int n;
	Nd*root;
	
	ST(int n):n(n),root(nullptr){
	}
	
	void update(Nd*&i,int l,int r,int ll,int rr){
		if(l>rr||r<ll){
			return;
		}
		if(!i){
			i=new Nd{};
			dbg++;
		}
		if(l>=ll&&r<=rr){
			i->a+=l-ll;
			i->d+=1;
			return;
		}
		update(i->l,l,(l+r)/2,ll,rr);
		update(i->r,(l+r)/2+1,r,ll,rr);
	}
	
	void update(int ll,int rr){
		update(root,0,n-1,ll,rr);
	}
	
	int query(Nd*&i,int l,int r,int ii){
		if(!i||l>ii||r<ii){
			return 0;
		}
		int ans=i->a+i->d*(ii-l);
		if(l==r){
			return ans;
		}
		return ans+query(i->l,l,(l+r)/2,ii)+query(i->r,(l+r)/2+1,r,ii);
	}
	
	int query(int ii){
		return query(root,0,n-1,ii);
	}
};

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N=getN(),K=getK(),M=1e9;
	ST a(M+1),b(M+1);
	auto calc=[&](int x)->int{
		return 0;
		return a.query(x)+b.query(M/2-(x+K));
	};
	for(int i=0;i<N;i++){
		int y=Data();
		a.update(y,M);
		b.update(M/2-y,M);
		int l=-5e8,h=5e8;
		while(h-l>=3){
			int m1=l+(h-l)/3;
			int m2=h-(h-l)/3;
			if(calc(m1)<=calc(m2)){
				h=m2;
			}
			else{
				l=m1;
			}
		}
		int ans=1e18;
		for(int i=l;i<=h;i++){
			ans=min(ans,calc(i));
		}
		Solution(ans);
	}
	// cout<<dbg<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1896 KiB
2Wrong answer3ms2088 KiB
subtask20/20
3Wrong answer3ms2188 KiB
4Wrong answer3ms2400 KiB
5Wrong answer3ms2616 KiB
6Wrong answer3ms2832 KiB
7Wrong answer4ms2920 KiB
8Wrong answer3ms3260 KiB
subtask30/20
9Wrong answer3ms3124 KiB
10Wrong answer3ms3124 KiB
11Wrong answer3ms3364 KiB
12Wrong answer3ms3244 KiB
13Wrong answer3ms3344 KiB
14Wrong answer3ms3252 KiB
subtask40/20
15Wrong answer3ms3120 KiB
16Wrong answer3ms3252 KiB
17Wrong answer3ms3588 KiB
18Wrong answer3ms3820 KiB
19Wrong answer3ms3792 KiB
20Wrong answer3ms3900 KiB
subtask50/40
21Wrong answer3ms4132 KiB
22Wrong answer3ms4140 KiB
23Wrong answer3ms4116 KiB
24Wrong answer3ms4124 KiB
25Wrong answer3ms3992 KiB
26Wrong answer3ms4000 KiB