102432024-03-29 18:02:51111Egyengetőcpp17Wrong answer 0/1003.53s5088 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#include "grader.h"

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N=getN(),K=getK(),M=4e8;
	ordered_set<int>s;
	auto calc=[&](int x)->int{
		int c=0;
		for(int i:s){
			if(i<x){
				c+=x-i;
			}
			if(i>x+K){
				c+=i-(x+K);
			}
		}
		return c;
	};
	for(int i=0;i<N;i++){
		s.insert(Data());
		int ans=1e18;
		{
			int l=0,h=i;
			while(l<h){
				int m=(l+h)/2;
				if(m>=i-s.order_of_key(*s.find_by_order(m)+K)){
					h=m;
				}
				else{
					l=m+1;
				}
			}
			ans=min(ans,calc(*s.find_by_order(h)));
		}
		{
			int l=0,h=i;
			while(l<h){
				int m=(l+h)/2;
				if(s.order_of_key(*s.find_by_order(m)-K)>=i-m){
					h=m;
				}
				else{
					l=m+1;
				}
			}
			ans=min(ans,calc(*s.find_by_order(h)-K));
		}
		Solution(ans);
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2024 KiB
subtask20/20
3Accepted4ms2240 KiB
4Accepted4ms2456 KiB
5Accepted7ms2432 KiB
6Wrong answer4ms2560 KiB
7Wrong answer3ms2768 KiB
8Wrong answer14ms3140 KiB
subtask30/20
9Wrong answer3ms3180 KiB
10Accepted23ms3580 KiB
11Wrong answer17ms3532 KiB
12Accepted23ms3796 KiB
13Accepted23ms3880 KiB
14Accepted23ms4004 KiB
subtask40/20
15Wrong answer4ms3828 KiB
16Accepted2.006s4952 KiB
17Wrong answer3ms3696 KiB
18Accepted1.986s5060 KiB
19Wrong answer9ms3844 KiB
20Accepted1.008s5088 KiB
subtask50/40
21Time limit exceeded3.526s4172 KiB
22Time limit exceeded3.53s3992 KiB
23Wrong answer6ms3720 KiB
24Wrong answer3ms3708 KiB
25Time limit exceeded3.509s4020 KiB
26Time limit exceeded3.509s3788 KiB