QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#95946 | #6127. Kawa Exam | CSU2023 | AC ✓ | 336ms | 22292kb | C++14 | 4.9kb | 2023-04-12 17:16:40 | 2023-04-12 17:16:41 |
Judging History
answer
#include <bits/stdc++.h>
template <class T>
inline void read(T &res)
{
char ch; bool flag = false; res = 0;
while (ch = getchar(), !isdigit(ch) && ch != '-');
ch == '-' ? flag = true : res = ch ^ 48;
while (ch = getchar(), isdigit(ch))
res = res * 10 + ch - 48;
flag ? res = -res : 0;
}
template <class T>
inline void put(T x)
{
if (x > 9)
put(x / 10);
putchar(x % 10 + 48);
}
template <class T>
inline void _put(T x)
{
if (x < 0)
x = -x, putchar('-');
put(x);
}
template <class T>
inline void CkMin(T &x, T y) {x > y ? x = y : 0;}
template <class T>
inline void CkMax(T &x, T y) {x < y ? x = y : 0;}
template <class T>
inline T Min(T x, T y) {return x < y ? x : y;}
template <class T>
inline T Max(T x, T y) {return x > y ? x : y;}
template <class T>
inline T Abs(T x) {return x < 0 ? -x : x;}
template <class T>
inline T Sqr(T x) {return x * x;}
// 若传入 int x 同时结果可能爆 int 应这样写 Sqr((ll)x)
using std::map;
using std::set;
using std::pair;
using std::bitset;
using std::string;
using std::vector;
using std::complex;
using std::multiset;
using std::priority_queue;
typedef long long ll;
typedef long double ld;
typedef complex<ld> com;
typedef pair<int, int> pir;
const ld pi = acos(-1.0);
const ld eps = 1e-8;
const int Maxn = 1e9;
const int Minn = -1e9;
const int mod = 998244353;
const int N = 1e5 + 5;
const int M = 2e5 + 5;
vector<int> v[N];
int tot_ans, n, m, C, V, tis, T_data, T = 1, _ans;
int ans[N], in_ans[N], out_ans[N], col[N], cnt[N], num[N];
int down[N], son[N], pos[N], idx[N], sze[N];
int a[N], nxt[M], to[M], adj[N];
int up[N], dfn[N], low[N];
bool bridge[M], tree[M], vis[N];
inline void linkArc(int x, int y)
{
nxt[++T] = adj[x]; adj[x] = T; to[T] = y;
nxt[++T] = adj[y]; adj[y] = T; to[T] = x;
}
inline void Tarjan(int x)
{
dfn[x] = low[x] = ++tis;
int y;
for (int e = adj[x]; e; e = nxt[e])
{
if (e == (up[x] ^ 1))
continue;
if (!dfn[y = to[e]])
{
up[y] = e;
Tarjan(y);
CkMin(low[x], low[y]);
if (dfn[x] < low[y])
bridge[e ^ 1] = bridge[e] = true;
}
else
CkMin(low[x], dfn[y]);
}
}
inline void dfs(int x)
{
col[x] = C;
pos[x] = ++V;
idx[V] = x;
int y;
sze[x] = 1;
for (int e = adj[x]; e; e = nxt[e])
if (!col[y = to[e]])
{
tree[e] = true;
if (bridge[e])
down[e >> 1] = y;
dfs(y);
sze[x] += sze[y];
sze[y] > sze[son[x]] ? son[x] = y : 0;
}
}
inline void addCnt(int x)
{
if (cnt[x] > 0)
--num[cnt[x]];
++num[++cnt[x]];
CkMax(_ans, cnt[x]);
}
inline void decCnt(int x)
{
if (--num[cnt[x]] == 0 && _ans == cnt[x])
--_ans;
--cnt[x];
if (cnt[x] > 0)
++num[cnt[x]];
}
inline void addSubtree(int x)
{
for (int i = pos[x]; i <= pos[x] + sze[x] - 1; ++i)
addCnt(a[idx[i]]);
}
inline void decSubtree(int x)
{
for (int i = pos[x]; i <= pos[x] + sze[x] - 1; ++i)
decCnt(a[idx[i]]);
}
inline void dfsTraverse(int x)
{
vis[x] = true;
for (int y : v[x])
{
if (y == son[x])
continue ;
dfsTraverse(y);
decSubtree(y);
}
if (son[x])
dfsTraverse(son[x]);
addCnt(a[x]);
for (int y : v[x])
{
if (y == son[x])
continue ;
addSubtree(y);
}
in_ans[x] = _ans;
// std::cout << "(" << x << " " << _ans << std::endl;
}
inline void dfsTraverse2(int x)
{
for (int y : v[x])
{
if (y == son[x])
continue ;
dfsTraverse2(y);
addSubtree(y);
}
if (son[x])
dfsTraverse2(son[x]);
decCnt(a[x]);
for (int y : v[x])
{
if (y == son[x])
continue ;
decSubtree(y);
}
out_ans[x] = _ans;
// std::cout << ")" << x << " " << _ans << std::endl;
}
int main()
{
read(T_data);
while (T_data--)
{
read(n); read(m);
C = tot_ans = tis = V = 0;
for (int i = 1; i <= n; ++i)
read(a[i]);
for (int i = 1, u, v; i <= m; ++i)
{
read(u); read(v);
linkArc(u, v);
}
for (int i = 1; i <= n; ++i)
if (!dfn[i])
Tarjan(i);
for (int i = 1; i <= n; ++i)
if (!col[i])
{
++C;
dfs(i);
}
for (int i = 1; i <= n; ++i)
for (int e = adj[i]; e; e = nxt[e])
if (tree[e])
v[i].emplace_back(to[e]);
for (int i = 1; i <= n; ++i)
if (!vis[i])
{
dfsTraverse(i);
ans[col[i]] = _ans;
tot_ans += _ans;
dfsTraverse2(i);
}
for (int i = 1; i <= m; ++i)
{
if (bridge[i << 1])
put(tot_ans - ans[col[down[i]]] + in_ans[down[i]] + out_ans[down[i]]);
else
put(tot_ans);
putchar(i < m ? ' ' : '\n');
}
for (int i = 1; i <= T; ++i)
bridge[i] = tree[i] = false;
T = 1;
for (int i = 1; i <= n; ++i)
{
v[i].clear();
ans[i] = in_ans[i] = out_ans[i] = 0;
dfn[i] = low[i] = 0;
up[i] = down[i] = col[i] = adj[i] = sze[i] = son[i] = pos[i] = idx[i] = 0;
vis[i] = false;
}
}
}
/*
3
7 5
1 2 1 2 1 2 1
1 2
1 3
2 4
5 6
5 7
3 3
1 2 3
1 2
1 3
2 3
2 3
12345 54321
1 2
1 2
1 1
*/
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 8956kb
input:
3 7 5 1 2 1 2 1 2 1 1 2 1 3 2 4 5 6 5 7 3 3 1 2 3 1 2 1 3 2 3 2 3 12345 54321 1 2 1 2 1 1
output:
6 5 5 5 4 1 1 1 1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 336ms
memory: 22292kb
input:
5557 2 7 79960 79960 2 2 1 1 1 1 2 2 1 1 2 1 1 2 9 8 21881 70740 70740 21881 22458 22458 639 21881 70740 3 3 1 6 5 8 7 5 5 7 2 3 5 1 7 6 6 7 13064 20716 6746 13064 6746 69225 5 5 4 1 4 1 1 6 4 5 3 2 3 2 8 4 45146 14400 45146 45146 14400 72969 14400 45146 8 6 1 3 4 6 8 3 18 13 48132 37949 92338 92338...
output:
2 2 2 2 2 2 2 6 6 7 6 6 6 6 6 3 3 3 4 4 3 3 7 7 7 7 9 9 9 8 9 8 9 8 9 9 10 9 9 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 9 10 9 16 16 16 16 16 17 16 16 10 10 11 10 12 11 10 10 10 10 10 10 10 12 10 10 10 10 10 11 10 9 9 9 9 9 9 9 9 9 9 9 9 9 10 ...
result:
ok 5557 lines
Test #3:
score: 0
Accepted
time: 157ms
memory: 16560kb
input:
10 100000 99999 3983 3983 20157 97983 20157 20157 3983 3983 97983 20157 20157 3983 97983 20157 3983 20157 20157 3983 3983 3983 97983 97983 20157 3983 3983 97983 20157 97983 20157 97983 3983 97983 97983 3983 20157 3983 20157 20157 97983 3983 3983 3983 3983 97983 97983 3983 97983 97983 3983 20157 3983...
output:
33392 33393 33393 33393 33393 33392 33392 33393 33393 33393 33392 33393 33393 33392 33393 33393 33392 33392 33392 33393 33393 33393 33392 33392 33393 33393 33393 33393 33393 33392 33393 33393 33392 33393 33392 33393 33393 33393 33392 33392 33392 33392 33393 33393 33392 33393 33393 33392 33393 33392 ...
result:
ok 10 lines
Test #4:
score: 0
Accepted
time: 161ms
memory: 16688kb
input:
10 100000 99999 27534 27534 3780 3780 27534 53544 27534 3780 3780 53544 53544 27534 53544 53544 3780 3780 3780 3780 53544 27534 3780 3780 53544 27534 27534 53544 27534 27534 53544 27534 27534 27534 3780 27534 27534 3780 3780 3780 27534 53544 3780 53544 27534 3780 3780 3780 27534 27534 27534 3780 275...
output:
33613 33601 33601 33600 33600 33601 33601 33601 33600 33601 33600 33600 33601 33601 33601 33601 33601 33601 33600 33600 33601 33601 33601 33601 33600 33601 33601 33600 33601 33600 33601 33600 33601 33601 33601 33601 33600 33601 33601 33601 33601 33601 33601 33601 33601 33601 33600 33601 33600 33601 ...
result:
ok 10 lines
Test #5:
score: 0
Accepted
time: 186ms
memory: 16420kb
input:
10 100000 99999 92499 92270 92270 92499 92499 92499 92270 54017 92270 92270 92270 54017 54017 54017 54017 92270 92499 54017 92270 54017 92499 92499 92270 92270 54017 54017 54017 54017 92270 92270 92499 54017 54017 92499 92499 54017 92270 92270 54017 92499 92270 92270 54017 54017 54017 92499 92499 54...
output:
33506 33482 33507 33482 33508 33483 33508 33483 33508 33483 33507 33483 33506 33483 33505 33483 33503 33483 33503 33482 33504 33483 33505 33483 33504 33483 33502 33483 33501 33483 33500 33482 33502 33483 33500 33483 33501 33482 33502 33483 33501 33483 33500 33482 33500 33483 33498 33483 33499 33483 ...
result:
ok 10 lines
Test #6:
score: 0
Accepted
time: 165ms
memory: 16292kb
input:
10 100000 99999 76207 76207 88551 88551 98176 76207 98176 88551 88551 98176 88551 76207 76207 98176 98176 76207 76207 88551 76207 88551 76207 88551 88551 76207 88551 76207 98176 88551 76207 98176 88551 88551 76207 88551 98176 88551 76207 76207 98176 88551 76207 98176 76207 88551 88551 88551 88551 76...
output:
33484 33484 33476 33484 33477 33485 33476 33485 33477 33485 33477 33486 33477 33484 33477 33485 33476 33485 33476 33485 33476 33483 33477 33483 33477 33485 33476 33485 33477 33485 33476 33487 33476 33487 33476 33486 33477 33486 33476 33486 33477 33486 33476 33486 33476 33486 33477 33487 33477 33487 ...
result:
ok 10 lines
Test #7:
score: 0
Accepted
time: 188ms
memory: 15252kb
input:
10 100000 99999 70486 49904 70486 49904 87935 49904 49904 87935 87935 49904 49904 87935 49904 87935 87935 70486 49904 87935 87935 49904 70486 87935 49904 70486 87935 87935 49904 49904 49904 87935 70486 70486 70486 49904 70486 87935 87935 87935 70486 87935 70486 49904 87935 49904 49904 87935 70486 87...
output:
33491 33486 33489 33486 33489 33486 33489 33486 33487 33486 33487 33486 33486 33485 33486 33486 33486 33486 33485 33486 33485 33485 33486 33486 33485 33486 33485 33486 33485 33485 33485 33486 33485 33486 33485 33486 33485 33486 33485 33486 33485 33486 33485 33486 33485 33486 33485 33485 33486 33485 ...
result:
ok 10 lines
Test #8:
score: 0
Accepted
time: 188ms
memory: 15536kb
input:
10 100000 99999 98004 33580 98004 98004 98004 92291 92291 98004 98004 92291 92291 33580 98004 92291 33580 98004 98004 33580 98004 92291 92291 33580 92291 92291 98004 33580 98004 33580 33580 98004 33580 92291 33580 33580 92291 92291 92291 98004 33580 98004 92291 92291 33580 92291 98004 98004 92291 92...
output:
33462 33463 33421 33463 33422 33465 33421 33463 33422 33464 33422 33462 33422 33464 33421 33464 33422 33464 33422 33465 33422 33463 33422 33462 33422 33463 33422 33465 33421 33464 33422 33464 33422 33463 33422 33463 33421 33463 33421 33462 33422 33460 33422 33461 33421 33461 33422 33460 33422 33459 ...
result:
ok 10 lines