답안 #432160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
432160 2021-06-17T22:44:38 Z peuch 식물 비교 (IOI20_plants) C++17
49 / 100
1311 ms 28568 KB
#include "plants.h"
#include<bits/stdc++.h>
using namespace std;

int N;
bool sub1;
vector<int> esq, dir, id;

vector<pair<int, int> > mini;
vector<int> lz;
vector<int> R;

vector<pair<pair<int, int>, int> > seg;
vector<int> lz2;

void build(int pos, int ini, int fim){
	lz[pos] = lz2[pos] = 0;
	if(ini == fim){
		mini[pos] = make_pair(R[ini], ini);
		seg[pos] = make_pair(make_pair(1, 0), ini);
		return;
	}
	int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	build(e, ini, mid);
	build(d, mid + 1, fim);
	mini[pos] = min(mini[e], mini[d]);
	seg[pos] = min(seg[e], seg[d]);
}

void refresh2(int pos, int ini, int fim){
	if(lz2[pos] == 0) return;
	seg[pos].first.second += lz2[pos];
	if(ini != fim){
		int e = pos << 1, d = e | 1;
		lz2[e] += lz2[pos];
		lz2[d] += lz2[pos];
	}
	lz2[pos] = 0;
}

void activate(int pos, int ini, int fim, int id){
	refresh2(pos, ini, fim);
	if(ini > id || fim < id) return;
	if(ini == fim){
		seg[pos].first.first ^= 1;
		refresh2(pos, ini, fim);
		return;
	}
	int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	activate(e, ini, mid, id);
	activate(d, mid + 1, fim, id);
	seg[pos] = min(seg[e], seg[d]);
}

void update2(int pos, int ini, int fim, int p, int q, int val){
	refresh2(pos, ini, fim);
	if(ini > q || fim < p) return;
	if(ini >= p && fim <= q){
		lz2[pos] += val;
		refresh2(pos, ini, fim);
		return;
	}
	int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	update2(e, ini, mid, p, q, val);
	update2(d, mid + 1, fim, p, q, val);
	seg[pos] = min(seg[e], seg[d]);
}

void refresh(int pos, int ini, int fim){
	if(lz[pos] == 0) return;
	mini[pos].first += lz[pos];
	if(ini != fim){
		int e = pos << 1, d = e | 1;
		lz[e] += lz[pos];
		lz[d] += lz[pos];
	}
	lz[pos] = 0;
}

void update(int pos, int ini, int fim, int p, int q, int val){
	refresh(pos, ini, fim);
	if(ini > q || fim < p) return;
	if(ini >= p && fim <= q){
		lz[pos] += val;
		refresh(pos, ini, fim);
		return;
	}
	int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	update(e, ini, mid, p, q, val);
	update(d, mid + 1, fim, p, q, val);
	mini[pos] = min(mini[e], mini[d]);
}

void init(int k, vector<int> r) {
	sub1 = k == 2;
	R = r;
	N = R.size();
	if(sub1){
		esq = vector<int> (N);
		dir = vector<int> (N);
		int ini;
		for(ini = 0; ini < N; ini++)
			if(r[ini] == 0) break;
		ini++;
		ini %= N;
		esq[ini] = 0;
		for(int i = ini + 1; i != ini; i++, i %= N){
			int ant = i - 1;
			if(ant < 0) ant += N;
			esq[i] = esq[ant] + 1;
			if(r[ant] == 0) esq[i] = 0;
		}
		
		for(ini = 0; ini < N; ini++)
			if(r[ini] == 1) break;
		dir[ini] = 0;
		for(int i = (ini + N - 1) % N; i != ini; i += N - 1, i %= N){
			int nex = i + 1;
			if(nex >= N) nex -= N;
			dir[i] = dir[nex] + 1;
			if(r[i] == 1) dir[i] = 0;
		}
		return;
	}
	mini = vector<pair<int, int> > (4 * N);
	seg = vector<pair<pair<int, int>, int> > (4 * N);
	lz = lz2 = vector<int> (4 * N);
	build(1, 0, N - 1);
	id = vector<int> (N);
	for(int i = 0; i < N; i++){
		while(1){
			int in = mini[1].first;
			int idx = mini[1].second;
			if(in != 0) break;
			update(1, 0, N - 1, idx, idx, 1e8);
			activate(1, 0, N - 1, idx);
			update2(1, 0, N - 1, idx + 1, idx + k - 1, 1);
			update2(1, 0, N - 1, 0, idx + k - 1 - N, 1);
		}
		int idx = seg[1].second;
		update2(1, 0, N - 1, idx + 1, idx + k - 1, -1);
		update2(1, 0, N - 1, 0, idx + k - 1 - N, -1);
		activate(1, 0, N - 1, idx);
		update(1, 0, N - 1, idx - k + 1, idx - 1, -1);
		update(1, 0, N - 1, idx + N - k + 1, N - 1, -1);
		id[idx] = N - i;
	}
	return;
}

