跳到正文

个人记录

机房第一次测试讲评

玩玩就好7744约 21 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 21 分钟

版本

  1. v1当前

赛时实况

8:00:00 \quad 比赛开始

8:46:56 \quad 比赛首次提交,提交人:邬健翔

8:46:56 \quad T2首次提交,提交人:邬健翔

9:00:00 \quad 处理了可以看到分数的问题

9:56:49 \quad T3首次提交,提交人:蔡智勋

10:10:00 \quad 处理了T3大数据太弱的问题

10:22:41 \quad T1首次提交,提交人:蔡智勋

11:27:50 \quad 比赛首次AC,提交人:蔡智勋

11:27:50 \quad T1首次AC,提交人:蔡智勋

11:30:00 \quad T3新增一组大样例

11:57:34 \quad T3首次AC,提交人:吴鎏亿

11:59:59 \quad 比赛最后一次提交,提交人:蔡智勋

成绩

姓名T1T2T3总分Rank
蔡智勋10070201901
吴鎏亿0701001702
洛韬20700903
邬健翔07020903
张美湖07020903

T1 游戏

原题:CF15C 稍加改编

subtask1:

直接暴力搜索

subtask2:

爆索+剪枝应该也可以过

subtask3:

只要你发现了这道题是一个Nim博弈,那就一定可以做出来的!

subtask4:

我们发现Nim博弈过subtask3的复杂度是O(Tn)O(Tn)的,对于subtask4的数据范围是显然不可以接受的,所以我们有以下的思考过程:

首先,这是一个博弈论的题目,而且明显是Nim博弈,所以思路应该还是延续subtask3的思路,并且改进复杂度。

对于复杂度的提供O(T)O(T)显然是必须的,那么我们应该着重对O(n)O(n)的那一部分下手。

我们考虑到我们实际上求的是x⊕x+1⊕x+2⊕......⊕x+n−1x \oplus x + 1 \oplus x + 2 \oplus...... \oplus x + n - 1,我们可以很自然的联想到如果我们可以对这一坨东西进行一个前缀和求和,那么自然可以在O(1)O(1)的时间内求出来。

但是我们会发现数据范围 也不允许我们预处理前缀和。

但是

如果你愿意手玩一下数据

你会发现这样一个性质:

求0⊕1⊕2⊕......⊕x−1⊕x0 \oplus1 \oplus 2 \oplus ...... \oplus x - 1 \oplus x时:

