• The 2019 China Collegiate Programming Contest Harbin Site


    感觉这场好简单,去年场上做的CCPC都好难,嘤嘤嘤

    这场的题目都挺卡的。

    L. LRU Algorithm

    只能说这个时间非常的卡。

    写了哈希和散列表T掉了,然后改成暴力for询问判断,这下时间正常了,然后一直wa。最后发现询问全(0)的时候也要输出( ext{Yes}),是不是有一点点坑。

    哈希需要注意:

    • 哈希是将字符串看成(n)进制数,选取的(base)必须(geq)字符集大小。

    • 散列表这东西就是看上去很快,真正卡常的时候是不是应该看作一个(log)

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef double db;
    typedef pair <int, int> pin;
    typedef pair <ll, ll> pll;
    
    #ifndef ONLINE_JUDGE
    bool MEMORY_ST;
    #endif
    
    const int N = 5005;
    
    int T, n, qn, a[N], s[N], hq1[N], hq2[N], pos[N];
    bool ans[N];
    vector <int> q[N];
    
    inline void inc(int &x, int y, int P) {
        if (!(y >= 0 && y < P)) y = (y % P + P) % P;
        x += y;
        if (x >= P) x -= P;
    }
    
    namespace HashTable {
        int b1 = 8209, b2 = 7307, P1 = 999749, P2 = 10001659;
    }
    using HashTable::b1;
    using HashTable::b2;
    using HashTable::P1;
    using HashTable::P2;
    
    namespace Fread {
        const int L = 1 << 15;
        
        char buffer[L], *S, *T;
        
        inline char Getchar() {
            if(S == T) {
                T = (S = buffer) + fread(buffer, 1, L, stdin);
                if(S == T) return EOF;
            }
            return *S++;
        }
        
        template <class T> 
        inline void read(T &X) {
            char ch; T op = 1;
            for(ch = Getchar(); ch > '9' || ch < '0'; ch = Getchar())
                if(ch == '-') op = -1;
            for(X = 0; ch >= '0' && ch <= '9'; ch = Getchar()) 
                X = (X << 1) + (X << 3) + ch - '0'; 
            X *= op;
        }
        
    } using Fread::read;   
    
    #ifndef ONLINE_JUDGE
    bool MEMORY_ED;
    #endif
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("sample.in", "r", stdin);
        freopen("test.out", "w", stdout);
        clock_t st_clock = clock();
    #endif
    
        read(T);
        for (; T--; ) {
            read(n), read(qn);
            for (int i = 1; i <= n; i++) {
                read(a[i]);
                s[i] = pos[i] = 0;
            } 
            for (int i = 1; i <= qn; i++) ans[i] = 0;
            for (int m, i = 1; i <= qn; i++) {
                read(m);
                int cur1 = 0, cur2 = 0;
                for (int ix, j = 1; j <= m; j++) {
                    read(ix);
                    cur1 = 1LL * cur1 * b1 % P1;
                    inc(cur1, ix, P1);
                    cur2 = 1LL * cur2 * b2 % P2;
                    inc(cur2, ix, P2);
                } 
                q[m].emplace_back(i);
                hq1[i] = cur1, hq2[i] = cur2;
                if (cur1 == 0 && cur2 == 0) ans[i] = 1;
            }
            for (int i = 1; i <= n; i++) {
                int p = pos[a[i]];
                if (!p) {
                    for (int j = n - 1; j >= 1; j--) s[j + 1] = s[j];
                } else {
                    for (int j = p - 1; j >= 1; j--) s[j + 1] = s[j];
                }
                s[1] = a[i];
                int cur1 = 0, cur2 = 0;
                for (int j = 1; j <= n; j++) {
                    if (s[j] != 0) pos[s[j]] = j;
                    cur1 = 1LL * cur1 * b1 % P1;
                    inc(cur1, s[j], P1);
                    cur2 = 1LL * cur2 * b2 % P2;
                    inc(cur2, s[j], P2);
                    for (int k = 0; k < q[j].size(); k++) {
                        int id = q[j][k];
                        if (hq1[id] == cur1 && hq2[id] == cur2) {
                            ans[id] = 1;
                        }
                    }
                }
                // for (int j = 1; j <= n; j++)
                //     printf("%d%c", s[j], " 
    "[j == n]);
            }
            for (int i = 1; i <= qn; i++) puts(ans[i] ? "Yes" : "No");
            for (int i = 1; i <= n; i++) q[i].clear();
        }
    
    #ifndef ONLINE_JUDGE
        clock_t ed_clock = clock();
        printf("time = %f ms
    ", (double)(ed_clock - st_clock) / CLOCKS_PER_SEC * 1000);
        printf("memory = %.2f MB
    ", (&MEMORY_ED - &MEMORY_ST) / 1024.0 / 1024.0);
    #endif
        return 0;
    }
    
  • 相关阅读:
    git
    HTML5 新增语义化标签
    vue directive 常用指令
    JS 数组 数组迭代方法 map, forEach, filter, some, every,
    图片居中
    进度条
    移动页面 REM自适应
    轮播图基本样式
    webpack3.0
    关于码云中项目提交的问题
  • 原文地址:https://www.cnblogs.com/CzxingcHen/p/15450357.html
Copyright © 2020-2023  润新知