답안 #770862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770862 2023-07-02T05:07:11 Z SanguineChameleon 식물 비교 (IOI20_plants) C++17
27 / 100
200 ms 15732 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 20;
const int inf = 1e9 + 20;
int a[maxn];
pair<int, int> tree[maxn * 4];
int lazy[maxn * 4];
int pos[maxn];
int n, k;

bool cmp(pair<int, int> p1, pair<int, int> p2) {
	if (p1.first != p2.first) {
		return p1.first < p2.first;
	}
	else if (p1.second < p2.second && p2.second - p1.second + 1 <= k) {
		return true;
	}
	else if (p1.second > p2.second && n - (p1.second - p2.second - 1) <= k) {
		return true;
	}
	else {
		return false;
	}
}

void build(int id, int lt, int rt) {
	if (lt == rt) {
		tree[id] = make_pair(a[lt], lt);
		return;
	}
	int mt = (lt + rt) / 2;
	build(id * 2, lt, mt);
	build(id * 2 + 1, mt + 1, rt);
	tree[id] = min(tree[id * 2], tree[id * 2 + 1], cmp);
}

void update(int id, int lt, int rt, int ql, int qr, int add) {
	if (lt == ql && rt == qr) {
		tree[id].first += add;
		lazy[id] += add;
		return;
	}
	tree[id * 2].first += lazy[id];
	lazy[id * 2] += lazy[id];
	tree[id * 2 + 1].first += lazy[id];
	lazy[id * 2 + 1] += lazy[id];
	lazy[id] = 0;
	int mt = (lt + rt) / 2;
	if (qr <= mt) {
		update(id * 2, lt, mt, ql, qr, add);
	}
	else if (ql >= mt + 1) {
		update(id * 2 + 1, mt + 1, rt, ql, qr, add);
	}
	else {
		update(id * 2, lt, mt, ql, mt, add);
		update(id * 2 + 1, mt + 1, rt, mt + 1, qr, add);
	}
	tree[id] = min(tree[id * 2], tree[id * 2 + 1], cmp);
}

void init(int _k, vector<int> _a) {
	n = _a.size();
	k = _k;
	for (int i = 0; i < n; i++) {
		a[i] = k - 1 - _a[i];
	}
	build(1, 0, n - 1);
	for (int i = 0; i < n; i++) {
		int rt = tree[1].second;
		int lt = (rt + n - (k - 1)) % n;
		pos[rt] = i;
		update(1, 0, n - 1, rt, rt, inf);
		if (lt <= rt) {
			update(1, 0, n - 1, lt, rt, -1);
		}
		else {
			update(1, 0, n - 1, lt, n - 1, -1);
			update(1, 0, n - 1, 0, rt, -1);
		}
	}
	return;
}

int compare_plants(int x, int y) {
	return (pos[x] > pos[y] ? 1 : -1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 42 ms 3452 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 448 KB Output is correct
10 Correct 46 ms 3584 KB Output is correct
11 Correct 42 ms 3444 KB Output is correct
12 Correct 41 ms 3568 KB Output is correct
13 Correct 42 ms 3460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 42 ms 3452 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 448 KB Output is correct
10 Correct 46 ms 3584 KB Output is correct
11 Correct 42 ms 3444 KB Output is correct
12 Correct 41 ms 3568 KB Output is correct
13 Correct 42 ms 3460 KB Output is correct
14 Correct 53 ms 4300 KB Output is correct
15 Correct 189 ms 12008 KB Output is correct
16 Correct 54 ms 6380 KB Output is correct
17 Correct 200 ms 15680 KB Output is correct
18 Correct 161 ms 15184 KB Output is correct
19 Correct 167 ms 15724 KB Output is correct
20 Correct 182 ms 15732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 42 ms 3344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -