답안 #205255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205255 2020-02-28T11:28:58 Z ics0503 Minerals (JOI19_minerals) C++17
90 / 100
100 ms 18160 KB
#include "minerals.h"
#include<algorithm>
#include<vector>
using namespace std;
vector<int>L, R;
struct SEG {
	vector<int>L;
	int l, r, s, e, who, ck;
} seg[212121];
int segN = 1, segW[212121];
void make_seg(int now, int s, int e) {
	seg[now].who = s;
	seg[now].s = s; seg[now].e = e;
	if (s == e) {
		segW[s] = now;
		return;
	}
	int m = (s + e) / 2;
	if (!seg[now].l)seg[now].l = ++segN;
	make_seg(seg[now].l, s, m);
	if (!seg[now].r)seg[now].r = ++segN;
	make_seg(seg[now].r, m + 1, e);
}
int is_in[212121];
void go_down(int now, int s, int e) {
	seg[now].ck = 1;
	if (s == e) return;
	int m = (s + e) / 2, l = seg[now].l, r = seg[now].r, bef;
	for (int i = m + 1; i <= e; i++) {
		is_in[i] = !is_in[i];
		bef = Query(L[i]);
	}
	random_shuffle(seg[now].L.begin(), seg[now].L.end());
	for (int p : seg[now].L) {
		if (seg[r].L.size() == (e - (m + 1) + 1)) { seg[l].L.push_back(p); continue; }
		if (seg[l].L.size() == (m - s + 1)) { seg[r].L.push_back(p); continue; }
		int res = Query(p);
		if (res == bef) {
			if (is_in[s])seg[l].L.push_back(p);
			else seg[r].L.push_back(p);
		}
		else {
			if (is_in[s])seg[r].L.push_back(p);
			else seg[l].L.push_back(p);
		}
		bef = res;
	}
	go_down(l, s, m);
}
void Solve(int n) {
	int cnt = 0;
	vector<int>v;
	for (int i = 1; i <= n * 2; i++)v.push_back(i);
	random_shuffle(v.begin(), v.end());
	for (int i: v) {
		int res = Query(i);
		if (res != cnt) L.push_back(i);
		else seg[1].L.push_back(i);
		cnt = res;
	}
	for (int i = 0; i < n; i++)is_in[i] = 1;
	make_seg(1, 0, n - 1);
	go_down(1, 0, n - 1);
	for (int i = 2; i <= segN; i++) {
		int s = seg[i].s, e = seg[i].e;
		if (seg[i].ck || seg[i].L.empty() || s == e)continue;
		go_down(i, s, e);
	}
	for (int i = 0; i < n; i++) {
		for (int p : seg[segW[i]].L) {
			Answer(L[i], p);
		}
	}
}

Compilation message

minerals.cpp: In function 'void go_down(int, int, int)':
minerals.cpp:35:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (seg[r].L.size() == (e - (m + 1) + 1)) { seg[l].L.push_back(p); continue; }
       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
minerals.cpp:36:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (seg[l].L.size() == (m - s + 1)) { seg[r].L.push_back(p); continue; }
       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
