QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101561#6379. LaLa and Monster Hunting (Part 2)xiaoyaowudiWA 5ms8252kbC++142.3kb2023-04-30 11:09:532023-04-30 11:09:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-30 11:09:54]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:8252kb
  • [2023-04-30 11:09:53]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
constexpr int N(100010),p(998244353),K(1e4);
std::vector<std::pair<int,int>> es[N],ts[N];int d[N],cnt[N],te[N],fe[N];
std::pair<int,int> ds[N];
std::bitset<N> bs[(K<<1)+10];
int W(int k){return k>=p?k-p:k;}
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);int n,m;
	std::cin>>n>>m;
	for(int i(1),u,v;i<=m;++i)
	{
		std::cin>>u>>v;
		++u;++v;
		ds[i]={u,v};++d[u],++d[v];es[u].emplace_back(v,i);
		es[v].emplace_back(u,i);
	}
	for(int i(1);i<=m;++i)
	{
		auto [u,v]=ds[i];
		if(d[u]<d[v] || (d[u]==d[v] && u<v)) ts[u].emplace_back(v,i);
		else ts[v].emplace_back(u,i);
	}
	for(int i(1);i<=n;++i)
	{
		static int vis[N];
		for(auto [v,id]:ts[i])
		{
			vis[v]=id;
		}
		for(auto [v,id1]:ts[i])
		{
			for(auto [t,id2]:ts[v]) if(vis[t])
			{
				++cnt[i],++cnt[v],++cnt[t];
				++te[vis[t]],++te[id1],++te[id2];
			}
		}
	}
	for(int i(1);i<=n;++i)
	{
		static int cnt[N];
		for(auto [v,_]:es[i]) for(auto [t,__]:ts[v]) if(d[i]<d[t] || (d[i]==d[t] && i<t)) ++cnt[t];
		for(auto [v,id1]:es[i]) for(auto [t,id2]:ts[v]) if(d[i]<d[t] || (d[i]==d[t] && i<t)) fe[id1]=W(fe[id1]+cnt[t]-1),fe[id2]=W(fe[id2]+cnt[t]-1);
		for(auto [v,_]:es[i]) for(auto [t,__]:ts[v]) cnt[t]=0;
	}
	int ans(0);
	for(int i(1);i<=n;++i)
	{
		int t(0),f(0);for(auto [v,_]:es[i]) t+=d[v]-1,f=W(f+cnt[v]);
		f=W(f-W(cnt[i]<<1)+p);
		ans=(ans-W(f<<1)+p)%p;
		ans=(ans+2ll*(p-cnt[i])*(cnt[i]-1))%p;
		ans=(ans+1ll*t*f)%p;
		ans=(ans+1ll*(p-cnt[i])*(d[i]-2)%p*(d[i]-3))%p;
	}
	for(int i(1);i<=m;++i) ans=(ans+2ll*(p-te[i])*fe[i])%p;
	for(int l(1);l<=m;l+=K)
	{
		int r(std::min(l+K-1,m));
		static int mm[N];int mc(0);
		for(int i(l);i<=r;++i)
		{
			auto [u,v]=ds[i];
			if(!mm[u]) mm[u]=++mc;
			if(!mm[v]) mm[v]=++mc;
		}
		for(int i(1);i<=m;++i)
		{
			auto [u,v]=ds[i];
			if(mm[u]) bs[mm[u]][v]=true;
			if(mm[v]) bs[mm[v]][u]=true;
		}
		for(int i(l);i<=r;++i)
		{
			auto [u,v]=ds[i];
			int cnt((bs[mm[u]]&bs[mm[v]]).count());
			cnt=1ll*(p-cnt)*(cnt-1)%p;
			ans=(ans+1ll*(p-4+d[u]-3+d[v]-3)*cnt)%p;
		}
		for(int i(1);i<=mc;++i) bs[i].reset();
		for(int i(l);i<=r;++i) mm[ds[i].first]=mm[ds[i].second]=0;
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 8184kb

input:

6 7
0 1
1 2
0 2
2 3
3 4
4 5
3 5

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 8168kb

input:

6 15
0 1
0 2
0 3
0 4
0 5
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

output:

360

result:

ok 1 number(s): "360"

Test #3:

score: 0
Accepted
time: 1ms
memory: 8116kb

input:

2 0

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 5ms
memory: 8108kb

input:

2 1
0 1

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 5ms
memory: 8104kb

input:

2 1
0 1

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 0ms
memory: 8204kb

input:

2 1
0 1

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 0ms
memory: 8160kb

input:

2 0

output:

0

result:

ok 1 number(s): "0"

Test #8:

score: 0
Accepted
time: 5ms
memory: 8096kb

input:

2 1
0 1

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: 0
Accepted
time: 1ms
memory: 8168kb

input:

3 3
1 2
0 2
0 1

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 0ms
memory: 8108kb

input:

3 2
0 1
0 2

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: 0
Accepted
time: 4ms
memory: 8216kb

input:

3 2
0 2
0 1

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 1ms
memory: 8232kb

input:

3 3
0 1
0 2
1 2

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 4ms
memory: 8048kb

input:

3 0

output:

0

result:

ok 1 number(s): "0"

Test #14:

score: 0
Accepted
time: 5ms
memory: 8224kb

input:

3 3
0 2
0 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: 0
Accepted
time: 1ms
memory: 8244kb

input:

4 5
0 3
0 2
1 3
0 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #16:

score: 0
Accepted
time: 5ms
memory: 8184kb

input:

4 3
2 3
1 2
0 2

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 1ms
memory: 8208kb

input:

4 1
2 3

output:

0

result:

ok 1 number(s): "0"

Test #18:

score: -100
Wrong Answer
time: 0ms
memory: 8252kb

input:

4 3
2 3
1 2
0 3

output:

998244352

result:

wrong answer 1st numbers differ - expected: '0', found: '998244352'