답안 #1104604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104604 2024-10-24T06:40:21 Z Nonoze 나일강 (IOI24_nile) C++17
100 / 100
103 ms 21964 KB
#include "nile.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define cmax(a, b) a=max(a, b)
#define cmin(a, b) a=min(a, b)
#define fi first
#define se second

vector<pair<int, int>> leftt;

int calc(int d, int l, int r) { int n=r-l+1;
	if ((r-l+1)%2==0) return 0;
	int ans=min(leftt[l].se, leftt[r].se);
	for (int i=l; i<=r; i+=2) cmin(ans, leftt[i].se);
	for (int i=l; i<n-1; i++) {
		if (leftt[i+1].fi-leftt[i-1].fi<=d) cmin(ans, leftt[i].se);
	}
	return ans;
}

int n, q, base;
vector<pair<int, int>> a;
vector<int> par, szz, odd, even, best;

int getpar(int x) {
	if (x==par[x]) return x;
	return par[x]=getpar(par[x]);
}

void merge(int a, int &ans) {
	int b=a+1;
	a=getpar(a), b=getpar(b);
	if (a==b) return;
	ans-=(szz[a]%2)*min(best[a], odd[a])+(szz[b]%2)*min(best[b], odd[b]);
	if (szz[a]%2) swap(odd[b], even[b]);
	cmin(odd[a], odd[b]), cmin(even[a], even[b]), cmin(best[a], best[b]);
	szz[a]+=szz[b];
	par[b]=a;
	ans+=(szz[a]%2)*min(best[a], odd[a]);
}

void add(int a, int val, int &ans) {
	a=getpar(a);
	ans-=(szz[a]%2)*min(best[a], odd[a]);
	cmin(best[a], val);
	ans+=(szz[a]%2)*min(best[a], odd[a]);
}

