답안 #117117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117117 2019-06-14T22:24:10 Z MB81 Ball Machine (BOI13_ballmachine) C++11
0 / 100
1000 ms 35316 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int> pii32;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 1e5+10;
const int lg = 18;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

set <pii> s1;
vector <int> g[maxn];
int mn[maxn], fins[maxn], fine[maxn], fen[maxn], par[maxn][lg];
int n, q;

bool cmp (int id1, int id2) {
	return (mn[id1] < mn[id2]);
}

void upd (int x, int val) {
	for (; x < maxn; x += x&-x)
		fen[x] += val;
	return;
}

int get (int x) { 
	int res = 0;
	for (; x; x -= x&-x)
		res += fen[x];
	return res;
}

int dfs0 (int v) {
	mn[v] = IN;
	for (auto u : g[v])
		mn[v] = min(mn[v], dfs0(u));
	sort(all(g[v]), cmp);
	mn[v] = min(mn[v], v);
	return mn[v];
}

int dfs (int v, int ftime = 1, int parent = -1) {
	par[v][0] = parent;
	fins[v] = ftime;
	for (int i = 1; i < lg; i++)
		if (par[v][i - 1] + 1)
			par[v][i] = par[par[v][i - 1]][i - 1];
	for (auto u : g[v])
		ftime = dfs(u, ftime, v);
	fine[v] = ftime;
	return ftime + 1;
}

int getver (int v, int k) {
	for (int i = lg - 1; i >= 0; i--)
		if (k <= (1 << i)) {
			v = par[v][i];
			k -= (1 << i);
		}
	return v;
}

void del (int v) {
	upd(fins[v], -1);
	upd(fine[v], 1);
	s1.insert(MP(fine[v], v));
	return;
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	int r = -1;
	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		--p;
		if (p == -1)
			r = i;
		else
			g[p].PB(i);
	}
	memset(par, -1, sizeof par);
	dfs0(r);
	dfs(r);
	for (int i = 0; i < n; i++)
		s1.insert(MP(fine[i], i));
	for (int i = 0; i < q; i++) {
		int type, k, v, ans = -85;
		cin >> type;
		if (type == 1) {
			cin >> k;
			for (int t = 0; t < k; t++) {
				int v = s1.begin()->S;
				ans = v;
				s1.erase(*s1.begin());
				upd(fins[v], 1);
				upd(fine[v], -1);
			}
			cout << ans + 1 << "\n";
		}
		if (type == 2) {
			cin >> v;
			--v;
			cout << get(fine[v]) << "\n";
			del(getver(v, get(fine[v])));
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 21 ms 19328 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Execution timed out 1085 ms 15352 KB Time limit exceeded
3 Runtime error 76 ms 29788 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 21 ms 19448 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 20 ms 19328 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 22 ms 19584 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Incorrect 11 ms 9984 KB Output isn't correct
8 Incorrect 12 ms 9856 KB Output isn't correct
9 Incorrect 16 ms 10112 KB Output isn't correct
10 Runtime error 33 ms 22264 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Incorrect 123 ms 16336 KB Output isn't correct
12 Runtime error 74 ms 29688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Incorrect 113 ms 16632 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 13428 KB Output isn't correct
2 Incorrect 223 ms 23196 KB Output isn't correct
3 Execution timed out 1073 ms 17780 KB Time limit exceeded
4 Incorrect 81 ms 14328 KB Output isn't correct
5 Incorrect 78 ms 14328 KB Output isn't correct
6 Incorrect 75 ms 14440 KB Output isn't correct
7 Incorrect 72 ms 13816 KB Output isn't correct
8 Incorrect 51 ms 13432 KB Output isn't correct
9 Incorrect 398 ms 23292 KB Output isn't correct
10 Incorrect 224 ms 23100 KB Output isn't correct
11 Incorrect 204 ms 23160 KB Output isn't correct
12 Incorrect 193 ms 21244 KB Output isn't correct
13 Incorrect 173 ms 25084 KB Output isn't correct
14 Execution timed out 1080 ms 17776 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Incorrect 79 ms 16504 KB Output isn't correct
2 Incorrect 191 ms 21480 KB Output isn't correct
3 Incorrect 161 ms 23544 KB Output isn't correct
4 Incorrect 134 ms 20216 KB Output isn't correct
5 Incorrect 150 ms 20100 KB Output isn't correct
6 Incorrect 139 ms 20088 KB Output isn't correct
7 Incorrect 139 ms 18908 KB Output isn't correct
8 Incorrect 151 ms 23416 KB Output isn't correct
9 Incorrect 200 ms 23436 KB Output isn't correct
10 Incorrect 202 ms 23032 KB Output isn't correct
11 Incorrect 212 ms 23172 KB Output isn't correct
12 Incorrect 215 ms 21496 KB Output isn't correct
13 Incorrect 220 ms 27256 KB Output isn't correct
14 Runtime error 120 ms 35316 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1070 ms 21952 KB Time limit exceeded
2 Incorrect 226 ms 21552 KB Output isn't correct
3 Incorrect 242 ms 26780 KB Output isn't correct
4 Execution timed out 1080 ms 21880 KB Time limit exceeded
5 Incorrect 212 ms 23140 KB Output isn't correct
6 Incorrect 215 ms 23160 KB Output isn't correct
7 Incorrect 204 ms 21496 KB Output isn't correct
8 Incorrect 206 ms 26748 KB Output isn't correct
9 Runtime error 94 ms 34672 KB Execution killed with signal 11 (could be triggered by violating memory limits)