QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#424057#8109. PostcardsIratisWA 246ms77228kbC++143.3kb2024-05-28 21:16:372024-05-28 21:16:37

Judging History

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

  • [2024-05-28 21:16:37]
  • 评测
  • 测评结果:WA
  • 用时:246ms
  • 内存:77228kb
  • [2024-05-28 21:16:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define md(a) a=(a%mod+mod)%mod
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)

bool ST;

const int N=3005,M=500005;int sum[N][N],ans,Shift;bool swa[M];
int n,m,Q,prt[N],L[N],R[N],sign,bk[N];bool tag[M],vst[N];struct EDGE{int x,y;}E[M];vector<pair<int,int> >son[N],nxt[N];
inline void ade(int x,int y,int id){nxt[x].push_back({y,id});}inline void zcy(int x,int y,int id){ade(x,y,id),ade(y,x,id);}
inline int S(int xa,int ya,int xb,int yb){return sum[xb][yb]-sum[xa-1][yb]-sum[xb][ya-1]+sum[xa-1][ya-1];}
void idfs(int x,int fa)
{
	prt[x]=fa,vst[x]=1,L[x]=++sign,bk[sign]=x;
	for(auto pa:nxt[x])
	{
		int y=pa.first,id=pa.second;if(vst[y])continue;
		son[x].push_back({y,id}),tag[id]=1;if(E[id].x==y)swap(E[id].x,E[id].y),swa[id]^=1;idfs(y,x);
	}
	R[x]=sign;
}
int t,id[120],uv[120],vu[120],X[120],Y[120],sz[120];bool f[120][120];
struct num{int l,r;}a[120];int cnt,dis[120][120];vector<int>del[120];
inline bool cmp(num a,num b){return a.l<b.l||(a.l==b.l&&a.r>b.r);}
inline void Query()
{
	ans=cnt=0;cin>>t;for(int i=1;i<=t;i++)cin>>id[i]>>uv[i]>>vu[i],id[i]=(id[i]+Shift)%m+1;
	for(int i=1;i<=t;i++)if(swa[id[i]])swap(uv[i],vu[i]);
	// for(int i=1;i<=t;i++)cout<<"close:"<<id[i]<<" "<<uv[i]<<" "<<vu[i]<<'\n';
	for(int i=1;i<=t;i++)if(tag[id[i]])a[++cnt]={L[E[id[i]].y],R[E[id[i]].y]};a[++cnt]={1,n};sort(a+1,a+cnt+1,cmp);
	// for(int i=1;i<=cnt;i++)cout<<a[i].l<<' '<<a[i].r<<'\n';
	for(int x=1;x<=cnt;x++)for(int y=1;y<=cnt;y++)dis[x][y]=0;
	for(int i=1;i<=t;i++)
	{
		int p=bk[E[id[i]].x],q=bk[E[id[i]].y];X[i]=Y[i]=cnt;
		while(p<a[X[i]].l||p>a[X[i]].r)X[i]--;while(q<a[Y[i]].l||q>a[Y[i]].r)Y[i]--;if(X[i]==Y[i])continue;
		if(!uv[i])dis[X[i]][Y[i]]++;if(!vu[i])dis[Y[i]][X[i]]++;
	}
	// for(int i=1;i<=cnt;i++,cout<<'\n')for(int j=1;j<=cnt;j++)cout<<dis[i][j]<<' ';
	// cout<<'\n';
	for(int x=1;x<=cnt;x++)
	{
		del[x].clear();int las=0;sz[x]=a[x].r-a[x].l+1;
		for(int y=x+1;y<=cnt;y++)if(a[y].l>las)del[x].push_back(y),las=a[y].r,sz[x]-=a[y].r-a[y].l+1;
	}
	for(int x=1;x<=cnt;x++)for(int y=1;y<=cnt;y++)if(x!=y)
	{
		dis[x][y]+=S(a[x].l,a[x].r,a[y].l,a[y].r);
		for(int u:del[x])dis[x][y]-=S(a[u].l,a[u].r,a[y].l,a[y].r);
		for(int v:del[y])dis[x][y]-=S(a[x].l,a[x].r,a[v].l,a[v].r);
		for(int u:del[x])for(int v:del[y])dis[x][y]+=S(a[u].l,a[u].r,a[v].l,a[v].r);
	}
	// for(int i=1;i<=cnt;i++,cout<<'\n')for(int j=1;j<=cnt;j++)cout<<dis[i][j]<<' ';
	// cout<<'\n';
	for(int x=1;x<=cnt;x++)for(int y=1;y<=cnt;y++)f[x][y]=(x==y||dis[x][y]>0);
	for(int k=1;k<=cnt;k++)for(int i=1;i<=cnt;i++)for(int j=1;j<=cnt;j++)f[i][j]|=(f[i][k]&f[k][j]);
	for(int i=1;i<=cnt;i++){bool fg=1;for(int j=1;j<=cnt;j++)fg&=f[j][i];if(fg)ans+=sz[i];}
}

bool ED;

signed main()
{
	int time_st=clock();
	cerr<<(&ST-&ED)/1024.0/1024<<endl;ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>Q;for(int i=1;i<=m;i++)cin>>E[i].x>>E[i].y,zcy(E[i].x,E[i].y,i);
	idfs(1,0);for(int i=1;i<=m;i++)if(!tag[i]){int x=L[E[i].x],y=L[E[i].y];sum[x][y]++,sum[y][x]++;}
	// for(int i=1;i<=n;i++,cout<<'\n')for(int j=1;j<=n;j++)cout<<sum[i][j]<<' ';cout<<'\n';
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
	while(Q--){Query();cout<<ans<<'\n';Shift+=ans;}
	cerr<<(clock()-time_st)/1e6<<endl;return 0;
}

詳細信息

Test #1:

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

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: 246ms
memory: 77228kb

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:

0
2981
0
1605
2200
0
1697
0
0
0
2837
0
2316
2
818
2428
0
0
2951
0
-1390
0
2931
2962
0
0
-30
0
0
0
2975
0
1741
1369
2
0
0
0
0
1
0
1541
0
0
2956
0
0
1
2249
2983
0
0
0
0
2468
0
0
0
0
0
0
0
0
0
1807
0
1539
0
2723
2966
0
2588
2997
0
0
0
2208
0
0
0
1966
0
1608
2274
0
0
0
2302
1971
2980
0
0
0
0
1658
0
0
0
...

result:

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