QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#310830 | #8109. Postcards | vme50 | WA | 132ms | 53812kb | C++17 | 3.7kb | 2024-01-21 18:38:51 | 2024-01-21 18:38:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mid ((l+r)/2)
const int N=3e3+5,M=5e5+5,LIM=1e7+5;
#define gc() (P1==P2 && (P2=(P1=bufI)+fread(bufI,1,LIM,stdin),P1==P2)?EOF:*P1++)
#define pc(x) (((P3==bufO+LIM)?(fwrite(bufO,1,P3-bufO,stdout),P3=bufO):P3),*P3++=(x))
int stO[55];char bufI[LIM],bufO[LIM],*P1=bufI,*P2=bufI,*P3=bufO;
int rd()
{
int res=0;bool fl=0;char c=0;while(!isdigit(c)) fl|=c=='-',c=gc();
while(isdigit(c)) res=res*10+(c-48),c=gc();return fl?-res:res;
}
void wr(ll x)
{
if(!x) {pc('0');return;}if(x<0) pc('-'),x=-x;
stO[0]=0;while(x) stO[++stO[0]]=x%10,x/=10;
for(int i=stO[0];i;--i) pc(stO[i]+48);
}
void flush() {fwrite(bufO,1,P3-bufO,stdout);P3=bufO;}
namespace SCC
{
const int N=205;
int n,dfn[N],low[N],st[N],bl[N],e[N][N];bool tg[N];
void Tarjan(int u)
{
dfn[u]=low[u]=++dfn[0];st[++st[0]]=u;
for(int v=1;v<=n;++v) if(e[u][v])
{
if(!dfn[v]) Tarjan(v),low[u]=min(low[u],low[v]);
else if(!bl[v]) low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u])
{
bl[u]=++bl[0];
while(st[st[0]]!=u) bl[st[st[0]--]]=bl[0];--st[0];
}
}
void clear(int _n)
{
n=_n;fill(dfn,dfn+n+1,0);fill(bl,bl+n+1,0);fill(tg+1,tg+n+1,0);
for(int i=1;i<=n;++i) fill(e[i]+1,e[i]+n+1,0);
}
int slv()
{
int res=0;for(int i=1;i<=n;++i) if(!dfn[i]) Tarjan(i);
for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
if(e[i][j] && bl[i]!=bl[j]) tg[bl[i]]=1;
for(int i=1;i<=bl[0];++i) if(!tg[i]) {if(res) return 0;res=i;}
return res;
}
}
int n,m,c,h,ans,L[N],R[N],w[N][N];bool fl,vs[N],tg[M];
struct Edge {int u,v,id;}e[M];vector<Edge> e1[N];
int a[N],b1[N],b2[N],z[N],o[N],st[N],id[N],sz[N],w1[N][N];
vector<int> ch[N];struct Node {int l,r;};vector<Node> z1[N];
int f(int l1,int r1,int l2,int r2)
{return w[r1][r2]-w[r1][l2-1]-w[l1-1][r2]+w[l1-1][l2-1];}
int qId(int x) {return id[o[lower_bound(o+1,o+o[0]+1,L[x])-o]];}
void dfs(int u,int f)
{
vs[u]=1;L[u]=++L[0];
for(auto i:e1[u]) if(i.id!=f)
{
if(!vs[i.v]) tg[i.id]=1,dfs(i.v,i.id);
else w[L[u]][L[i.v]]=w[L[i.v]][L[u]]=1;
}R[u]=L[0];
}
int slv()
{
if(fl) return 0;int t,res=0;h=rd();z[0]=o[0]=st[0]=0;z[++z[0]]=1;
for(int i=1;i<=h;++i)
{
a[i]=(rd()+ans)%m+1;b1[i]=rd();b2[i]=rd();
if(tg[a[i]]) z[++z[0]]=L[e[a[i]].u]<L[e[a[i]].v]?e[a[i]].v:e[a[i]].u;
}SCC::clear(z[0]);sort(z+1,z+z[0]+1,[](int x,int y) {return L[x]<L[y];});
for(int i=1;i<=z[0];++i)
{
while(st[0] && R[z[st[st[0]]]]<L[z[i]]) --st[0];
ch[i].clear();if(st[0]) ch[st[st[0]]].pb(i);st[++st[0]]=i;
}
for(int i=1,t;i<=z[0];++i)
{
t=L[z[i]];z1[i].clear();sz[i]=0;
for(auto j:ch[i]) if(t<L[z[j]])
z1[i].pb((Node) {t,L[z[j]]-1}),t=R[z[j]]+1;
if(t<=R[z[i]]) z1[i].pb((Node) {t,R[z[i]]});
for(auto [l,r]:z1[i]) id[o[++o[0]]=r]=i,sz[i]+=r-l+1;
}sort(o+1,o+o[0]+1);
for(int i=1;i<=z[0];++i) for(int j=1;j<i;++j)
{
w1[i][j]=0;
for(auto [l1,r1]:z1[i]) for(auto [l2,r2]:z1[j])
w1[i][j]+=f(l1,r1,l2,r2);
}
for(int i=1,u,v;i<=h;++i)
{
u=qId(e[a[i]].u);v=qId(e[a[i]].v);
if(!b1[i]) SCC::e[u][v]=1;if(!b2[i]) SCC::e[v][u]=1;
if(!tg[a[i]]) {if(u<v) swap(u,v);--w1[u][v];}
}
for(int i=1;i<=z[0];++i) for(int j=1;j<i;++j)
if(w1[i][j]) SCC::e[i][j]=SCC::e[j][i]=1;t=SCC::slv();
for(int i=1;i<=z[0];++i) if(SCC::bl[i]==t) res+=sz[i];return res;
}
int main()
{
n=rd();m=rd();c=rd();
for(int i=1,u,v;i<=m;++i)
{
u=rd();v=rd();e[i]=(Edge) {u,v,i};
e1[u].pb(e[i]);e1[v].pb((Edge) {v,u,i});
}dfs(1,0);for(int i=1;i<=n;++i) if(!vs[i]) {fl=1;break;}
for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
w[i][j]+=w[i][j-1]+w[i-1][j]-w[i-1][j-1];
for(int i=1,t;i<=c;++i) wr(t=slv()),pc('\n'),ans+=t;flush();return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11972kb
input:
4 4 3 1 2 4 3 2 3 1 3 2 3 1 1 1 0 1 3 1 1 0 0 1 0 3 1 0 1 1 1 1
output:
3 1 0
result:
ok 3 number(s): "3 1 0"
Test #2:
score: -100
Wrong Answer
time: 132ms
memory: 53812kb
input:
3000 11860 5000 135 1279 1379 1627 1253 2516 338 1596 260 1086 1153 2182 527 732 500 2820 1395 1556 793 1491 2673 2746 1630 1792 1720 2871 443 2095 1095 1296 2008 2358 1685 1801 2356 2704 1856 2698 1798 2134 1683 1792 812 2977 43 1507 1297 1574 222 1563 1278 2168 1181 1851 1492 2757 432 1459 428 902...
output:
3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3002 3000 3000 3001 3001 3000 3000 3000 3000 3000 3000 3000 3000 3000 0 3000 3010 3010 3000 3000 3000 3000 3000 3000 3000 3000 3001 3004 3000 3000 3002 2999 3000 3000 3000 3000 3000 3000 4164 3000 3000 3005 3000 3000 3001 3000 3000 3000 300...
result:
wrong answer 13th numbers differ - expected: '3000', found: '3002'