Submission #393009

# Submission time Handle Problem Language Result Execution time Memory
393009 2021-04-22T14:12:23 Z Mlxa Shopping (JOI21_shopping) C++14
1 / 100
424 ms 97320 KB
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;

namespace local {
	const int UP = 0, LEF = 2, RIG = 3;
	int n, l, r, choice = -1;
	vector<int> q;
	int cnt = 0;
}

void InitA(int nn, int ll, int rr) {
	using namespace local;
	n = nn;
	l = ll;
	r = rr;
}

void solve() {
	using namespace local;
	int v = 0, ql = 0, qr = 0;
	for (int i = 0; i < 20; ++i) {
		v += q[i] << i;
		ql += q[i + 20] << i;
		qr += q[i + 40] << i;
	}
	// cout << "? " << v << " " << ql << " " << qr << endl;
	if (!(ql <= l && r <= qr)) {
		cnt += 1;
		SendA(0);
		return;
	}
	if (r < v) {
		cnt += 2;
		SendA(1), SendA(0);
		return;
	}
	if (l > v) {
		cnt += 2;
		SendA(1), SendA(1);
		return;
	}
	choice = v;
}

void ex() {
	using namespace local;
	assert((int)q.size() == 20);
	int v = 0;
	for (int i = 0; i < 20; ++i) {
		v |= q[i] << i;
	}
	if (l <= v && v <= r) {
		choice = v;
	}
}

void ReceiveA(bool x) {
	using namespace local;
	if (choice != -1) {
		return;
	}
	q.push_back(x);
	if (cnt + 2 > 18 && (int)q.size() == 20) {
		ex();
		q.clear();
	}
	if ((int)q.size() == 60) {
		solve();
		q.clear();
	}
}

