QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661483#9356. LRU Algorithmganking#TL 1ms4828kbC++232.6kb2024-10-20 16:27:202024-10-20 16:27:22

Judging History

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

  • [2024-10-20 16:27:22]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:4828kb
  • [2024-10-20 16:27:20]
  • 提交

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];
int b[2][N];
unordered_map<ll,int> h[N],o[N];
int n,k,val;
int a[N];
int tmp,len;
int las;
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]);
    fo(i,1,n)b[0][i]=b[1][i]=0;
    // fo(i,1,n)q[0].push(0);
    las=0;
    fo(i,1,n)
    {
        len=0;
        // while(!q[(i)%2].empty())q[(i)%2].pop();
        // q[i%2].push(a[i]);
        b[i%2][1]=a[i];
        tmp=a[i];
        len=1;

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

        val=a[i]*i%mo1+1;
        h[len][f]=val;
        o[len][g]=val;

        if(len==n) {
            continue;
        }
        fo(j,1,n)
        {
            if(b[(i+1)%2][j]==a[i])continue;
            len++;
            tmp=b[(i+1)%2][j];
            b[i%2][len]=tmp;
            


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

            val=tmp*i%mo1+1;
            h[len][f]=val;
            o[len][g]=val;

            if(len==n)break;
        }
        // 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: 4828kb

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: