提交记录 4461


用户 题目 状态 得分 用时 内存 语言 代码长度
itdevwu noi17b. 【NOI2017】蚯蚓排队 Accepted 100 1.088 s 136136 KB C++11 2.98 KB
提交时间 评测时间
2018-07-23 16:41:46 2020-07-31 23:02:58
#include <bits/stdc++.h>
using namespace std;
// 137 149
const int N = 2e5 + 10, mod = 998244353;
typedef unsigned long long ll;
const ll base = 137;
ll pw[N];
int n, m, a[N], lst[N], nxt[N], seq[N];
char s[(int) 1e7 + 10];

//map<ll, int> cnt[16777217];

int head[16777217], rest[16777217], val[16777217], tot;
ll to[16777217];

inline void ins(ll x, int c) {
    int u = x & 16777215;
    for(int i = head[u] ; i ; i = rest[i]) {
        if(to[i] == x) {
            val[i] += c;
            return ;
        }
    }
    to[++ tot] = x, val[tot] = c, rest[tot] = head[u], head[u] = tot;
}

inline int query(ll x) {
    for(int i = head[x & 16777215] ; i ; i = rest[i])
        if(to[i] == x)
            return val[i];
    return 0;
}

inline void fafa(int x, int y) {
    int bef_tot = 0, aft_tot = 0;
    for(int u = x ; bef_tot <= 50 && u ; u = lst[u])
        seq[++ bef_tot] = a[u];
    reverse(seq + 1, seq + 1 + bef_tot);
    int tot = bef_tot;
    for(int u = y ; aft_tot <= 50 && u ; u = nxt[u])
        seq[++ tot] = a[u];
    for(int i = 1 ; i <= bef_tot ; ++ i) {
        ll hs = 0;
        for(int j = i ; j <= tot ; ++ j) {
            hs = hs * base + seq[j];
            if(j - i + 1 > 50) break;
            if(j > bef_tot) ins(hs, 1);
        }
    }
}

inline void gygy(int x, int y) {
    int bef_tot = 0, aft_tot = 0;
    for(int u = x ; bef_tot <= 50 && u ; u = lst[u])
        seq[++ bef_tot] = a[u];
    reverse(seq + 1, seq + 1 + bef_tot);
    int tot = bef_tot;
    for(int u = y ; aft_tot <= 50 && u ; u = nxt[u])
        seq[++ tot] = a[u];;
    for(int i = 1 ; i <= bef_tot ; ++ i) {
        ll hs = 0;
        for(int j = i ; j <= tot ; ++ j) {
            hs = hs * base + seq[j];
            if(j - i + 1 > 50) break;
            if(j > bef_tot) ins(hs, -1);
        }
    }
}

inline void read(int &x) {
    char c = x = 0;
    while(!isdigit(c)) c = getchar();
    while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
}

int main() {
    pw[0] = 1; for(int i = 1 ; i < N ; ++ i) pw[i] = pw[i - 1] * base;
    read(n), read(m);
    for(int i = 1 ; i <= n ; ++ i) read(a[i]), ins(a[i], 1);
    for(int i = 1 ; i <= m ; ++ i) {
        int op, x, y, k;
        read(op);
        if(op == 1) {
            read(x), read(y);
            lst[y] = x, nxt[x] = y;
            fafa(x, y);
        } else if(op == 2) {
            read(x);
            int y = nxt[x];
            lst[y] = 0, nxt[x] = 0;
            gygy(x, y);
        } else {
            scanf("%s", s + 1), read(k);
            int ans = 1, len = strlen(s + 1);
            ll hs = 0;
            if(k <= len) {
                for(int i = 1 ; i <= k ; ++ i)
                    hs = hs * base + s[i] - '0';
                ans = query(hs);
                for(int i = 2 ; i + k - 1 <= len ; ++ i) {
                    hs = (hs - (s[i - 1] - '0') * pw[k - 1]) * base + s[i + k - 1] - '0';
                    ans = ((long long) ans * query(hs)) % mod;
                }
            } else ans = 0;
            printf("%d\n", ans);
        }
    }
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1646.73 us1 MB + 596 KBAcceptedScore: 4

Testcase #2317.52 us1 MB + 864 KBAcceptedScore: 4

Testcase #37.788 ms7 MB + 72 KBAcceptedScore: 4

Testcase #41.68 ms12 MB + 748 KBAcceptedScore: 4

Testcase #57.578 ms16 MB + 732 KBAcceptedScore: 4

Testcase #6131.381 ms84 MB + 932 KBAcceptedScore: 4

Testcase #715.467 ms2 MB + 372 KBAcceptedScore: 4

Testcase #877.82 ms81 MB + 948 KBAcceptedScore: 4

Testcase #9136.066 ms85 MB + 816 KBAcceptedScore: 4

Testcase #10136.437 ms83 MB + 104 KBAcceptedScore: 4

Testcase #11300.451 ms90 MB + 884 KBAcceptedScore: 4

Testcase #12137.884 ms87 MB + 896 KBAcceptedScore: 4

Testcase #1331.918 ms2 MB + 964 KBAcceptedScore: 4

Testcase #14162.292 ms95 MB + 748 KBAcceptedScore: 4

Testcase #15209.188 ms98 MB + 216 KBAcceptedScore: 4

Testcase #16300.619 ms98 MB + 468 KBAcceptedScore: 4

Testcase #17552.806 ms105 MB + 300 KBAcceptedScore: 4

Testcase #18530.957 ms127 MB + 296 KBAcceptedScore: 4

Testcase #19702.574 ms132 MB + 968 KBAcceptedScore: 4

Testcase #20127.102 ms82 MB + 156 KBAcceptedScore: 4

Testcase #2166.046 ms4 MB + 80 KBAcceptedScore: 4

Testcase #22372.228 ms121 MB + 188 KBAcceptedScore: 4

Testcase #23408.825 ms122 MB + 284 KBAcceptedScore: 4

Testcase #24693.279 ms126 MB + 636 KBAcceptedScore: 4

Testcase #251.088 s132 MB + 864 KBAcceptedScore: 4


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