QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#138889 | #6127. Kawa Exam | minhcool | AC ✓ | 2018ms | 64852kb | C++14 | 4.0kb | 2023-08-12 13:00:41 | 2023-08-12 13:00:42 |
Judging History
answer
#define local
#ifndef local
#include ""
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define save savee
#define int long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 3e5 + 5;
const int oo = 1e18 + 7, mod = 1e9 + 7;
mt19937 rng(1);
int rnd(int l, int r){
int temp = rng() % (r - l + 1);
return abs(temp) + l;
}
int n, a[N], m;
int answer[N];
vector<int> Adj[N], Adj2[N];
map<ii, int> mp;
//int answer[N];
int cnt;
int num[N], low[N];
int total, save;
int maxi1 = 0;
int cur1[N], cnt1[N];
// actually the complement of maxi1/cur1/cnt1
int maxi2 = 0;
int cur2[N], cnt2[N];
bool ck[N];
int sz[N], par[N];
void ins(int x){
cnt1[cur1[x]]--;
cur1[x]++;
cnt1[cur1[x]]++;
if(cur1[x] > maxi1) maxi1++;
cnt2[cur2[x]]--;
cur2[x]--;
cnt2[cur2[x]]++;
if(!cnt2[maxi2]) maxi2--;
}
void era(int x){
cnt2[cur2[x]]--;
cur2[x]++;
cnt2[cur2[x]]++;
if(cur2[x] > maxi2) maxi2++;
cnt1[cur1[x]]--;
cur1[x]--;
cnt1[cur1[x]]++;
if(!cnt1[maxi1]) maxi1--;
}
vector<int> nodes;
void dfs1(int u, int p){
nodes.pb(u);
cnt++;
num[u] = low[u] = cnt;
for(auto v : Adj[u]){
if(!num[v]){
Adj2[u].pb(v);
par[v] = u;
//cout << u << " " << v << "\n";
dfs1(v, u);
low[u] = min(low[u], low[v]);
if(low[v] > num[u]){
//cout << "OK " << u << " " << v << "\n";
if(mp[{u, v}] > 0) ck[mp[{u, v}]] = 1;
}
}
else if(v != p){
low[u] = min(low[u], num[v]);
}
}
}
vector<int> get_nodes;
void prep(int u){
sz[u] = 1;
for(auto v : Adj2[u]){
prep(v);
sz[u] += sz[v];
}
}
void dfs3(int u){
get_nodes.pb(u);
for(auto v : Adj2[u]) dfs3(v);
}
void dfs2(int u, bool er){
//sz[u] = 1;
ii maxi = {-1, -1};
for(auto v : Adj2[u]){
//dfs2(v);
// sz[u] += sz[v];
maxi = max(maxi, {sz[v], v});
}
if(maxi.fi >= 0){
for(auto v : Adj2[u]){
if(v != maxi.se) dfs2(v, 1);
}
dfs2(maxi.se, 0);
get_nodes.clear();
for(auto v : Adj2[u]) if(v != maxi.se) dfs3(v);
for(auto it : get_nodes) ins(a[it]);
}
ins(a[u]);
//cout << u << " " <<par[u] << " "<< mp[{u, par[u]}] << " " << maxi1 << " " << maxi2 << " " << save << "\n";
if(mp[{u, par[u]}] >= 0) answer[mp[{u, par[u]}]] = maxi1 + maxi2 - save;
if(er){
get_nodes.clear();
dfs3(u);
for(auto it : get_nodes) era(a[it]);
}
}
void init(){
for(int i = 1; i <= n; i++){
Adj[i].clear(), Adj2[i].clear();
mp.clear();
cnt = 0;
get_nodes.clear();
par[i] = 0; sz[i] = 0;
num[i] = low[i] = 0;
}
for(int i = 1; i <= m; i++) ck[i] = answer[i] = 0;
total = 0;
}
#ifdef local
void process(){
cin >> n >> m;
init();
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= m; i++){
int x, y;
cin >> x >> y;
if(x == y) continue;
if(x > y) swap(x, y);
if(mp.find({x, y}) != mp.end()) mp[{x, y}] = -1;
else{
mp[{x, y}] = mp[{y, x}] = i;
Adj[x].pb(y), Adj[y].pb(x);
}
}
for(int i = 1; i <= n; i++){
if(num[i]) continue;
nodes.clear();
dfs1(i, i);
cnt2[0] = 1e5;
for(auto it : nodes){
cnt2[cur2[a[it]]]--;
cur2[a[it]]++;
cnt2[cur2[a[it]]]++;
if(cur2[a[it]] > maxi2) maxi2++;
}
//cout << maxi2 << "\n";
save = maxi2;
total += save;
//continue;
prep(i);
//continue;
dfs2(i, 0);
for(auto it : nodes){
maxi1 = maxi2 = 0;
cur1[a[it]] = cur2[a[it]] = 0;
}
for(int j = 0; j <= nodes.size(); j++) cnt1[j] = cnt2[j] = 0;
}
for(int i = 1; i <= m; i++){
if(!ck[i]) answer[i] = 0;
//cout << ck[i] << "\n";
cout << total + answer[i];
if(i != m) cout << " ";
}
cout << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("kek.inp", "r", stdin);
//freopen("kek.out", "w", stdout);
int t;
cin >> t;
while(t--) process();
}
#endif
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 32364kb
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: 2018ms
memory: 64852kb
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: 779ms
memory: 61664kb
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: 886ms
memory: 64844kb
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: 735ms
memory: 56196kb
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: 749ms
memory: 54476kb
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: 721ms
memory: 52932kb
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: 776ms
memory: 51476kb
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