提交记录 8577


用户 题目 状态 得分 用时 内存 语言 代码长度
Labelray noi17b. 【NOI2017】蚯蚓排队 Accepted 100 1.043 s 395984 KB C++11 3.38 KB
提交时间 评测时间
2019-02-26 16:39:55 2020-08-01 01:21:54
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>

template <typename T> void in(T &_){
    char c=getchar(); _=0; int fl=1;
    while(c<'0'||c>'9') fl=c=='-'?-1:fl, c=getchar();
    while(c>='0'&&c<='9') _=_*10+c-'0', c=getchar(); _*=fl;
}

typedef unsigned long long ULL;

struct HashMap{
    #define MOD ((1<<21)-1)
    ULL val[200010];
    int ne[200010], cnt[200010], tot, head[MOD+1];
    std::queue<int> q;
    
    void insert(ULL v){
        int qwq=v%MOD;
        for(int i=head[qwq]; i; i=ne[i])
            if(val[i]==v){
                cnt[i]++;
                return;
            }
        int now;
        if(q.empty()) now=++tot;
        else{now=q.front(); q.pop();}
        val[now]=v;
        cnt[now]=1;
        ne[now]=head[qwq];
        head[qwq]=now;
    }
    
    void erase(ULL v){
        int qwq=v%MOD;
        for(int i=head[qwq], j=-1; i; j=i, i=ne[i])
            if(val[i]==v){
                cnt[i]--;
                if(!cnt[i]){
                    q.push(i);
                    if(~j) ne[j]=ne[i];
                    else head[qwq]=ne[i];
                }
                return;
            }
    }
    
    int count(ULL v){
        int qwq=v%MOD;
        for(int i=head[qwq]; i; i=ne[i])
            if(val[i]==v) return cnt[i];
        return 0;
    }
    
    void print(){
        for(int i=1; i<=tot; i++) printf(" %llu %d\n", val[i], cnt[i]);
    }
    #undef MOD
}H[65];

struct Node{
    Node *pre, *ne;
    int val;
    Node() : pre(NULL), ne(NULL){}
}node[200010];

const int MOD=998244353, MAX_K=55;
ULL bin[MAX_K+10];
int N, M, s[10000010], f[2*MAX_K+5];
char _s[10000010];

namespace Hash{
    ULL h[10000010];
    
    void init(int *s, int l, int r){
        h[l-1]=1;
        for(int i=l; i<=r; i++) h[i]=h[i-1]*7+s[i];
    }
    
    ULL query(int l, int r){return h[r]-h[l-1]*bin[r-l+1];}
}

int main(){
    int opt, x, y, K;
    in(N); in(M);
    bin[0]=1;
    for(int i=1; i<=MAX_K; i++) bin[i]=bin[i-1]*7;
    for(int i=1; i<=N; i++){
        in(node[i].val);
        H[1].insert(node[i].val);
    }
    while(M--){
        in(opt);
        if(opt==1){
            in(x); in(y);
            int L=MAX_K+1, R=MAX_K;
            Node *v=node+x;
            while(L>1 && v) f[--L]=v->val, v=v->pre;
            v=node+y;
            while(R<2*MAX_K && v) f[++R]=v->val, v=v->ne;
            Hash::init(f, L, R);
            for(int i=L; i<=MAX_K; i++)
                for(int j=MAX_K+1; j<=std::min(R, i+49); j++)
                    H[j-i+1].insert(Hash::query(i, j));
            node[x].ne=node+y; node[y].pre=node+x;
        }else if(opt==2){
            in(x);
            int L=MAX_K+1, R=MAX_K;
            Node *v=node+x;
            while(L>1 && v) f[--L]=v->val, v=v->pre;
            v=node+x; v=v->ne;
            while(R<2*MAX_K && v) f[++R]=v->val, v=v->ne;
            Hash::init(f, L, R);
            for(int i=L; i<=MAX_K; i++)
                for(int j=MAX_K+1; j<=std::min(R, i+49); j++) 
                    H[j-i+1].erase(Hash::query(i, j));
            node[x].ne->pre=NULL; node[x].ne=NULL;
        }else{
            scanf("%s", _s+1);
            in(K); int l=strlen(_s+1);
            for(int i=1; i<=l; i++) s[i]=_s[i]-'0';
            int ans=1;
            Hash::init(s, 1, l);
            for(int i=K; i<=l; i++)
                ans=1LL*ans*H[K].count(Hash::query(i-K+1, i))%MOD;
            printf("%d\n", ans);
        }
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1845 us4 MB + 956 KBAcceptedScore: 4

Testcase #2595.75 us5 MB + 384 KBAcceptedScore: 4

Testcase #314.104 ms10 MB + 700 KBAcceptedScore: 4

Testcase #42.016 ms16 MB + 616 KBAcceptedScore: 4

Testcase #511.169 ms20 MB + 300 KBAcceptedScore: 4

Testcase #6217.315 ms326 MB + 76 KBAcceptedScore: 4

Testcase #719.688 ms5 MB + 712 KBAcceptedScore: 4

Testcase #8136.037 ms324 MB + 44 KBAcceptedScore: 4

Testcase #9223.943 ms328 MB + 96 KBAcceptedScore: 4

Testcase #10191.629 ms329 MB + 636 KBAcceptedScore: 4

Testcase #11369.654 ms331 MB + 620 KBAcceptedScore: 4

Testcase #12230.517 ms339 MB + 300 KBAcceptedScore: 4

Testcase #1338.658 ms5 MB + 712 KBAcceptedScore: 4

Testcase #14262.692 ms348 MB + 228 KBAcceptedScore: 4

Testcase #15332.572 ms349 MB + 256 KBAcceptedScore: 4

Testcase #16388.986 ms351 MB + 988 KBAcceptedScore: 4

Testcase #17586.029 ms352 MB + 116 KBAcceptedScore: 4

Testcase #18716.005 ms384 MB + 416 KBAcceptedScore: 4

Testcase #19877.006 ms386 MB + 720 KBAcceptedScore: 4

Testcase #20207.771 ms335 MB + 1012 KBAcceptedScore: 4

Testcase #2177.763 ms5 MB + 724 KBAcceptedScore: 4

Testcase #22551.73 ms379 MB + 976 KBAcceptedScore: 4

Testcase #23603.846 ms379 MB + 276 KBAcceptedScore: 4

Testcase #24830.773 ms385 MB + 608 KBAcceptedScore: 4

Testcase #251.043 s384 MB + 272 KBAcceptedScore: 4


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:12:43 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