ans={xx%4==01x%4==1x+1x%4==20x%4==3ans=\left\{ \begin{aligned} x & \quad x \% 4 == 0\\ 1 & \quad x \%4 == 1\\ x + 1 & \quad x \% 4 == 2\\ 0 & \quad x \%4 == 3 \end{aligned} \right.

那么我们现在就可以O(1)O(1)求出后面这一坨了,现在程序的时间复杂度显然是O(T)O(T)

code

C++
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<climits>
#include<sstream>
using namespace std;
#define int long long

inline int read()
{
    char c;
    int flag = 1;
    while ((c = getchar()) < '0' || c > '9')
    {
        if (c == '-')
        {
            flag = -1;
        }
    }
    int count = c - '0';
    while ((c = getchar()) >= '0' && c <= '9')
    {
        count *= 10;
        count += c - '0';
    }
    return count * flag;
}

inline void print(int x)
{
    if (x < 0)
    {
        x = -x;
        putchar('-');
    }
    if (x > 9)
    {
        print(x / 10);
    }
    putchar(x % 10 + '0');
}

inline int pre(int x)
{
    if (x % 4 == 0)
    {
        return x;
    }
    if (x % 4 == 1)
    {
        return 1;
    }
    if (x % 4 == 2)
    {
        return x + 1;
    }
    if (x % 4 == 3)
    {
        return 0;
    }
    return 0;
}

const int Mod = 1e9 + 7;

inline int pow(int a, int b, int c)
{
    int ans = 1;
    while (b)
    {
        if (b & 1)
        {
            ans *= a;
            ans %= c;
        }
        a *= a;
        a %= c;
        b >>= 1;
    }
    return ans;
}

signed main()
{
    int n = read();
    int zzz = 0, xrq = 0;
    for (register int i = 1; i <= n; i++)
    {
        int m = read(), x = read();
        int count = pre(x + m - 1) ^ pre(x - 1);
        if (count == 0)
        {
            zzz++;
        }
        else
        {
            xrq++;
        }
    }
    if (xrq == 0)
    {
        cout << "zzz is over!";
    }
    else
    {
        int inv = pow(xrq, Mod - 2, Mod);
        int ans = zzz * inv;
        ans %= Mod;
        cout << ans;
    }
    return 0;
}

T2 三角关系

原题:P4722

首先我们确定最小割=最大流,然后就可以愉快的做题了!

subtask1+subtask2:

直接最大流。

subtask3:

考虑最大流的Dinic算法复杂度是O(n2m)O(n^2m)所以肯定会T掉。

我们只需要使用其他的最大流算法就可以了啊!详情参考原题。

code

C++
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<climits>
#include<sstream>
#include<fstream>
using namespace std;
#include<queue>
#include<vector>
#define int long long

inline int read()
{
	char c;
	int flag = 1;
	while ((c = getchar()) < '0' || c > '9')
	{
		if (c == '-')
		{
			flag = -1;
		}
	}
	int count = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
	{
		count *= 10;
		count += c - '0';
	}
	return count * flag;
}

inline void print(int x)
{
	if (x < 0)
	{
		x = -x;
		putchar('-');
	}
	if (x > 9)
	{
		print(x / 10);
	}
	putchar(x % 10 + '0');
}

const int N = 1210;
const int M = 3e5 + 10;

int head[N], net[M], vis[M], wigh[M];
int tot = 1;

inline void add(int u, int v, int w)
{
	tot++;
	net[tot] = head[u];
	head[u] = tot;
	vis[tot] = v;
	wigh[tot] = w;
}

int h[N];

queue<int> q;

inline bool bfs(int n, int s, int t)
{
	fill(h + 1, h + n + 1, 1e9);
	h[t] = 0;
	q.push(t);
	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		for (register int i = head[u]; i; i = net[i])
		{
			int v = vis[i];
			int w = wigh[i ^ 1];
			if (w && h[v] > h[u] + 1)
			{
				h[v] = h[u] + 1;
				q.push(v);
			}
		}
	}
	return h[s] != 1e9;
}

int gap[M];
int inq[M];
int e[M];

struct cmp
{
	inline bool operator() (int a, int b) const
	{
		return h[a] < h[b];
	}
};

priority_queue<int, vector<int>, cmp> qq;

inline void push(int u, int s, int t)
{
	for (register int i = head[u]; i; i = net[i])
	{
		int v = vis[i];
		int w = wigh[i];
		if (w && h[v] + 1 == h[u])
		{
			int d = min(e[u], w);
			wigh[i] -= d;
			wigh[i ^ 1] += d;
			e[u] -= d;
			e[v] += d;
			if (v != s && v != t && !inq[v])
			{
				qq.push(v);
				inq[v] = 1;
			}
			if (e[u] == 0)
			{
				break;
			}
		}
	}
	return;
}

inline void rev(int u)
{
	h[u] = 1e9;
	for (register int i = head[u]; i; i = net[i])
	{
		int v = vis[i];
		int w = wigh[i];
		if (w && h[v] + 1 < h[u])
		{
			h[u] = h[v] + 1;
		}
	}
	return;
}

signed main()
{
	int n, m, s, t;
	n = read(), m = read(), s = read(), t = read();
	for(register int i = 1 ; i <= m ; i++)
	{
		int u = read(), v = read(), w = read();
		add(u, v, w);
		add(v, u, 0);
	}
	if (bfs(n, s, t) == 0)
	{
		print(0);
		return 0;
	}
	h[s] = n;
	for (register int i = 1; i <= n; i++)
	{
		if (h[i] < 1e9)
		{
			gap[h[i]]++;
		}
	}
	for (register int i = head[s]; i; i = net[i])
	{
		int v = vis[i];
		int w = wigh[i];
		if (w)
		{
			wigh[i] -= w;
			wigh[i ^ 1] += w;
			e[s] -= w;
			e[v] += w;
			if (v != s && v != t && inq[v] == 0)
			{
				qq.push(v);
				inq[v] = 1;
			}
		}
	}
	while (!qq.empty())
	{
		int u = qq.top();
		inq[u] = 0;
		qq.pop();
		push(u, s, t);
		if (e[u])
		{
			gap[h[u]]--;
			if (gap[h[u]] == 0)
			{
				for (register int i = 1; i <= n; i++)
				{
					if (i != s && i != t && h[i] > h[u] && h[i] < n + 1)
					{
						h[i] = n + 1;
					}
				}
			}
			rev(u);
			gap[h[u]]++;
			qq.push(u);
			inq[u] = 1;
		}
	}
	print(e[t]);
	return 0;
}

T3 追求

原题:P4592

subtask1:

直接暴力。

subtask2:

因为是一条链,所以可以直接转化为问题: P4735 最大异或和。

那么很显然就是用可持久化Trie来做了。

subtask3:

考虑到这个询问实在是太像树链剖分了,而且树链剖分的实质就是对于一些答案可以分段求得的书上问题转化为线段问题。

那么很显然就是一个树剖,然后再用可持久化线段树进行处理就好了。

code

C++
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<climits>
#include<sstream>
#include<fstream>
using namespace std;
#define int long long

inline int read()
{
	char c;
	int flag = 1;
	while ((c = getchar()) < '0' || c > '9')
	{
		if (c == '-')
		{
			flag = -1;
		}
	}
	int count = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
	{
		count *= 10;
		count += c - '0';
	}
	return count * flag;
}

inline void print(int x)
{
	if (x < 0)
	{
		x = -x;
		putchar('-');
	}
	if (x > 9)
	{
		print(x / 10);
	}
	putchar(x % 10 + '0');
}

const int N = 2e5 + 10;
const int M = 1e7 + 10;

struct Tree
{
	int ls;
	int rs;
	int lazy;
}tree[M];
int tot = 0;

inline int clone()
{
	tot++;
	return tot;
}

inline void insert(int p1, int p2, int dep, int x, int p)
{
	for (register int i = dep; i >= 0; i--)
	{
		int a = (x >> i) & 1;
		if (p2)
		{
			if (a == 0)
			{
				tree[p1].rs = tree[p2].rs;
			}
			else
			{
				tree[p1].ls = tree[p2].ls;
			}
		}
		if (a == 0)
		{
			tree[p1].ls = clone();
			p1 = tree[p1].ls;
			p2 = tree[p2].ls;
		}
		else
		{
			tree[p1].rs = clone();
			p1 = tree[p1].rs;
			p2 = tree[p2].rs;
		}
		tree[p1].lazy = p;
	}
	tree[p1].lazy = p;
}

int s[N];

inline int query(int p, int dep, int x, int l)
{
	for (register int i = dep; i >= 0; i--)
	{
		int a = (x >> i) & 1;
		if (a == 0)
		{
			if (tree[tree[p].rs].lazy >= l)
			{
				p = tree[p].rs;
			}
			else
			{
				p = tree[p].ls;
			}
		}
		else
		{
			if (tree[tree[p].ls].lazy >= l)
			{
				p = tree[p].ls;
			}
			else
			{
				p = tree[p].rs;
			}
		}
		//cout << p << endl;
	}
	return x ^ s[tree[p].lazy];
}

int head[N], net[N << 1], vis[N << 1];
int cnt = 1;

inline void add(int u, int v)
{
	cnt++;
	net[cnt] = head[u];
	head[u] = cnt;
	vis[cnt] = v;
}

int siz[N], dep[N], son[N], father[N];
int a[N];

inline void dfs(int u, int fa)
{
	siz[u] = 1;
	dep[u] = dep[fa] + 1;
	father[u] = fa;
	for (register int i = head[u]; i; i = net[i])
	{
		int v = vis[i];
		if (v == fa)
		{
			continue;
		}
		dfs(v, u);
		siz[u] += siz[v];
		if (siz[son[u]] < siz[v])
		{
			son[u] = v;
		}
	}
}

int top[N], seg[N], rev[N];

inline void dfs(int u)
{
	if (son[u])
	{
		seg[0]++;
		seg[son[u]] = seg[0];
		rev[seg[0]] = son[u];
		top[son[u]] = top[u];
		dfs(son[u]);
	}
	for (register int i = head[u]; i; i = net[i])
	{
		int v = vis[i];
		if (top[v])
		{
			continue;
		}
		seg[0]++;
		seg[v] = seg[0];
		rev[seg[0]] = v;
		top[v] = v;
		dfs(v);
	}
}

int root[N];

inline int query_way(int x, int y, int z)
{
	int ans = 0;
	while (top[x] != top[y])
	{
		if (dep[top[x]] < dep[top[y]])
		{
			swap(x, y);
		}
		//cout << seg[top[x]] << " " << seg[x] << endl;
		ans = max(ans, query(root[seg[x]], 31, z, seg[top[x]]));
		x = father[top[x]];
	}
	if (dep[x] > dep[y])
	{
		swap(x, y);
	}
	//cout << seg[y] << " " << seg[x] << endl;
	ans = max(ans, query(root[seg[y]], 31, z, seg[x]));
	return ans;
}

inline int query_son(int p, int z)
{
	return query(root[seg[p] + siz[p] - 1], 31, z, seg[p]);
}

signed main()
{
	int n, m;
	n = read(), m = read();
	for (register int i = 1; i <= n; i++)
	{
		a[i] = read();
	}
	for (register int i = 1; i <= n - 1; i++)
	{
		int u = read(), v = read();
		add(u, v);
		add(v, u);
	}
	dfs(1, 0);
	seg[0] = seg[1] = top[1] = rev[1] = 1;
	dfs(1);
	tree[0].lazy = -1;
	root[0] = clone();
	for (register int i = 1; i <= seg[0]; i++)
	{
		root[i] = clone();
		s[i] = a[rev[i]];
		insert(root[i], root[i - 1], 31, s[i], i);
	}
	for (register int i = 1; i <= m; i++)
	{
		int c = read();
		if (c == 2)
		{
			int x = read(), y = read(), z = read();
			print(query_way(x, y, z));
			putchar('\n');
		}
		else
		{
			int p = read(), z = read();
			print(query_son(p, z));
			putchar('\n');
		}
	}
	return 0;
}

PS: 就这分数,lt的幸福无望啊!

原文