QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#370592#6354. 4zyz07WA 0ms10668kbC++171.8kb2024-03-29 12:43:292024-03-29 12:44:33

Judging History

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

  • [2024-03-29 12:44:33]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:10668kb
  • [2024-03-29 12:43:29]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops,fast-math,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
#define For(Ti,Ta,Tb) for(auto Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(auto Ti=(Ta);Ti>=(Tb);--Ti)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
using ll=long long;
using ull=unsigned long long;
const int N=1e5+5,B=20000;
int n,m,edge[N][2],id[N],deg[N],tag[N],ans3;
vector<int> g[N],g2[N];
vector<array<int,2>> tri[N];
ull bs[N][(B>>6)+2];
void assign(ull* bs,int i){
	bs[i>>6]|=1LLU<<(i&63);
}
int and_count(ull* bs1,ull* bs2,int len){
	int ans=0;
	For(i,0,len-1){
		ans+=__builtin_popcountll(bs1[i]&bs2[i]);
	}
	return ans;
}
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n>>m;
	For(i,1,m){
		auto& [u,v]=edge[i];
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	For(i,1,n){
		deg[i]=g[i].size();
	}
	For(u,1,n){
		for(int v:g[u]){
			if(deg[u]<deg[v]||(deg[u]==deg[v]&&u<v)){
				g2[u].push_back(v);
			}
		}
	}
	For(u,1,n){
		for(int v:g2[u]){
			tag[v]=u;
		}
		for(int v:g2[u]){
			for(int w:g2[v]){
				if(tag[w]==u){
					++ans3;
					tri[u].push_back({v,w});
					tri[v].push_back({u,w});
					tri[w].push_back({u,v});
				}
			}
		}
	}
	ll ans=0;
	For(u,1,n){
		if(tri[u].size()<3) continue;
		int tot=0;
		for(int v:g[u]){
			tag[v]=++tot;
		}
		for(int l=1,r=min(tot,B);l<=tot;l+=B,r=min(tot,r+B)){
			for(auto [v,w]:tri[u]){
				if(l<=tag[w]&&tag[w]<=r){
					assign(bs[tag[v]],tag[w]-l);
				}
				if(l<=tag[v]&&tag[v]<=r){
					assign(bs[tag[w]],tag[v]-l);
				}
			}
			for(auto [v,w]:tri[u]){
				ans+=and_count(bs[tag[v]],bs[tag[w]],((r-l+1)>>6)+1);
			}
			For(i,1,tot){
				memset(bs[i],0,sizeof(ull)*(((r-l+1)>>6)+1));
			}
		}
	}
	cout<<n<<' '<<m<<' '<<ans3<<' '<<ans/12<<'\n';
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 10668kb

input:

5 9
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5

output:

5 9 7 2

result:

wrong answer 1st numbers differ - expected: '2', found: '5'