답안 #551213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551213 2022-04-20T05:48:05 Z Sohsoh84 쌀 창고 (IOI11_ricehub) C++17
51 / 100
47 ms 3340 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define X			first
#define Y			second
#define debug(x)		cerr << #x << ": " << x << endl;

const ll MAXN = 1e6 + 10;

inline pll operator+ (const pll& a, const pll& b) {
	return {a.X + b.X, a.Y + b.Y};
}

int n;
vector<ll> vec;

namespace median {
	pll fen[MAXN], tot = {0, 0};

	inline void update(int ind, pll val) {
		tot = tot + val;
		for (++ind; ind < MAXN; ind += ind & -ind)
			fen[ind] = fen[ind] + val;
	}

	inline pll query(int ind) {
		pll ans = {0, 0};
		for (++ind; ind > 0; ind -= ind & -ind)
			ans = ans + fen[ind];
		return ans;
	}

	inline ll median() {
		int l = 0, r = int(vec.size()) - 1;
		while (l < r) {
			int mid = (l + r) >> 1;
			if (query(mid).Y <= (tot.Y + 1) / 2) l = mid + 1;
			else r = mid;
		}

		return l;
	}

	inline ll cost() {
		int ind = median();
		ll ans = 0;

		pll e = query(ind);
		ans += e.Y * vec[ind] - e.X;

		e = tot + pll(-e.X, -e.Y);
		ans += e.X - e.Y * vec[ind];
		return ans;
	}
}	

int besthub(int R, int L, int X[], long long B) {	
	n = R;
	for (int i = 0; i < n; i++)
		vec.push_back(X[i]);

	int ans = 0, l = 0;
	for (int r = 0; r < n; r++) {
		median::update(r, {vec[r], 1});
		while (median::cost() > B) {
			median::update(l, {-vec[l], -1});
			l++;
		}

		ans = max(ans, r - l + 1);
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 552 KB Output is correct
22 Correct 3 ms 468 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 1004 KB Output is correct
2 Correct 14 ms 1044 KB Output is correct
3 Correct 42 ms 3136 KB Output is correct
4 Correct 41 ms 3188 KB Output is correct
5 Correct 32 ms 1860 KB Output is correct
6 Correct 34 ms 1856 KB Output is correct
7 Correct 42 ms 3268 KB Output is correct
8 Correct 42 ms 3340 KB Output is correct
9 Correct 35 ms 1856 KB Output is correct
10 Correct 37 ms 1884 KB Output is correct
11 Correct 47 ms 3264 KB Output is correct
12 Correct 40 ms 3336 KB Output is correct
13 Incorrect 36 ms 1920 KB Output isn't correct
14 Halted 0 ms 0 KB -