QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#716936#9356. LRU AlgorithmXinyoucuo1dui#ML 0ms7764kbC++232.7kb2024-11-06 16:25:242024-11-06 16:25:24

Judging History

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

  • [2024-11-06 16:25:24]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:7764kb
  • [2024-11-06 16:25:24]
  • 提交

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];
void dfs(int len,vector<int> &s,vector<int> &q)
{
	// printf("dfs %d\n",len);
	// for(int i:s) printf("%d ",i);
	// puts("");
	// for(int i:q) printf("%d(%d) ",i,csz[i]);
	// puts("");
	// puts("");
	for(int i:q) if(csz[i]<len)
	{
		// printf("assign %d\n",i);
		ans[i]=1;
	}
	else
	{
		int v=c[i][len];
		if(ts[len][v]==NULL)
			ts[len][v]=new vector<int>();
		if(tq[len][v]==NULL)
			tq[len][v]=new vector<int>();
		// if(!ts[len][v].empty())
		// vector<int>().swap(ts[len][v]);
		// if(!tq[len][v].empty())
		// vector<int>().swap(tq[len][v]);
	}
	for(int i:q) if(csz[i]>=len)
	{
		(*tq[len][c[i][len]]).push_back(i);
	}
	for(int i:s) if(sz[i]>=len)
	{
		if(ts[len][a[i][len]]!=NULL)
		(*ts[len][a[i][len]]).push_back(i);
	}
	for(int i:q) if(csz[i]>=len)
	{
		int v=c[i][len];
		if(ts[len][v]!=NULL&&!(*ts[len][v]).empty())
		{
			// vector<int> _s,_q;
			// _s.swap(*ts[len][v]),
			// _q.swap(*tq[len][v]);
			dfs(len+1,*ts[len][v],*tq[len][v]);
			ts[len][v]=NULL;
			tq[len][v]=NULL;
		}
	}
}
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)
		{
			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;
			// 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();
			// bool gg=0;
			for(int j=1; j<=csz[i]; ++j)
			{
				c[i][j]=read();
				// if(c[i][j]>n||c[i][j]<=0) gg=1;
				// printf("%d ",c[i][j]);
			}
			// puts("");
		}
		vector<int> strings;
		for(int i=1; i<=n; ++i)
			strings.push_back(i);
		dfs(1,strings,queries);
		for(int i=1; i<=m; ++i)
			if(ans[i]) puts("Yes");
			else puts("No");
		for(int i=0; i<=n; ++i)
		for(int j=0; j<=n; ++j)
			ts[i][j]=tq[i][j]=NULL;
			// vector<int>().swap(ts[i][j]),
			// vector<int>().swap(tq[i][j]);
		
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Memory Limit Exceeded

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: