QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#813#556879#8671. 分流器-xcxxx-jiamengtongFailed.2024-09-11 08:45:312024-09-11 08:45:31

詳細信息

Extra Test:

Invalid Input

input:

50
47 4
44 9
19 24
46 11
10 51
31 41
8 18
43 39
46 49
19 44
49 27
45 22
45 35
34 51
16 17
36 32
46 41
49 20
46 40
25 28
37 29
33 45
27 42
28 33
26 29
42 28
41 49
48 33
44 48
38 47
45 39
50 34
37 50
41 40
47 39
41 39
46 50
49 47
49 49
44 51
48 44
45 48
51 50
50 50
49 46
47 51
50 50
50 51
50 50
51 51

output:


result:

FAIL Condition failed: "ind[i] >= 1"

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#556879#8671. 分流器jiamengtong100 ✓168ms316432kbC++141.0kb2024-09-10 21:50:272024-09-10 21:50:28

answer

#include<bits/stdc++.h>
#define M 50005
using namespace std;
using ull = unsigned long long;
int n, ans[M];
ull hp[M][800];
void add(int x, int y)
{
	for(int i = 0; i <= n / 63; i++)
	{
		hp[y][i] += (hp[x][i] >> 1);
		if(hp[x][i + 1] & 1) hp[y][i] += (1ull << 62);
		if(hp[y][i] >> 63) hp[y][i + 1]++, hp[y][i] ^= (1ull << 63);
	}
}
int ctz(int i)
{
	for(int j = 0; j <= n / 63; j++) if(hp[i][j]) return j * 63 + __builtin_ctzll(hp[i][j]);
}
int main()
{
	scanf("%d", &n);
	hp[1][n / 63] = 1ull << (n % 63);
	int minn = n;
	for(int i = 1, x; i <= n; i++)
	{
		scanf("%d", &x), add(i, x);
		scanf("%d", &x), add(i, x);
		minn = min(minn, ctz(i));
	}
	int pw = n - minn + 1;
	ans[0] = 1;
	int tot = 1;
	while(pw)
	{
		int nt = min(pw, 25);
		pw -= nt;
		for(int i = 0; i < tot; i++) ans[i] <<= nt;
		for(int i = 0; i < tot; i++) ans[i + 1] += ans[i] / 10, ans[i] %= 10;
		while(ans[tot]) ans[tot + 1] += ans[tot] / 10, ans[tot] %= 10, tot++;
	}
	for(int i = tot - 1; i >= 0; i--) printf("%d", ans[i]);
	return 0;
}