QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661432#9356. LRU Algorithmganking#TL 1ms4900kbC++202.2kb2024-10-20 16:12:582024-10-20 16:12:59

Judging History

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

  • [2024-10-20 16:12:59]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:4900kb
  • [2024-10-20 16:12:58]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define db long double
#define mk make_pair
#define eb emplace_back 
#define pi pair<ll,ll>
#define fo(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define fd(i,a,b) for(ll (i)=(a);(i)>=(b);(i)--)
using namespace std;
const int N=1e4+10;
const ll mo1=1e9+7;
const ll mo2=1e9+9;
const ll P=131;
const ll Q=13331;
ll f,g,pp[N],qq[N];
queue<int>q[2];
unordered_map<ll,int> h[N],o[N];
int n,k,val;
int a[N];
int tmp,len;
void R(int &x){
    int t=0;
    char ch;
    for (ch=getchar();!('0'<=ch && ch<='9');ch=getchar());
    for (;('0'<=ch && ch<='9');ch=getchar()) t=t*10+ch-'0';
    x=t;
}
void solve(){
    R(n); R(k);
    fo(i,1,n) h[i].clear(),o[i].clear();

    fo(i,1,n) R(a[i]);
    while(!q[0].empty())q[0].pop();
    while(!q[1].empty())q[1].pop();
    fo(i,1,n)q[0].push(0);
    fo(i,1,n)
    {
        while(!q[(i)%2].empty())q[(i)%2].pop();
        q[i%2].push(a[i]);
        tmp=a[i];
        len=1;

        f=tmp+1;
        g=tmp+1;

        val=rand()+1;
        h[len][f]=val;
        o[len][g]=val;

        if(len==n) {
            continue;
        }
        while(!q[(i+1)%2].empty())
        {
            tmp=q[(i+1)%2].front();
            q[(i+1)%2].pop();
            if(tmp==a[i])continue;
            q[i%2].push(tmp);
            len++;

            f=(f*P%mo1+(tmp+1))%mo1;
            g=(g*Q%mo2+(tmp+1))%mo2;

            val=rand()+1;
            h[len][f]=val;
            o[len][g]=val;

            if(len==n)break;
            //tmp len

        }

    }

    int l,x;
    while (k--) {
        R(l);
        f=g=0;
        fo(i,1,l) {
            R(x);
            
            f=(f*P%mo1+(x+1))%mo1;
            g=(g*Q%mo2+(x+1))%mo2;
        }

        if (h[l][f]==o[l][g] && h[l][f]!=0) puts("Yes");
        else puts("No");
    }
}
int main(){

    pp[0]=qq[0]=1;
    
    fo(i,1,5005) {
        pp[i]=pp[i-1]*P%mo1;
        qq[i]=qq[i-1]*Q%mo2;
    }

    // ios::sync_with_stdio(false);

    srand(time(NULL));
    // cin.tie(0),cout.tie(0);

    int T=1;    
    R(T);

    // return 0;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Time 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:


result: