QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#326713 | #6441. Ancient Magic Circle in Teyvat | Kalenist | WA | 2ms | 9052kb | C++20 | 5.7kb | 2024-02-13 20:04:34 | 2024-02-13 20:04:34 |
Judging History
answer
#include<bits/stdc++.h>
#define N 100010
#define ull unsigned long long
#define pc __builtin_popcountll
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define Down(i,a,b) for(register int i=a;i>=b;i--)
using namespace std;
int n,m,d[N],a[N],occ[N],rnk[N];
int mn[N],id[N],rev[N],sta[N],top;
long long tot,ans;
bool mark[N];
mt19937 rnd(time(0));
vector<int> go[N],big[N],small[N],h[N];
struct E{int x,y;}edge[N<<1],nw[N<<2];
struct my_bitset
{
int sz;ull v[10];
inline void ins(int x){v[x/64]|=1ull<<(x%64);}
inline void init(int nsz)
{
sz=(nsz-1)/64;
For(i,0,sz) v[i]=0;
}
inline int cnt()
{
int res=0;
For(i,0,sz) res+=pc(v[i]);
return res;
}
inline my_bitset operator &(const my_bitset &p)const
{
my_bitset res;res.sz=sz;
For(i,0,sz) res.v[i]=v[i]&p.v[i];
return res;
}
}bs[1010];//手写bitset
struct my_big_bitset
{
int sz;ull v[2010];
inline void ins(int x){v[x/64]|=1ull<<(x%64);}
inline void del(int x){v[x/64]^=1ull<<(x%64);}
inline void init(int nsz)
{
sz=(nsz-1)/64;
For(i,0,sz) v[i]=0;
}
inline int cnt()
{
int res=0;
For(i,0,sz) res+=pc(v[i]);
return res;
}
inline my_big_bitset operator &(const my_big_bitset &p)const
{
my_big_bitset res;res.sz=sz;
For(i,0,sz) res.v[i]=v[i]&p.v[i];
return res;
}
}bbs[10010];//手写bitset
inline int read()
{
register int x=0,c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x;
}
inline long long C(int n,int m)
{
if(n < m) return 0;
if(m > 3)
{
__int128 res=1;
For(i,1,m) res*=n-i+1;
For(i,1,m) res/=i;
return res;
}long long res=1;
For(i,1,m) res*=n-i+1;
For(i,1,m) res/=i;
return res;
}
inline long long solve1()
{
long long res=1ll*m*C(n-2,2);
//printf("%d: %lld\n",1,res);
return res;
}
inline long long solve2()
{
long long res=0;
For(i,1,m)
{
int x=edge[i].x,y=edge[i].y;
res+=m-(d[x]+d[y]-1);
}res>>=1;
//printf("%d: %lld\n",2,res);
return res;
}
inline long long solve3()
{
long long res=0;
For(i,1,n) res+=C(d[i],2)*(n-3);
//printf("%d: %lld\n",3,res);
return res;
}
inline void solve457()
{
long long res4=0,res5=0,res7=0,cir=0;
For(i,1,m)
{
int x=edge[i].x,y=edge[i].y;
res4+=1ll*(d[x]-1)*(d[y]-1);
}
For(i,1,n)
{
for(int to:big[i]) mark[to]=true;
for(int to:big[i]) for(int v:big[to])
if(mark[v]) cir++,res7+=d[i]+d[to]+d[v]-6;
for(int to:big[i]) mark[to]=false;
}res4-=cir*3,res5=cir*(n-3);
tot-=res4,tot-=res5,tot+=res7;
//printf("%d: %lld\n%d: %lld\n%d: %lld\n",4,res4,5,res5,7,res7);
return;
}
inline long long solve6()
{
long long res=0;
For(i,1,n) res+=C(d[i],3);
//printf("%d: %lld\n",6,res);
return res;
}
inline long long solve8()
{
long long res=0,del=0;
For(i,1,n)
{
int cnt=0;
for(int to:big[i])
for(int v:go[to]) if(v^i)
{
if(!occ[v]) a[++cnt]=v;
occ[v]++;
}
For(j,1,cnt) res+=C(occ[a[j]],2),occ[a[j]]=0;
}
For(i,1,n)
{
int cnt=0;
for(int to:big[i])
for(int v:small[to]) if(v^i)
{
if(!occ[v]) a[++cnt]=v;
occ[v]++;
}
For(j,1,cnt) del+=C(occ[a[j]],2),occ[a[j]]=0;
}res-=del>>1;
//printf("%d: %lld\n",8,res);
return res;
}
inline long long solve9()
{
long long res=0;
For(i,1,n) id[i]=i;
shuffle(id+1,id+n,rnd);
For(i,1,n) rev[id[i]]=i;
For(i,1,m)
{
int a=edge[i].x,b=edge[i].y;
if(id[a] > id[b]) swap(a,b);
h[id[b]].push_back(id[a]);
}mn[n+1]=n+1;
Down(i,n,1)
{
mn[i]=mn[i+1];
for(int x:h[i]) mn[i]=min(mn[i],x);
}int pos=1;
For(i,1,n)
{
rnk[i]=top?sta[top--]:++rnk[0];
bbs[rnk[i]].init(n+1);
for(int to:go[rev[i]]) bbs[rnk[i]].ins(to);
for(int x:h[i]) res+=C((bbs[rnk[i]]&bbs[x]).cnt(),2);
while(pos < mn[i+1]) sta[++top]=rnk[pos++];
}
//printf("%d: %lld\n",9,res);
return res;
}
inline long long solve10()
{
long long res=0;
memset(rnk,0,sizeof(rnk));
For(i,1,n)
{
int cnt=0,sz=small[i].size();rnk[0]=0;
for(int to:small[i]) rnk[to]=++rnk[0],bs[rnk[0]].init(sz);
for(int to:small[i]) for(int v:small[to])
if(rnk[v]) bs[rnk[to]].ins(rnk[v]-1),nw[++cnt]=(E){to,v};
For(j,1,cnt)
{
int a=nw[j].x,b=nw[j].y;
res+=(bs[rnk[a]]&bs[rnk[b]]).cnt();
}for(int to:small[i]) rnk[to]=0;
}
//printf("%d: %lld\n",10,res);
return res;
}
int main()
{
n=read(),m=read();
For(i,1,m)
{
int x=read(),y=read();
edge[i]=(E){x,y};
go[x].push_back(y),d[x]++;
go[y].push_back(x),d[y]++;
}tot=C(n,4);
For(i,1,n) for(int to:go[i])
if(d[i] > d[to] || d[i] == d[to] && i > to)
big[i].push_back(to);
For(i,1,n) for(int to:go[i])
if(d[i] < d[to] || d[i] == d[to] && i < to)
small[i].push_back(to);
tot+=solve1()*(-1),tot+=solve2();
tot+=solve3(),solve457();
tot+=solve6()*(-1),tot+=solve8();
tot+=solve9()*(-1),ans=solve10(),tot+=ans;
printf("%lld\n",abs(tot-ans));
return 0;
}
/*
4 6
1 2
2 3
3 4
4 1
1 3
2 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6320kb
input:
7 6 1 2 1 3 1 4 2 3 2 4 3 4
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 6224kb
input:
4 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 6560kb
input:
4 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 6108kb
input:
4 2 1 2 1 3
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 1ms
memory: 6364kb
input:
4 2 1 2 3 4
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 1ms
memory: 6268kb
input:
4 3 1 2 1 3 1 4
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 0ms
memory: 6652kb
input:
4 3 1 2 2 3 3 4
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 2ms
memory: 6204kb
input:
4 3 1 2 2 3 1 3
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 0ms
memory: 6316kb
input:
4 4 1 2 2 3 1 3 1 4
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 1ms
memory: 6212kb
input:
4 4 1 2 2 3 3 4 1 4
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 2ms
memory: 6368kb
input:
4 5 1 2 1 3 1 4 2 3 3 4
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 1ms
memory: 6544kb
input:
4 6 1 2 1 3 1 4 2 3 2 4 3 4
output:
1
result:
ok 1 number(s): "1"
Test #13:
score: 0
Accepted
time: 0ms
memory: 6200kb
input:
633 0
output:
6626427570
result:
ok 1 number(s): "6626427570"
Test #14:
score: 0
Accepted
time: 0ms
memory: 9052kb
input:
633 100 284 424 27 560 19 484 92 558 59 385 440 577 11 420 341 543 285 330 430 569 88 259 13 499 444 557 418 483 167 220 185 497 175 489 246 400 387 577 125 303 99 336 152 437 116 324 229 472 200 338 46 197 368 399 345 386 92 439 121 132 50 310 444 525 454 631 174 337 276 337 476 597 405 557 99 263 ...
output:
6606576764
result:
ok 1 number(s): "6606576764"
Test #15:
score: 0
Accepted
time: 0ms
memory: 8888kb
input:
633 200 147 540 247 463 502 553 168 519 24 395 126 170 417 437 77 94 453 466 104 400 32 145 231 496 199 360 391 597 492 599 526 627 384 481 219 238 115 508 74 112 239 243 96 480 31 164 119 467 96 578 275 574 66 364 80 409 18 527 97 462 552 570 7 350 344 473 221 621 174 613 167 181 61 474 45 320 64 4...
output:
6586769859
result:
ok 1 number(s): "6586769859"
Test #16:
score: -100
Wrong Answer
time: 2ms
memory: 8956kb
input:
633 500 193 462 116 450 462 486 197 295 471 593 189 220 484 576 143 415 256 588 132 543 46 363 18 184 105 395 243 529 36 188 83 588 127 339 184 415 182 193 123 341 176 427 446 484 143 525 76 473 161 519 126 386 234 418 119 181 28 94 543 569 333 448 206 588 103 563 499 536 131 263 614 632 478 489 284...
output:
6527638885
result:
wrong answer 1st numbers differ - expected: '6527638886', found: '6527638885'