int Answer() {
	using namespace local;
	assert(choice != -1);
	return choice;
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second

namespace my {

const int N = 1 << 20;
const int INF =   1e9;

bool bad[N];
pair<int, int> t[2 * N];
int query(int l, int r) {
	pair<int, int> res = make_pair(INF, -1);
	for (l += N, r += N; l <= r; l /= 2, r /= 2) {
		if (l % 2 == 1) {
			res = min(res, t[l++]);
		}
		if (r % 2 == 0) {
			res = min(res, t[r--]);
		}
	}
	return res.y;
}
vector<pair<int, int>> g[N];
int lb[N], rb[N];
const int UP  = 0;
const int LEF = 2;
const int RIG = 3;

int pdfs(int l, int r) {
	int v = query(l, r);
	lb[v] = l, rb[v] = r;
	if (l < v) {
		int u = pdfs(l, v - 1);
		g[v].emplace_back(u, LEF);
		g[u].emplace_back(v, UP);
	}
	if (v < r) {
		int u = pdfs(v + 1, r);
		g[v].emplace_back(u, RIG);
		g[u].emplace_back(v, UP);
	}
	return v;
}
int sz[N];
void szdfs(int v, int p) {
	sz[v] = 1;
	for (auto e : g[v]) {
		int u = e.x;
		if (u == p || bad[u]) {
			continue;
		}
		szdfs(u, v);
		sz[v] += sz[u];
	}
}
int cdfs(int v, int p, int s) {
	for (auto e : g[v]) {
		int u = e.x;
		if (u == p || bad[u]) {
			continue;
		}
		if (2 * sz[u] > s) {
			return cdfs(u, v, s);
		}
	}
	return v;
}
int center(int v) {
	szdfs(v, v);
	return cdfs(v, v, sz[v]);
}
void send(int len, int msk) {
	for (int i = 0; i < len; ++i) {
		SendB((msk >> i) & 1);
	}
}
void ask(int v) {
	send(20, v);
	send(20, lb[v]);
	send(20, rb[v]);
}
int root;
int state = -1;
int Acnt;

vector<pair<int, int>> srt;
void edfs(int v, int p) {
	srt.emplace_back(t[N + v].x, v);
	for (auto e : g[v]) {
		int u = e.x;
		if (u == p || bad[u]) {
			continue;
		}
		edfs(u, v);
	}
}

void express() {
	edfs(root, root);
	sort(srt.begin(), srt.end());
	for (auto e : srt) {
		send(20, e.y);
	}
}
}

void InitB(int n, vector<int> p) {
	using namespace my;
	for (int i = 0; i < n; ++i) {
		t[N + i] = make_pair(p[i], i);
	}
	for (int i = N - 1; i > 0; --i) {
		t[i] = min(t[i + i], t[i + i + 1]);
	}
	root = pdfs(0, n - 1);
	root = center(root);
	bad[root] = true;
	ask(root);
}

void ReceiveB(bool y) {
	// cout << "ReceiveB " << y << endl;
	using namespace my;
	++Acnt;
	if (state == -1) {
		state = y;
	} else if (state == 1) {
		state = 2 + y;
	} else {
		assert(false);
	}
	if (state == 0 || state == 2 || state == 3) {
		for (auto e : g[root]) {
			if (e.y == state) {
				root = e.x;
				break;
			}
		}
		// cout << "go to " << root << endl;
		root = center(root);
		bad[root] = true;
		ask(root);
		state = -1;
		if (Acnt + 2 > 18) {
			express();
			return;
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 33300 KB Output is correct
2 Correct 25 ms 33280 KB Output is correct
3 Correct 27 ms 33236 KB Output is correct
4 Correct 24 ms 33424 KB Output is correct
5 Correct 27 ms 33288 KB Output is correct
6 Correct 25 ms 33412 KB Output is correct
7 Correct 31 ms 33408 KB Output is correct
8 Correct 24 ms 33408 KB Output is correct
9 Correct 31 ms 33400 KB Output is correct
10 Correct 31 ms 33408 KB Output is correct
11 Correct 32 ms 33352 KB Output is correct
12 Correct 31 ms 33408 KB Output is correct
13 Correct 32 ms 33412 KB Output is correct
14 Correct 27 ms 33396 KB Output is correct
15 Correct 27 ms 33412 KB Output is correct
16 Correct 24 ms 33408 KB Output is correct
17 Correct 25 ms 33356 KB Output is correct
18 Correct 28 ms 33408 KB Output is correct
19 Correct 27 ms 33412 KB Output is correct
20 Correct 27 ms 33412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 33300 KB Output is correct
2 Correct 25 ms 33280 KB Output is correct
3 Correct 27 ms 33236 KB Output is correct
4 Correct 24 ms 33424 KB Output is correct
5 Correct 27 ms 33288 KB Output is correct
6 Correct 25 ms 33412 KB Output is correct
7 Correct 31 ms 33408 KB Output is correct
8 Correct 24 ms 33408 KB Output is correct
9 Correct 31 ms 33400 KB Output is correct
10 Correct 31 ms 33408 KB Output is correct
11 Correct 32 ms 33352 KB Output is correct
12 Correct 31 ms 33408 KB Output is correct
13 Correct 32 ms 33412 KB Output is correct
14 Correct 27 ms 33396 KB Output is correct
15 Correct 27 ms 33412 KB Output is correct
16 Correct 24 ms 33408 KB Output is correct
17 Correct 25 ms 33356 KB Output is correct
18 Correct 28 ms 33408 KB Output is correct
19 Correct 27 ms 33412 KB Output is correct
20 Correct 27 ms 33412 KB Output is correct
21 Correct 35 ms 33928 KB Output is correct
22 Correct 27 ms 33932 KB Output is correct
23 Correct 34 ms 33988 KB Output is correct
24 Correct 27 ms 33996 KB Output is correct
25 Correct 33 ms 33912 KB Output is correct
26 Correct 38 ms 33908 KB Output is correct
27 Correct 32 ms 34684 KB Output is correct
28 Correct 33 ms 34688 KB Output is correct
29 Correct 37 ms 34432 KB Output is correct
30 Correct 30 ms 34008 KB Output is correct
31 Correct 27 ms 33924 KB Output is correct
32 Correct 27 ms 33920 KB Output is correct
33 Correct 30 ms 34028 KB Output is correct
34 Incorrect 10 ms 192 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 424 ms 96596 KB Output is correct
2 Correct 417 ms 97304 KB Output is correct
3 Correct 417 ms 97292 KB Output is correct
4 Correct 386 ms 97320 KB Output is correct
5 Runtime error 6 ms 192 KB Execution killed with signal 13
6 Halted 0 ms 0 KB -