The Preliminary Contest for ICPC Asia Shanghai 2019

D. Counting Sequences I

暴力搜索。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

map<vector<short>, short> m;
vector<short> vec;

void calc(int num1) {
    vector<short> tmp;
    if(num1)
        tmp.push_back(num1);
    int n = vec.size();
    int cur = 1;
    for(int i = 1; i < n; ++i) {
        if(vec[i] != vec[i - 1]) {
            tmp.push_back(cur);
            cur = 1;
        } else
            ++cur;
    }
    tmp.push_back(cur);
    sort(tmp.begin(), tmp.end());
    m[tmp]++;
}

void dfs(int last, int cur, ll pro, int sum) {
    for(int i = last; i <= 3000; ++i) {
        int tcur = cur + 1;
        ll tpro = pro * i;
        int tsum = sum + i;
        if(tpro - tsum + tcur > 3000)
            break;

        vec.push_back(i);
        calc(tpro - tsum);
        if(tpro * i - (tsum + i) + (tcur + 1) <= 3000)
            dfs(i, tcur, tpro, tsum);
        vec.pop_back();
    }
}

ll qpow(ll x, int n) {
    ll res = 1;
    while(n) {
        if(n & 1)
            res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

int ans[3005], prod[3005], invprod[3005];

void Init() {
    dfs(2, 0, 1, 0);
    prod[0] = 1;
    for(int i = 1; i <= 3000; ++i) {
        prod[i] = 1ll * prod[i - 1] * i % MOD;
        invprod[i] = qpow(prod[i], MOD - 2);
    }
    for(auto mi : m) {
        ll sum = 1;
        int len = 0;
        for(auto vi : mi.first) {
            len += vi;
            sum = (sum * invprod[vi]) % MOD;
        }
        sum = (sum * prod[len]) % MOD;
        sum = (sum * mi.second) % MOD;
        ans[len] = (sum + ans[len]) % MOD;
    }
    ans[0] = ans[1] = 0;
}

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    Init();
    int T;
    scanf("%d", &T);
    while(T--) {
        int n;
        scanf("%d", &n);
        printf("%d\n", ans[n]);
    }
}

H. Luhhy‘s Matrix

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;

struct Matrix {
    bitset<16> ma[16];
    Matrix() {}
    void Clear() {
        for(int i = 0; i < 16; ++i)
            ma[i] = 0;
    }
    void one() {
        Clear();
        for(int i = 0; i < 16; ++i)
            ma[i][i] = 1;
    }
    Matrix operator*(const Matrix& t)const {
        Matrix res;
        for(int i = 0; i < 16; ++i) {
            for(int k = 0; k < 16; ++k) {
                if(ma[i][k])
                    res.ma[i] ^= t.ma[k];
            }
        }
        return res;
    }
};

stack<Matrix> Stack1, Stack2;
Matrix ProdStack1, tmp;

void Push(uint seed, uint lastans) {
    seed ^= lastans;
    for(int i = 0; i < 16; ++i) {
        seed ^= seed * seed + 15;
        for(int j = 0; j < 16; ++j)
            tmp.ma[i][j] = (seed >> j) & 1;
    }
    Stack1.push(tmp);
    ProdStack1 = tmp * ProdStack1;
}

void Pop() {
    if(Stack2.empty()) {
        tmp.one();
        while(!Stack1.empty()) {
            tmp = tmp * Stack1.top();
            Stack1.pop();
            Stack2.push(tmp);
        }
        ProdStack1.one();
    }
    Stack2.pop();
}

uint ans[16][16];

inline void InitAns() {
    uint p17[16], p19[16];
    p17[0] = 1, p19[0] = 1;
    for(int i = 1; i < 16; ++i) {
        p17[i] = p17[i - 1] * 17u;
        p19[i] = p19[i - 1] * 19u;
    }
    for(int i = 0; i < 16; ++i) {
        for(int j = 0; j < 16; ++j)
            ans[i][j] = p17[i] * p19[j];
    }
}

uint Calc() {
    if(Stack1.empty() && Stack2.empty())
        return 0;
    tmp = ProdStack1;
    if(!Stack2.empty())
        tmp = tmp * Stack2.top();
    uint res = 0;
    for(int i = 0; i < 16; ++i) {
        for(int j = 0; j < 16; ++j) {
            if(tmp.ma[i][j])
                res += ans[i][j];
        }
    }
    return res;
}

inline void Read(uint &x) {
    x = 0;
    char ch = getchar();
    while(ch < '0' || ch > '9')
        ch = getchar();
    while(ch >= '0' && ch <= '9')
        x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
}

inline void Write(uint x) {
    if(x < 10)
        putchar(x + '0');
    else {
        Write(x / 10);
        putchar(x % 10 + '0');
    }
}

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    InitAns();
    uint T;
    Read(T);
    while(T--) {
        while(!Stack1.empty())
            Stack1.pop();
        while(!Stack2.empty())
            Stack2.pop();
        ProdStack1.one();
        uint n, t, seed, lastans = 0;
        Read(n);
        for(int i = 1; i <= n; ++i) {
            Read(t), Read(seed);
            if(t == 1)
                Push(seed, lastans);
            else
                Pop();
            lastans = Calc();
            Write(lastans);
            putchar('\n');
        }
    }
}

