QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#759649#9356. LRU Algorithm275307894a#WA 60ms4020kbC++142.4kb2024-11-18 10:50:162024-11-18 10:50:17

Judging History

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

  • [2024-11-18 10:50:17]
  • 评测
  • 测评结果:WA
  • 用时:60ms
  • 内存:4020kb
  • [2024-11-18 10:50:16]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=5e3+5,M=N*4+5,K=1000+5,mod=1e8+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,q,A[N],B[N];
int gpre[N],gnxt[N];
int pre[N],nxt[N];
int tot=0;
void calc(int x,int w){
	tot+=w*(nxt[x]==gnxt[x]);
	tot+=w*(pre[x]==gpre[x]);
}
void del(int x){
	calc(x,-1);calc(pre[x],-1);calc(nxt[x],-1);
	nxt[pre[x]]=nxt[x];pre[nxt[x]]=pre[x];
	calc(pre[x],1);calc(nxt[x],1);
	nxt[x]=pre[x]=-1;
	calc(x,1);
}
void ins(int x,int y){
	calc(x,-1);calc(nxt[x],-1);calc(y,-1);
	pre[y]=x;nxt[y]=nxt[x];
	nxt[pre[y]]=pre[nxt[y]]=y;
	calc(y,1);calc(pre[y],1);calc(nxt[y],1);
}
void qry(){
	int lim;scanf("%d",&lim);
	for(int i=1;i<=lim;i++) scanf("%d",&B[i]);
	for(int i=0;i<=n+1;i++) gpre[i]=gnxt[i]=-1;
	int La=0,cnt=0;
	for(int i=1;i<=lim;i++) if(B[i]){
		int x=B[i];
		if(~gpre[x]){puts("No");return;}
		gpre[x]=La;gnxt[La]=x;La=x;
	}
	gpre[n+1]=La;gnxt[La]=n+1;
	for(int i=0;i<=n+1;i++) pre[i]=nxt[i]=-1;
	nxt[0]=n+1;pre[n+1]=0;
	tot=0;
	for(int i=0;i<=n+1;i++) calc(i,1);
	// gdb(tot);
	int cts=0;
	for(int i=1;i<=n;i++){
		int x=A[i];
		if(pre[x]==-1){
			if(cts==lim){
				int y=pre[n+1];
				del(y);
				cts--;
			}
			ins(0,x);cts++;
		}else{
			del(x);
			ins(0,x);
		}
		// gdb(tot);
		if(tot==2*(n+2)){puts("Yes");gdb(i);return;}
	}
	puts("No");
}
void Solve(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++) scanf("%d",&A[i]);
	while(q--) qry();
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 60ms
memory: 4020kb

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'