QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#602740 | #8716. 树 | ITC_TL# | Compile Error | / | / | C++20 | 3.4kb | 2024-10-01 12:33:18 | 2024-10-01 12:33:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fore(i, l, r) for (register int i = (int)l; i <= (int)r; i++)
#define ford(i, r, l) for (register int i = (int)r; i >= (int)l; i--)
const int MAXN = 412345LL;
ll T, n, m, q, dep[MAXN];
ll hand[MAXN], to[MAXN], nxt[MAXN], tot;
ll fa[MAXN][32], b[MAXN];
ll er[MAXN];
void pre()
{
er[0] = 1;
fore(i, 1, 31) er[i] = er[i - 1] * 2;
return;
}
void add(ll x, ll y)
{
tot++;
to[tot] = y;
nxt[tot] = hand[x];
hand[x] = tot;
}
ll cen(ll x, ll y)
{
if (cen < 0)
return -1;
ford(i, 31, 0)
{
if (y >= er[i])
{
y -= er[i];
x = fa[x][i];
}
}
return x;
}
ll lca(ll x, ll y)
{
if (dep[x] < dep[y])
swap(x, y);
if (dep[x] > dep[y])
{
x = cen(x, dep[y] - dep[x]);
}
if (x == y)
return x;
ford(i, 31, 0)
{
if (fa[x][i] != fa[y][i])
x = fa[x][i], y = fa[y][i];
}
fore(i, 0, 31)
{
if (fa[x][i] == fa[y][i])
return fa[x][i];
}
}
void sou(ll t)
{
fore(i, 1, 31)
fa[t][i] = fa[fa[t][i - 1]][i - 1];
for (register int i = hand[t]; i; i = nxt[i])
{
if (!fa[to[i]][0] && to[i] != 1)
{
fa[to[i]][0] = t;
dep[to[i]] = dep[t] + 1;
sou(to[i]);
}
}
return;
}
bool nei(ll tar, ll x, ll y)
{
ll cen1 = cen(x, dep[x] - dep[tar]);
ll cen2 = cen(y, dep[y] - dep[tar]);
ll lc = lca(x, y);
if ((cen1 == tar || cen2 == tar) && dep[tar] >= dep[lc])
return 1;
return 0;
}
bool vis[MAXN];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
pre();
cin >> n >> m >> q;
ll l, r;
fore(i, 1, n - 1)
{
cin >> l >> r;
add(l, r);
add(r, l);
}
dep[1] = 1;
sou(1);
fore(i, 1, m)
{
cin >> b[i];
}
ll cnt = 1;
l = 1, r = 2;
vis[l] = 1;
fore(i, 3, m)
{
if (nei(b[r], b[l], b[i]))
{
r = i;
continue;
}
l = r;
vis[l] = 1;
r = i;
cnt++;
}
// cout << cnt << endl;
if (l != n)
vis[n] = 1, cnt++;
while (q--)
{
cin >> l >> r;
if (vis[l])
{
if (l - 1 >= 1 && vis[l - 1] == 0)
vis[l - 1] = 1, cnt++;
if (l + 1 <= n && vis[l + 1] == 0)
vis[l + 1] = 1, cnt++;
if (l - 2 >= 1 && nei(b[l - 1], r, b[l - 2]))
vis[l - 1] = 0, cnt--;
if (l + 2 <= n && nei(b[l + 1], r, b[l + 2]))
vis[l + 1] = 0, cnt--;
b[l] = r;
}
else
{
vis[l] = 1;
cnt++;
if (l - 1 >= 1 && vis[l - 1] == 0)
vis[l - 1] = 1, cnt++;
if (l + 1 <= n && vis[l + 1] == 0)
vis[l + 1] = 1, cnt++;
if (l - 2 >= 1 && nei(b[l - 1], r, b[l - 2]))
vis[l - 1] = 0, cnt--;
if (l + 2 <= n && nei(b[l + 1], r, b[l + 2]))
vis[l + 1] = 0, cnt--;
if (nei(b[l - 1], r, b[l + 1]))
vis[l] = 0, cnt--;
b[l] = r;
}
cout << cnt << endl;
}
return 0;
}
/*
5 5 3
2 1
3 2
1 4
5 1
1 5 4 2 3
1 3
5 3
3 3
*/
详细
answer.code: In function ‘void pre()’: answer.code:14:10: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister] 14 | fore(i, 1, 31) er[i] = er[i - 1] * 2; | ^ answer.code:4:41: note: in definition of macro ‘fore’ 4 | #define fore(i, l, r) for (register int i = (int)l; i <= (int)r; i++) | ^ answer.code: In function ‘long long int cen(long long int, long long int)’: answer.code:26:9: error: invalid template-argument-list 26 | if (cen < 0) | ^~~ answer.code:26:9: note: function name as the left hand operand of ‘<’ is ill-formed in C++20; wrap the function name in ‘()’ answer.code:28:10: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister] 28 | ford(i, 31, 0) | ^ answer.code:5:41: note: in definition of macro ‘ford’ 5 | #define ford(i, r, l) for (register int i = (int)r; i >= (int)l; i--) | ^ answer.code: In function ‘long long int lca(long long int, long long int)’: answer.code:48:10: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister] 48 | ford(i, 31, 0) | ^ answer.code:5:41: note: in definition of macro ‘ford’ 5 | #define ford(i, r, l) for (register int i = (int)r; i >= (int)l; i--) | ^ answer.code:53:10: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister] 53 | fore(i, 0, 31) | ^ answer.code:4:41: note: in definition of macro ‘fore’ 4 | #define fore(i, l, r) for (register int i = (int)l; i <= (int)r; i++) | ^ answer.code: In function ‘void sou(long long int)’: answer.code:61:10: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister] 61 | fore(i, 1, 31) | ^ answer.code:4:41: note: in definition of macro ‘fore’ 4 | #define fore(i, l, r) for (register int i = (int)l; i <= (int)r; i++) | ^ answer.code:63:23: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister] 63 | for (register int i = hand[t]; i; i = nxt[i]) | ^ answer.code: In function ‘int main()’: answer.code:92:10: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister] 92 | fore(i, 1, n - 1) | ^ answer.code:4:41: note: in definition of macro ‘fore’ 4 | #define fore(i, l, r) for (register int i = (int)l; i <= (int)r; i++) | ^ answer.code:100:10: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister] 100 | fore(i, 1, m) | ^ answer.code:4:41: note: in definition of macro ‘fore’ 4 | #define fore(i, l, r) for (register int i = (int)l; i <= (int)r; i++) | ^ answer.code:107:10: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister] 107 | fore(i, 3, m) | ^ answer.code:4:41: note: in definition of macro ‘fore’ 4 | #define fore(i, l, r) for (register int i = (int)l; i <= (int)r; i++) | ^ answer.code: In function ‘long long int lca(long long int, long long int)’: answer.code:58:1: warning: control reaches end of non-void function [-Wreturn-type] 58 | } | ^