原文地址:https://www.cnblogs.com/Inko/p/11525037.html

时间: 2024-08-02 06:18:24

The Preliminary Contest for ICPC Asia Shanghai 2019的相关文章

The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力)

The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力) 传送门:https://nanti.jisuanke.com/t/41400 题意: 给你三个数组a,b,c,要你求有多少个三元组(i,j,k),使得 \[ \begin{array}{l}{\left|A_{i}-B_{j}\right| \leq C_{k}, \text { and }} \\ {\left|B_{j}-C_{k}\right| \leq

Digit sum-----The Preliminary Contest for ICPC Asia Shanghai 2019

A digit sum S_b(n)Sb?(n) is a sum of the base-bb digits of nn. Such as S_{10}(233) = 2 + 3 + 3 = 8S10?(233)=2+3+3=8, S_{2}(8)=1 + 0 + 0 = 1S2?(8)=1+0+0=1, S_{2}(7)=1 + 1 + 1 = 3S2?(7)=1+1+1=3. Given NN and bb, you need to calculate \sum_{n=1}^{N} S_b

The Preliminary Contest for ICPC Asia Shanghai 2019 G. Substring (滑窗+哈希)

G. Substring 哎 一直超时or超内存 然后一直改一直改 然后 是 答案错误 然后 然后 最后结论是哈希姿势不对 我在别的地方找了这个: //https://www.cnblogs.com/napoleon_liu/archive/2010/12/29/1920839.html uint32_t hash( uint32_t a) { a = (a+0x7ed55d16) + (a<<12); a = (a^0xc761c23c) ^ (a>>19); a = (a+0x

01背包方案数(变种题)Stone game--The Preliminary Contest for ICPC Asia Shanghai 2019

题意:https://nanti.jisuanke.com/t/41420 给你n个石子的重量,要求满足(Sum<=2*sum<=Sum+min)的方案数,min是你手里的最小值. 思路: 从最大重量的石子开始背包,每次ans+=dp[j-v[i]]就行了. 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include &

给定进制下1-n每一位数的共享(Digit sum)The Preliminary Contest for ICPC Asia Shanghai 2019

题意:https://nanti.jisuanke.com/t/41422 对每一位进行找循环节规律就行了. 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc exit strcat itoa system("cls") 4 #include <io

The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum

题目:https://nanti.jisuanke.com/t/41422 思路:预处理 #include<bits/stdc++.h> using namespace std; int dp[11][1000001]={0}; int main() { for(int i=2;i<=10;i++) { for(int j=1;j<=1000000;j++) { int t=j; int res=0; res=j%i; dp[i][j]=res+dp[i][j/i]+dp[i][j

The Preliminary Contest for ICPC Asia Shanghai 2019 B. Light bulbs

题目:https://nanti.jisuanke.com/t/41399 思路:差分数组 区间内操作次数为奇数次则灯为打开状态 #include<bits/stdc++.h> using namespace std; map<int,int>mp; int main() { int T; scanf("%d",&T); int n,m; int l,r; for(int i=1;i<=T;i++) { mp.clear(); scanf(&quo

The Preliminary Contest for ICPC Asia Shanghai 2019 D. Counting Sequences I

题目:https://nanti.jisuanke.com/t/41412思路:dfs           先取ai>2  2^12>3000 因此至多取11个 其余用1补           (3000*2)-(3000+2)=2998 那么需要加入2998个1 正好3000位 所以 3000是ai最大取值           计算ans时 有重复元素的排列组合 :如1112233 res=7!/(3!*2!*2!)           另外预处理阶乘及其逆元 #include<bit

The Preliminary Contest for ICPC Asia Shanghai 2019 J. Stone game

题目:https://nanti.jisuanke.com/t/41420 思路:当a(a∈S′)为最小值 如果Sum(S′)−a≤Sum(S−S′)成立 那么(∀t∈S′,Sum(S′)−t≤Sum(S−S′))恒成立            先算01背包方案数 再从小到大排序进行退背包 #include<bits/stdc++.h> using namespace std; const int mod=1e9+7; int a[400]; int dp[150001]; int main()