vector<int> calculate_costs(vector<signed> _w, vector<signed> _a, vector<signed> _b, vector<signed> e) { n=sz(_w), q=sz(e);
	base=0;
	int ans=0;
	for (int i=0; i<n; i++) base+=(int)_b[i], _a[i]-=_b[i];
	for (int i=0; i<n; i++) a.pb({_w[i], _a[i]}), ans+=_a[i];
	sort(all(a));
	par.resize(n, 0), szz.resize(n, 1); iota(all(par), 0);
	odd.resize(n), even.resize(n, 1e18), best.resize(n, 1e18);
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq2;
	for (int i=0; i<n-1; i++) pq.push({a[i+1].fi-a[i].fi, i});
	for (int i=1; i<n-1; i++) pq2.push({a[i+1].fi-a[i-1].fi, i});
	for (int i=0; i<n; i++) odd[i]=a[i].se;
	vector<int> answers(q);
	vector<pair<int, int>> queries;
	for (int i=0; i<q; i++) queries.pb({e[i], i});
	sort(all(queries));
	for (auto [d, pos]: queries) {
		while (!pq.empty() && pq.top().fi<=d) {
			merge(pq.top().se, ans);
			pq.pop();
		}
		while (!pq2.empty() && pq2.top().fi<=d) {
			add(pq2.top().se, a[pq2.top().se].se, ans);
			pq2.pop();
		}
		answers[pos]=base+ans;
	}
	return answers;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 712 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 3 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 17164 KB Output is correct
2 Correct 53 ms 17212 KB Output is correct
3 Correct 53 ms 17320 KB Output is correct
4 Correct 51 ms 16964 KB Output is correct
5 Correct 52 ms 16188 KB Output is correct
6 Correct 48 ms 16188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 15684 KB Output is correct
2 Correct 53 ms 16052 KB Output is correct
3 Correct 58 ms 16032 KB Output is correct
4 Correct 58 ms 15948 KB Output is correct
5 Correct 54 ms 16200 KB Output is correct
6 Correct 65 ms 15940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 712 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 3 ms 712 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 712 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 712 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 3 ms 712 KB Output is correct
7 Correct 60 ms 17164 KB Output is correct
8 Correct 53 ms 17212 KB Output is correct
9 Correct 53 ms 17320 KB Output is correct
10 Correct 51 ms 16964 KB Output is correct
11 Correct 52 ms 16188 KB Output is correct
12 Correct 48 ms 16188 KB Output is correct
13 Correct 53 ms 15684 KB Output is correct
14 Correct 53 ms 16052 KB Output is correct
15 Correct 58 ms 16032 KB Output is correct
16 Correct 58 ms 15948 KB Output is correct
17 Correct 54 ms 16200 KB Output is correct
18 Correct 65 ms 15940 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 2 ms 712 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 520 KB Output is correct
25 Correct 62 ms 17388 KB Output is correct
26 Correct 62 ms 16448 KB Output is correct
27 Correct 73 ms 17728 KB Output is correct
28 Correct 70 ms 16444 KB Output is correct
29 Correct 68 ms 17344 KB Output is correct
30 Correct 76 ms 17468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 15684 KB Output is correct
2 Correct 53 ms 16052 KB Output is correct
3 Correct 58 ms 16032 KB Output is correct
4 Correct 58 ms 15948 KB Output is correct
5 Correct 54 ms 16200 KB Output is correct
6 Correct 65 ms 15940 KB Output is correct
7 Correct 70 ms 20160 KB Output is correct
8 Correct 71 ms 20428 KB Output is correct
9 Correct 79 ms 20416 KB Output is correct
10 Correct 79 ms 20160 KB Output is correct
11 Correct 80 ms 20416 KB Output is correct
12 Correct 87 ms 18580 KB Output is correct
13 Correct 80 ms 20416 KB Output is correct
14 Correct 75 ms 20204 KB Output is correct
15 Correct 88 ms 20424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 712 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 3 ms 712 KB Output is correct
8 Correct 60 ms 17164 KB Output is correct
9 Correct 53 ms 17212 KB Output is correct
10 Correct 53 ms 17320 KB Output is correct
11 Correct 51 ms 16964 KB Output is correct
12 Correct 52 ms 16188 KB Output is correct
13 Correct 48 ms 16188 KB Output is correct
14 Correct 53 ms 15684 KB Output is correct
15 Correct 53 ms 16052 KB Output is correct
16 Correct 58 ms 16032 KB Output is correct
17 Correct 58 ms 15948 KB Output is correct
18 Correct 54 ms 16200 KB Output is correct
19 Correct 65 ms 15940 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 592 KB Output is correct
25 Correct 2 ms 520 KB Output is correct
26 Correct 62 ms 17388 KB Output is correct
27 Correct 62 ms 16448 KB Output is correct
28 Correct 73 ms 17728 KB Output is correct
29 Correct 70 ms 16444 KB Output is correct
30 Correct 68 ms 17344 KB Output is correct
31 Correct 76 ms 17468 KB Output is correct
32 Correct 70 ms 20160 KB Output is correct
33 Correct 71 ms 20428 KB Output is correct
34 Correct 79 ms 20416 KB Output is correct
35 Correct 79 ms 20160 KB Output is correct
36 Correct 80 ms 20416 KB Output is correct
37 Correct 87 ms 18580 KB Output is correct
38 Correct 80 ms 20416 KB Output is correct
39 Correct 75 ms 20204 KB Output is correct
40 Correct 88 ms 20424 KB Output is correct
41 Correct 84 ms 21696 KB Output is correct
42 Correct 84 ms 20428 KB Output is correct
43 Correct 88 ms 20416 KB Output is correct
44 Correct 88 ms 21940 KB Output is correct
45 Correct 90 ms 21964 KB Output is correct
46 Correct 97 ms 21952 KB Output is correct
47 Correct 90 ms 21808 KB Output is correct
48 Correct 84 ms 21524 KB Output is correct
49 Correct 103 ms 20436 KB Output is correct