QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#717042#9356. LRU AlgorithmXinyoucuo1dui#WA 58ms150624kbC++232.5kb2024-11-06 16:43:322024-11-06 16:43:33

Judging History

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

  • [2024-11-06 16:43:33]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:150624kb
  • [2024-11-06 16:43:32]
  • 提交

answer

#include<bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
// #define int long long
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int b[5003],a[5003][5003],sz[5003];
int csz[5003],c[5003][5003];
bool vis[5003],ans[5003];
// vector<int> *ts[5003][5003],*tq[5003][5003];
int head1[5003][5003],head2[5003][5003];
int nxt1[5003],nxt2[5003];
int t1[5003][5003],t2[5003][5003];
void dfs(int len,int s,int q)
{
	int L1=0,L2=0;
	for(int i=s; i; i=nxt1[i]) t1[len][++L1]=i;
	for(int i=q; i; i=nxt2[i]) t2[len][++L2]=i;
	for(int I=1; I<=L2; ++I)
	{
		int i=t2[len][I];
		if(csz[i]<len)
		{
			ans[i]=1;
		}
		else
		{
			int v=c[i][len];
			head1[len][v]=0;
			head2[len][v]=0;
		}
	}
	for(int I=1; I<=L2; ++I)
	{
		int i=t2[len][I];
		if(csz[i]>=len)
		{
			int v=c[i][len];
			nxt2[i]=head2[len][v];
			head2[len][v]=i;
		}
	}
	for(int I=1; I<=L1; ++I)
	{
		int i=t1[len][I];
		if(sz[i]>=len)
		{
			int v=a[i][len];
			nxt1[i]=head1[len][v];
			head1[len][v]=i;
		}
	}
	for(int I=1; I<=L2; ++I)
	{
		int i=t2[len][I];
		if(csz[i]>=len)
		{
			int v=c[i][len];
			if(head1[len][v]&&head2[len][v])
			{
				dfs(len+1,head1[len][v],head2[len][v]);
				head1[len][v]=head2[len][v]=0;
			}
		}
	}
}
signed main()
{
	for(int T=read();T--;)
	{
		int n=read(),m=read();
		for(int i=1; i<=n; ++i) b[i]=read();
		// for(int i=1; i<=n; ++i) b[i]=n+1-i;
		for(int i=1; i<=n; ++i)
		{
			sz[i]=0;
			for(int i=1; i<=n; ++i) vis[i]=0;
			for(int j=1; j<=i; ++j) a[i][j]=0;
			for(int j=i; j>=1; --j)
				if(!vis[b[j]])
				{
					a[i][++sz[i]]=b[j];
					vis[b[j]]=1;
				}
			sz[i]=n;
			// if(i==n) for(int j=1; j<=sz[i]; ++j)
				// printf("%d ",a[i][j]);
			// puts("");
		}
		// vector<int> queries;
		for(int i=1; i<=m; ++i)
		{
			// queries.push_back(i);
			ans[i]=0;
			for(int j=1; j<=i; ++j) c[i][j]=0;
			csz[i]=read();
			// csz[i]=n;
			// bool gg=0;
			for(int j=1; j<=csz[i]; ++j)
			{
				c[i][j]=read();
				// c[i][j]=j;
			}
			// puts("");
		}
		vector<int> strings;
		for(int i=1; i<=n; ++i)
			nxt1[i]=i+1;
		for(int i=1; i<=m; ++i)
			nxt2[i]=i+1;
		nxt1[n]=0;
		nxt2[m]=0;
		dfs(1,1,1);
		for(int i=1; i<=m; ++i)
			if(ans[i]) puts("Yes");
			else puts("No");
		
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 13880kb

input:

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

output:

Yes
No
No
Yes
Yes

result:

ok 5 lines

Test #2:

score: -100
Wrong Answer
time: 58ms
memory: 150624kb

input:

105
50 10
23 30 34 20 27 11 21 29 12 7 21 42 45 48 8 15 6 16 19 35 16 14 29 11 31 18 22 4 45 22 14 4 13 40 43 48 27 15 15 15 15 10 15 11 31 37 34 34 50 14
1 25
2 23 6
3 29 21 11
4 12 29 18 39
5 29 21 11 27 20
6 21 10 9 3 34 14
7 49 36 36 43 50 50 35
8 12 29 21 11 27 20 34 30
9 11 27 20 34 30 23 0 0 ...

output:

No
No
Yes
No
Yes
No
No
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
No
No
Yes
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
No
No
No
No
No
Yes
No
No
No
Yes
Yes
Yes
Yes
No
No
Yes
No
No
No
Yes
Yes
Yes
Yes
No
No
Yes
No
No
No
Yes
No
Yes
No
Yes
No
Yes
No
No
No
Yes
Yes
Yes
No
No
No
No
No
No
Yes...

result:

wrong answer 44th lines differ - expected: 'Yes', found: 'No'