QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625372#9356. LRU Algorithmucup-team4352#WA 149ms3832kbC++232.0kb2024-10-09 18:54:452024-10-09 18:54:46

Judging History

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

  • [2024-10-09 18:54:46]
  • 评测
  • 测评结果:WA
  • 用时:149ms
  • 内存:3832kb
  • [2024-10-09 18:54:45]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define lowbit(x) (x&-x)
#define log(x) (31^__builtin_clz(x))
using namespace std;
const int p=2000223479;
int a[5005],loc[5005];
int ans[5005];
vector<int>qr[5005];
vector<int>qa[5005];
vector<int>qre,qae;
void solve(){
	int n,q;
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		qr[i].clear();
		qa[i].clear();
		loc[i]=-1;
	}
	qre.clear();
	qae.clear();
	for(int i=1;i<=q;i++){
		ans[i]=0;
		int len;
		cin>>len;
		vector<int>s;
		for(int j=1;j<=len;j++){
			int x;
			cin>>x;
			s.push_back(x);
		}
		int flag=0;
		if(s.back()==0){
			flag=1;
			while(s.size()&&s.back()==0)s.pop_back();
			if(s.empty())ans[i]=1;
		}
		// reverse(s.begin(),s.end());
		ll h=0;
		for(auto u:s){
			h=(h*1373+u)%p;
		}
		if(flag){
			qre.push_back(h);
			qae.push_back(i);
			continue;
		}
		qr[len].push_back(h);
		qa[len].push_back(i);
	}
	vector<int>st;
	for(int i=1;i<=n;i++){
		if(loc[a[i]]==-1){
			loc[a[i]]=st.size();
			st.push_back(a[i]);
		}
		else{
			for(int j=0;j<st.size();j++){
				if(st[j]==a[i]){
					st.erase(st.begin()+j);
					break;
				}
			}
			st.push_back(a[i]);
		}
		ll h=0;
		int len=0;
		for(int i=st.size()-1;i>=0;i--){
			h=(h*1373+st[i])%p;
			len++;
			if(qr[len].empty())continue;
			int loc=lower_bound(qr[len].begin(),qr[len].end(),h)-qr[len].begin();
			if(loc==qr[len].size())continue;
			while(loc<qr[len].size()&&qr[len][loc]==h){
				ans[qa[len][loc]]=1;
				qr[len].erase(qr[len].begin()+loc);
				qa[len].erase(qa[len].begin()+loc);
			}
		}
		int loc=lower_bound(qre.begin(),qre.end(),h)-qre.begin();
		if(loc==qre.size())continue;
		while(loc<qre.size()&&qre[loc]==h){
			ans[qae[loc]]=1;
			qre.erase(qre.begin()+loc);
			qae.erase(qae.begin()+loc);
		}
	}
	for(int i=1;i<=q;i++){
		if(ans[i])cout<<"Yes\n";
		else cout<<"No\n";
	}
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	cin>>t;
	while(t--)solve();
	return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 149ms
memory: 3832kb

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
Yes
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
Yes
No
Yes
Yes
Yes
No
No
No
No
No
No
Y...

result:

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