其他分享
首页 > 其他分享> > 正睿二轮省选day1

正睿二轮省选day1

作者:互联网

期望:100+16+8

实际:0+16+8

T1:

  最后的二分找每个1的位置写没了,本机上测爆longlong会到负数,但正睿的机子不是,判错了,直接爆0

  现在仍有三个点迷之wa掉

  70pts码

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;

const int N = 1000010;
const LL mod = 998244353;


inline LL read()
{
    LL x = 0, f = 0;
    char ch = getchar();
    while (!isdigit(ch)) f = ch == '-', ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    return f ? -x : x;
}

inline bool check(LL h, LL K)
{
    LL res = 1, a = 2ll;
    while (h)
    {
        if (h & 1) res = res * a;
        a = a * a;
        h >>= 1;
        if (res >= K || (a > 1e9 && h)) return false;
    }
    return true;
}

inline LL qpow(LL a, LL k, LL mod)
{
    LL res = 1;
    while (k)
    {
        if (k & 1) res = res * a % mod;
        a = a * a % mod;
        k >>= 1;
    }
    return res;
}

inline LL C(const int n, int m)
{
    if (m > n || n < 0 || m < 0) return 0;
    if (m > n - m) m = n - m;
    LL res = 1, mu = 1;
    for (int i = 1; i <= m; ++i)
    {
        res = res * (n - i + 1) / i;
        if (res >= 1e18 || res < 0) return 2e18;
    }
    return res;
}

int main()
{
    int T = read();
    while (T--)
    {
        LL n = read(), K = read();

        LL h = sqrt(n * 2);
        while (h * (h + 1) / 2 < n) h++;
        while (h * (h + 1) / 2 > n) h--;
        LL t = n - h * (h + 1) / 2;
        h++;

        LL ans = ((qpow(2, h, mod) - qpow(2, h - t, mod)) % mod + mod) % mod;
        if (t == 0 && K == 1) { printf("%lld\n", qpow(2, h - 1, mod) - 1); continue; }
        else if (t == 0) { puts("-1"); continue; }
        if (K == 1) { printf("%lld\n", ans); continue; }
        if (check(h - t - 1, K)) { puts("-1"); continue; }

        K--;
        LL res = 0, x = h - t - 1, y = 1, c = 1, rk = 0;
        for (int i = h - t - 1; i; i--)
        {
            c = c * x / y;
            if (res + c >= K)
            {
                K -= res;
                rk = h - t - i;
                break;
            }
            res = res + c;
            x--, y = h - t - i + 1;
        }

        LL siz = h - t - 1;
        if (K)
            for (int i = 1; i <= rk; i++)
            {
                LL l = 1, r = siz;
                while (l < r)
                {
                    int mid = l + r >> 1;
                    LL q = C(mid, rk - i + 1);
                    if (q < K) l = mid + 1;
                    else r = mid;
                }
                siz = l - 1;
                ans = (ans + qpow(2, siz, mod)) % mod;
                K -= C(l - 1, rk - i + 1);
            }
        printf("%lld\n", ans);
    }
}
View Code

T2:

  考场上看出来了,SAM模板题,但是我不会写,只写了暴力

#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;

#define mp make_pair

typedef long long LL;
typedef pair<int, int> PII;

const int N = 50010;

map<PII, int> vis;

struct String
{
    int siz, last;
    string str;

    struct Node
    {
        int len, link;
        map<char, int> nex;
        Node() {}
    };

    map<int, Node> st;

    void sam_extend(char c)
    {
        int cur = siz++;
        st[cur].len = st[last].len + 1;
        int p = last;
        while (p != -1 && !st[p].nex.count(c))
        {
            st[p].nex[c] = cur;
            p = st[p].link;
        }
        if (p == -1)
        {
            st[cur].link = 0;
        }
        else
        {
            int q = st[p].nex[c];
            if (st[p].len + 1 == st[q].len)
            {
                st[cur].link = q;
            }
            else
            {
                int clone = siz++;
                st[clone].len = st[p].len + 1;
                st[clone].nex = st[q].nex;
                st[clone].link = st[q].link;
                while (p != -1 && st[p].nex[c] == q)
                {
                    st[p].nex[c] = clone;
                    p = st[p].link;
                }
                st[q].link = st[cur].link = clone;
            }
        }
        last = cur;
    }

    inline void init()
    {
        st[0].len = 0;
        st[0].link = -1;
        siz++, last = 0;
    }

    inline void New()
    {
        cin >> str;
        init();
        for (int i = 0; i < str.size(); i++) sam_extend(str[i]);
    }

    inline int find(string T)
    {
        int v = 0, l = 0, best = 0, bestpos = 0;
        for (int i = 0; i < T.size(); i++)
        {
            while (v && !st[v].nex.count(T[i])) 
            {
                v = st[v].link;
                l = st[v].len;
            }
            if (st[v].nex.count(T[i])) 
            {
                v = st[v].nex[T[i]];
                l++;
            }
            if (l > best)
            {
                best = l;
                bestpos = i;
            }
        }
        return best;
    }
};

map<int, String> S;
int n;

int main()
{
    int q;
    scanf("%d%d", &n, &q);

    for (int i = 0; i < n; i++) S[i].New();

    while (q--)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        if (S[a].str.size() > S[b].str.size()) swap(a, b);
        if (vis[mp(a, b)]) printf("%d\n", vis[mp(a, b)]);
        else printf("%d\n", vis[mp(a, b)] = S[b].find(S[a].str));
    }
    return 0;
}
View Code

T3:

  不会

标签:include,省选,res,LL,st,int,正睿,day1,mod
来源: https://www.cnblogs.com/Arrogant-Hierarch/p/14417799.html