int compare_plants(int x, int y) {
	if(sub1){
		if(x + dir[x] >= y) return 1;
		if(x - esq[x] < 0 && (x + N - esq[x]) % N <= y) return 1;
		if(y - esq[y] <= x) return -1;
		if(y + dir[y] > N && (y + dir[y]) % N >= x) return -1;
		return 0;
	}
	if(id[x] > id[y]) return 1;
	else return -1;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 59 ms 3160 KB Output is correct
7 Correct 68 ms 3604 KB Output is correct
8 Correct 98 ms 6596 KB Output is correct
9 Correct 94 ms 6628 KB Output is correct
10 Correct 94 ms 6596 KB Output is correct
11 Correct 109 ms 6636 KB Output is correct
12 Correct 104 ms 6596 KB Output is correct
13 Correct 88 ms 6636 KB Output is correct
14 Correct 91 ms 6604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 6 ms 460 KB Output is correct
7 Correct 75 ms 4232 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 5 ms 436 KB Output is correct
10 Correct 79 ms 4368 KB Output is correct
11 Correct 71 ms 4240 KB Output is correct
12 Correct 90 ms 4364 KB Output is correct
13 Correct 86 ms 4316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 6 ms 460 KB Output is correct
7 Correct 75 ms 4232 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 5 ms 436 KB Output is correct
10 Correct 79 ms 4368 KB Output is correct
11 Correct 71 ms 4240 KB Output is correct
12 Correct 90 ms 4364 KB Output is correct
13 Correct 86 ms 4316 KB Output is correct
14 Correct 139 ms 6124 KB Output is correct
15 Correct 1253 ms 28312 KB Output is correct
16 Correct 144 ms 5572 KB Output is correct
17 Correct 1311 ms 27704 KB Output is correct
18 Correct 787 ms 27720 KB Output is correct
19 Correct 844 ms 27708 KB Output is correct
20 Correct 1078 ms 27716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 65 ms 3916 KB Output is correct
4 Correct 592 ms 28292 KB Output is correct
5 Correct 744 ms 28568 KB Output is correct
6 Correct 1041 ms 27992 KB Output is correct
7 Correct 1192 ms 27988 KB Output is correct
8 Correct 1284 ms 28092 KB Output is correct
9 Correct 665 ms 27712 KB Output is correct
10 Correct 695 ms 27708 KB Output is correct
11 Correct 93 ms 6468 KB Output is correct
12 Correct 657 ms 27756 KB Output is correct
13 Correct 763 ms 27744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 59 ms 3160 KB Output is correct
7 Correct 68 ms 3604 KB Output is correct
8 Correct 98 ms 6596 KB Output is correct
9 Correct 94 ms 6628 KB Output is correct
10 Correct 94 ms 6596 KB Output is correct
11 Correct 109 ms 6636 KB Output is correct
12 Correct 104 ms 6596 KB Output is correct
13 Correct 88 ms 6636 KB Output is correct
14 Correct 91 ms 6604 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 288 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 6 ms 460 KB Output is correct
21 Correct 75 ms 4232 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 5 ms 436 KB Output is correct
24 Correct 79 ms 4368 KB Output is correct
25 Correct 71 ms 4240 KB Output is correct
26 Correct 90 ms 4364 KB Output is correct
27 Correct 86 ms 4316 KB Output is correct
28 Correct 139 ms 6124 KB Output is correct
29 Correct 1253 ms 28312 KB Output is correct
30 Correct 144 ms 5572 KB Output is correct
31 Correct 1311 ms 27704 KB Output is correct
32 Correct 787 ms 27720 KB Output is correct
33 Correct 844 ms 27708 KB Output is correct
34 Correct 1078 ms 27716 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 65 ms 3916 KB Output is correct
38 Correct 592 ms 28292 KB Output is correct
39 Correct 744 ms 28568 KB Output is correct
40 Correct 1041 ms 27992 KB Output is correct
41 Correct 1192 ms 27988 KB Output is correct
42 Correct 1284 ms 28092 KB Output is correct
43 Correct 665 ms 27712 KB Output is correct
44 Correct 695 ms 27708 KB Output is correct
45 Correct 93 ms 6468 KB Output is correct
46 Correct 657 ms 27756 KB Output is correct
47 Correct 763 ms 27744 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Incorrect 1 ms 204 KB Output isn't correct
53 Halted 0 ms 0 KB -