minerals.cpp:38:3: warning: 'bef' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (res == bef) {
   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10360 KB Output is correct
2 Correct 10 ms 10236 KB Output is correct
3 Correct 11 ms 10232 KB Output is correct
4 Correct 11 ms 10360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 10488 KB Output is correct
2 Correct 13 ms 10488 KB Output is correct
3 Correct 16 ms 10872 KB Output is correct
4 Correct 23 ms 11512 KB Output is correct
5 Correct 33 ms 12664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10360 KB Output is correct
2 Correct 10 ms 10236 KB Output is correct
3 Correct 11 ms 10232 KB Output is correct
4 Correct 11 ms 10360 KB Output is correct
5 Correct 12 ms 10488 KB Output is correct
6 Correct 13 ms 10488 KB Output is correct
7 Correct 16 ms 10872 KB Output is correct
8 Correct 23 ms 11512 KB Output is correct
9 Correct 33 ms 12664 KB Output is correct
10 Correct 12 ms 10356 KB Output is correct
11 Correct 27 ms 12024 KB Output is correct
12 Correct 36 ms 12664 KB Output is correct
13 Correct 33 ms 12664 KB Output is correct
14 Correct 33 ms 12664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10360 KB Output is correct
2 Correct 10 ms 10236 KB Output is correct
3 Correct 11 ms 10232 KB Output is correct
4 Correct 11 ms 10360 KB Output is correct
5 Correct 12 ms 10488 KB Output is correct
6 Correct 13 ms 10488 KB Output is correct
7 Correct 16 ms 10872 KB Output is correct
8 Correct 23 ms 11512 KB Output is correct
9 Correct 33 ms 12664 KB Output is correct
10 Correct 12 ms 10356 KB Output is correct
11 Correct 27 ms 12024 KB Output is correct
12 Correct 36 ms 12664 KB Output is correct
13 Correct 33 ms 12664 KB Output is correct
14 Correct 33 ms 12664 KB Output is correct
15 Correct 82 ms 17604 KB Output is correct
16 Correct 82 ms 17520 KB Output is correct
17 Correct 83 ms 17576 KB Output is correct
18 Correct 80 ms 17392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10360 KB Output is correct
2 Correct 10 ms 10236 KB Output is correct
3 Correct 11 ms 10232 KB Output is correct
4 Correct 11 ms 10360 KB Output is correct
5 Correct 12 ms 10488 KB Output is correct
6 Correct 13 ms 10488 KB Output is correct
7 Correct 16 ms 10872 KB Output is correct
8 Correct 23 ms 11512 KB Output is correct
9 Correct 33 ms 12664 KB Output is correct
10 Correct 12 ms 10356 KB Output is correct
11 Correct 27 ms 12024 KB Output is correct
12 Correct 36 ms 12664 KB Output is correct
13 Correct 33 ms 12664 KB Output is correct
14 Correct 33 ms 12664 KB Output is correct
15 Correct 82 ms 17604 KB Output is correct
16 Correct 82 ms 17520 KB Output is correct
17 Correct 83 ms 17576 KB Output is correct
18 Correct 80 ms 17392 KB Output is correct
19 Correct 83 ms 17700 KB Output is correct
20 Correct 80 ms 17648 KB Output is correct
21 Correct 77 ms 17648 KB Output is correct
22 Correct 79 ms 17520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10360 KB Output is correct
2 Correct 10 ms 10236 KB Output is correct
3 Correct 11 ms 10232 KB Output is correct
4 Correct 11 ms 10360 KB Output is correct
5 Correct 12 ms 10488 KB Output is correct
6 Correct 13 ms 10488 KB Output is correct
7 Correct 16 ms 10872 KB Output is correct
8 Correct 23 ms 11512 KB Output is correct
9 Correct 33 ms 12664 KB Output is correct
10 Correct 12 ms 10356 KB Output is correct
11 Correct 27 ms 12024 KB Output is correct
12 Correct 36 ms 12664 KB Output is correct
13 Correct 33 ms 12664 KB Output is correct
14 Correct 33 ms 12664 KB Output is correct
15 Correct 82 ms 17604 KB Output is correct
16 Correct 82 ms 17520 KB Output is correct
17 Correct 83 ms 17576 KB Output is correct
18 Correct 80 ms 17392 KB Output is correct
19 Correct 83 ms 17700 KB Output is correct
20 Correct 80 ms 17648 KB Output is correct
21 Correct 77 ms 17648 KB Output is correct
22 Correct 79 ms 17520 KB Output is correct
23 Correct 82 ms 17900 KB Output is correct
24 Correct 83 ms 17900 KB Output is correct
25 Correct 89 ms 17904 KB Output is correct
26 Correct 84 ms 17776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10360 KB Output is correct
2 Correct 10 ms 10236 KB Output is correct
3 Correct 11 ms 10232 KB Output is correct
4 Correct 11 ms 10360 KB Output is correct
5 Correct 12 ms 10488 KB Output is correct
6 Correct 13 ms 10488 KB Output is correct
7 Correct 16 ms 10872 KB Output is correct
8 Correct 23 ms 11512 KB Output is correct
9 Correct 33 ms 12664 KB Output is correct
10 Correct 12 ms 10356 KB Output is correct
11 Correct 27 ms 12024 KB Output is correct
12 Correct 36 ms 12664 KB Output is correct
13 Correct 33 ms 12664 KB Output is correct
14 Correct 33 ms 12664 KB Output is correct
15 Correct 82 ms 17604 KB Output is correct
16 Correct 82 ms 17520 KB Output is correct
17 Correct 83 ms 17576 KB Output is correct
18 Correct 80 ms 17392 KB Output is correct
19 Correct 83 ms 17700 KB Output is correct
20 Correct 80 ms 17648 KB Output is correct
21 Correct 77 ms 17648 KB Output is correct
22 Correct 79 ms 17520 KB Output is correct
23 Correct 82 ms 17900 KB Output is correct
24 Correct 83 ms 17900 KB Output is correct
25 Correct 89 ms 17904 KB Output is correct
26 Correct 84 ms 17776 KB Output is correct
27 Correct 88 ms 18032 KB Output is correct
28 Correct 86 ms 18032 KB Output is correct
29 Correct 84 ms 17904 KB Output is correct
30 Correct 82 ms 17776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10360 KB Output is correct
2 Correct 10 ms 10236 KB Output is correct
3 Correct 11 ms 10232 KB Output is correct
4 Correct 11 ms 10360 KB Output is correct
5 Correct 12 ms 10488 KB Output is correct
6 Correct 13 ms 10488 KB Output is correct
7 Correct 16 ms 10872 KB Output is correct
8 Correct 23 ms 11512 KB Output is correct
9 Correct 33 ms 12664 KB Output is correct
10 Correct 12 ms 10356 KB Output is correct
11 Correct 27 ms 12024 KB Output is correct
12 Correct 36 ms 12664 KB Output is correct
13 Correct 33 ms 12664 KB Output is correct
14 Correct 33 ms 12664 KB Output is correct
15 Correct 82 ms 17604 KB Output is correct
16 Correct 82 ms 17520 KB Output is correct
17 Correct 83 ms 17576 KB Output is correct
18 Correct 80 ms 17392 KB Output is correct
19 Correct 83 ms 17700 KB Output is correct
20 Correct 80 ms 17648 KB Output is correct
21 Correct 77 ms 17648 KB Output is correct
22 Correct 79 ms 17520 KB Output is correct
23 Correct 82 ms 17900 KB Output is correct
24 Correct 83 ms 17900 KB Output is correct
25 Correct 89 ms 17904 KB Output is correct
26 Correct 84 ms 17776 KB Output is correct
27 Correct 88 ms 18032 KB Output is correct
28 Correct 86 ms 18032 KB Output is correct
29 Correct 84 ms 17904 KB Output is correct
30 Correct 82 ms 17776 KB Output is correct
31 Correct 86 ms 18116 KB Output is correct
32 Correct 100 ms 18160 KB Output is correct
33 Correct 82 ms 18032 KB Output is correct
34 Correct 92 ms 17904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10360 KB Output is correct
2 Correct 10 ms 10236 KB Output is correct
3 Correct 11 ms 10232 KB Output is correct
4 Correct 11 ms 10360 KB Output is correct
5 Correct 12 ms 10488 KB Output is correct
6 Correct 13 ms 10488 KB Output is correct
7 Correct 16 ms 10872 KB Output is correct
8 Correct 23 ms 11512 KB Output is correct
9 Correct 33 ms 12664 KB Output is correct
10 Correct 12 ms 10356 KB Output is correct
11 Correct 27 ms 12024 KB Output is correct
12 Correct 36 ms 12664 KB Output is correct
13 Correct 33 ms 12664 KB Output is correct
14 Correct 33 ms 12664 KB Output is correct
15 Correct 82 ms 17604 KB Output is correct
16 Correct 82 ms 17520 KB Output is correct
17 Correct 83 ms 17576 KB Output is correct
18 Correct 80 ms 17392 KB Output is correct
19 Correct 83 ms 17700 KB Output is correct
20 Correct 80 ms 17648 KB Output is correct
21 Correct 77 ms 17648 KB Output is correct
22 Correct 79 ms 17520 KB Output is correct
23 Correct 82 ms 17900 KB Output is correct
24 Correct 83 ms 17900 KB Output is correct
25 Correct 89 ms 17904 KB Output is correct
26 Correct 84 ms 17776 KB Output is correct
27 Correct 88 ms 18032 KB Output is correct
28 Correct 86 ms 18032 KB Output is correct
29 Correct 84 ms 17904 KB Output is correct
30 Correct 82 ms 17776 KB Output is correct
31 Correct 86 ms 18116 KB Output is correct
32 Correct 100 ms 18160 KB Output is correct
33 Correct 82 ms 18032 KB Output is correct
34 Correct 92 ms 17904 KB Output is correct
35 Incorrect 88 ms 17700 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -