QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#148895#6127. Kawa ExamPhantomThresholdWA 1238ms54068kbC++203.8kb2023-08-23 19:58:562023-08-23 20:32:13

Judging History

你现在查看的是最新测评结果

  • [2023-08-23 20:32:13]
  • 评测
  • 测评结果:WA
  • 用时:1238ms
  • 内存:54068kb
  • [2023-08-23 19:58:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct mode
{
	map<int,int> mp;
	multiset<int> s;
	void add(int x)
	{
		int &t=mp[x];
		if(t)s.erase(s.find(t));
		t++;
		s.insert(t);
	}
	void del(int x)
	{
		int &t=mp[x];
		s.erase(s.find(t));
		t--;
		if(t)
			s.insert(t);
		else
			mp.erase(x);
	}
	void clear()
	{
		mp.clear();s.clear();
	}
	int query()
	{
		if(s.empty())return 0;
		else return *--s.end();
	}
}IN,OUT;
int main()
{
	ios_base::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		vector<int> a(n+5);
		vector<vector<pair<int,int>>> G(n+5);
		vector<tuple<int,int,int>> edges;
		vector<int> ans(m+5);
		vector<int> pa(n+5);
		function<int(int)> find=[&](int x){return pa[x]?pa[x]=find(pa[x]):x;};
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		for(int i=1;i<=m;i++)
		{
			int u,v;
			cin>>u>>v;
			G[u].emplace_back(v,i);
			G[v].emplace_back(u,i);
			edges.emplace_back(u,v,i);
			int pu=find(u),pv=find(v);
			if(pu!=pv)pa[pv]=pu;
		}
		vector<int> ins(n+5),dfn(n+5),low(n+5),bel(n+5);
		int idx=0,bcnt=0;
		stack<int> st;
		function<void(int,int)> dfs0=[&](int u,int pe)
		{
			dfn[u]=low[u]=++idx;
			st.push(u);
			ins[u]=1;
			for(auto [v,i]:G[u])
			{
				if(i==pe)continue;
				if(not ins[v])
				{
					dfs0(v,i);
					low[u]=min(low[u],low[v]);
				}
				else if(ins[v]==1)
				{
					low[u]=min(low[u],dfn[v]);
				}
			}
			if(low[u]==dfn[u])
			{
				int vv;
				++bcnt;
				do
				{
					vv=st.top();st.pop();
					bel[vv]=bcnt;
					ins[vv]=2;
				}
				while(vv!=u);
			}
		};
		for(int i=1;i<=n;i++)
		{
			if(not ins[i])
				dfs0(i,-1);
		}
		cerr<<"1111"<<endl;
		vector<map<int,int>> cnt(bcnt+5);
		vector<vector<int>> vs(bcnt+5);
		vector<int> maxx(bcnt+5);
		for(int i=1;i<=n;i++)
		{
			cnt[bel[i]][a[i]]++;
			vs[bel[i]].push_back(i);
		}
		for(int i=1;i<=n;i++)
		{
			G[i].clear();
		}
		int sum=0;
		vector<mode> temp(n+5);
		for(int i=1;i<=n;i++)
		{
			temp[find(i)].add(a[i]);
		}
		for(auto [u,v,id]:edges)
		{
			int bu=bel[u],bv=bel[v];
			if(bu==bv)continue;
			ans[id]-=temp[find(u)].query();
			G[bu].emplace_back(bv,id);
			G[bv].emplace_back(bu,id);
		}
		for(int i=1;i<=n;i++)
		{
			if(find(i)==i)
				sum+=temp[i].query();
		}
		for(int i=1;i<=m;i++)
		{
			ans[i]+=sum;
		}
		//
		vector<int> vis(bcnt+5), son(bcnt+5), siz(bcnt+5), _dfn(bcnt+5), _idfn(bcnt+5);
		int _dfi;
		function<void(int,int)>dfsson=[&](int u,int ff)
		{
			_dfn[u]=++_dfi;
			_idfn[_dfi]=u;
			vis[u]=1;
			
			siz[u]=1;
			son[u]=0;
			for(auto [y,i]:G[u]) if(y!=ff)
			{
				dfsson(y,u);
				siz[u]+=siz[y];
				if( siz[son[u]]<siz[y] ) son[u]=y;
			}
		};
		function<void(int,int)> dfssub=[&](int u,int fid)
		{
			int si=0;
			for(auto [y,i]:G[u]) 
			{
				if(i!=fid && y!=son[u])
				{
					dfssub(y,i);
					for(int j=_dfn[y]+1;j<_dfn[y]+siz[y];j++)
					{
						int p= _idfn[j];
						for(auto col:vs[p])
							IN.del( a[col] ),
							OUT.add( a[col] );
					}
				}
				if(y==son[u]) si=i;
			}
			if(son[u])
			{
				dfssub(son[u],si);
				for(auto [y,i]:G[u]) if(i!=fid && y!=son[u])
				{
					for(int j=_dfn[y]+1;j<_dfn[y]+siz[y];j++)
					{
						int p= _idfn[j];
						for(auto col:vs[p])
							IN.add( a[col] ),
							OUT.del( a[col] );
					}
				}
			}
			for(auto col:vs[u])
				IN.add( a[col] ),OUT.del( a[col] );
				
			ans[fid]+=IN.query()+OUT.query();
		};
		for(int i=1;i<=bcnt;i++)
		{
			if(not vis[i])
			{
				IN.clear();OUT.clear();
				_dfi=0;
				dfsson(i,0);
				for(int j=_dfn[i];j<_dfn[i]+siz[i];j++)
				{
					int p=_idfn[j];
					for(auto col:vs[p])
						OUT.add(a[col]);
				}
				dfssub(i,0);
			}
		}
		for(int i=1;i<=m;i++)
		{
			cout<<ans[i]<<" \n"[i==m];
		}
	}
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3556kb

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: -100
Wrong Answer
time: 1238ms
memory: 54068kb

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
11 10 11 10 12 11 10 10 10 10 10 10 10 12 10 10 10 10 10 11
10 9 9 9 9 10 9 9 9 9 9 9 9 9 10...

result:

wrong answer 12th lines differ - expected: '10 10 11 10 12 11 10 10 10 10 10 10 10 12 10 10 10 10 10 11', found: '11 10 11 10 12 11 10 10 10 10 10 10 10 12 10 10 10 10 10 11'