답안 #871306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871306 2023-11-10T14:06:44 Z TAhmed33 Weirdtree (RMI21_weirdtree) C++17
8 / 100
2000 ms 20536 KB
#include <bits/stdc++.h>
#include <weirdtree.h>
using namespace std;
typedef long long ll;
int n;
ll arr[300001];
void initialise (int N, int q, int h[]) {
	n = N;
	for (int i = 1; i <= n; i++) {
		arr[i] = h[i];
	}
}
void cut (int l, int r, int k) {
	vector <pair <ll, ll>> dd;
	ll sum = 0;
	for (int i = l; i <= r; i++) {
		if (arr[i] < 0) return;
		dd.push_back({arr[i], i});
		sum += arr[i];
	}
	if (sum <= k) {
		for (int i = l; i <= r; i++) arr[i] = 0;
		return;
	}
	sort(dd.begin(), dd.end(), [] (pair <ll, ll> &a, pair <ll, ll> &b) {
		return a.first == b.first ? a.second < b.second : a.first > b.first;
	});
	dd.push_back({0, (ll)1e9});
	for (int i = 1; i < (int)dd.size(); i++) {
		if (dd[i].first == dd[i - 1].first) continue;
		ll t = (dd[i - 1].first - dd[i].first) * i;
		if (t <= k) {
			k -= t;
			continue;
		}
		ll y = k / i;
		for (int j = 0; j < i; j++) arr[dd[j].second] = dd[i - 1].first - y;
		k %= i;
		sort(dd.begin(), dd.begin() + i, [] (pair <ll, ll> &a, pair <ll, ll> &b) {
			return a.second < b.second;
		});
		for (int j = 0; j < k; j++) arr[dd[j].second]--;
		return;
	}	

}
void magic (int i, int x) {

}
ll inspect (int l, int r) {
	ll sum = 0;
	for (int i = l; i <= r; i++) {
		if (arr[i] < 0) return 0;
		sum += arr[i];
	}
	return sum;
}/*
int main () {
	int n, q;
	cin >> n >> q;
	int arr2[n + 1] = {};
	for (int i = 1; i <= n; i++) {
		cin >> arr2[i];
	}
	initialise(n, q, arr2);
	while (q--) {
		int k;
		cin >> k;
		if (k == 1) {
			int l, r, x;
			cin >> l >> r >> x;
			cut(l, r, x);
		} else {
			int l, r;
			cin >> l >> r;
			cout << inspect(l, r) << '\n';
		}
	}
}*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 352 KB Output is correct
2 Correct 8 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 352 KB Output is correct
2 Correct 8 ms 348 KB Output is correct
3 Execution timed out 2007 ms 20536 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2048 ms 17844 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -