2020.1.9考试总结

T1
数据范围很合适..
第一档就是暴力枚举
第二档就是数位DP
第三档就是矩阵乘法
丢一下学长的博客

#include<iostream>
#include<cstring>
#include<cstdio>
#define LL long long
using namespace std;
LL n;
const int mod = 1e9 + 7;
struct ju
{
    LL c[4][4];
    friend ju operator *(const ju &a, const ju &b)
    {
        ju c;
        memset(c.c, 0, sizeof(c.c));
        for (int i = 1; i <= 3; ++i)
            for (int j = 1; j <= 3; ++j)
                for (int k = 1; k <= 3; ++k)
                    c.c[i][j] += a.c[i][k] * b.c[k][j] % mod, c.c[i][j] %= mod;
        return c;
    }
} base, ans;
LL ksm(LL a, LL b, LL mod)
{
    LL res = 1;
    for (; b; b >>= 1, a = a * a % mod)
        if (b & 1)res = res * a % mod;
    return res;
}
ju ksm(ju a, LL b)
{
    ju res;
    memset(res.c, 0, sizeof(res.c));
    for (int i = 1; i <= 3; ++i)res.c[i][i] = 1;
    for (; b; b >>= 1, a = a * a)
        if (b & 1)res = res * a;
    return res;
}
int main()
{
    freopen("number.in", "r", stdin);
    freopen("number.out", "w", stdout);
    cin >> n;
    base.c[1][1] = 3; base.c[1][2] = 2; base.c[1][3] = 0;
    base.c[2][1] = 1; base.c[2][2] = 3; base.c[2][3] = 1;
    base.c[3][1] = 0; base.c[3][2] = 2; base.c[3][3] = 3;
    ans .c[1][1] = 3;
    ans .c[2][1] = 1;
    ans .c[3][1] = 0;
    ans = ksm(base, n - 1) * ans;
    (((ans.c[1][1] -= ksm(2, n, mod) + ksm(4, n, mod) % mod) %= mod) += mod) %= mod;
    ans.c[1][1] += ksm(3, n, mod);
    cout << ans.c[1][1] % mod;
    fclose(stdin); fclose(stdout);
    return 0;
}

T2
发现一个位置的值是奇数当且仅当 它所在的行加的次数+它所在的列加的次数 的和是奇数。
当有x行加了奇数次,y列加了奇数次,那么奇数个数就是(n-x)y+x(m-y)
枚举x,可以解方程得到y,特判一下(2x==n&&xm==k)的情况(化一化式子就知道了),贡献就是\(\displaystyle C_n^xC_m^yC_{\frac{r-x}{2}+n-1}^{n-1}C_{\frac{c-y}{2}+m-1}^{m-1}\)
大力卡一卡边界就行了。

#include<iostream>
#include<cstdio>
#define int long long
#define LL long long
#define DB double
using namespace std;
LL n, m, r, c, k, ans;
const int N = 400010, M = 200000, mod = 1e9 + 7;
LL jc[N], inv[N];
inline int read()
{
    int res = 0; char ch = getchar(); bool XX = false;
    for (; !isdigit(ch); ch = getchar())(ch == '-') && (XX = true);
    for (; isdigit(ch); ch = getchar())res = (res << 3) + (res << 1) + (ch ^ 48);
    return XX ? -res : res;
}
LL ksm(LL a, LL b, LL mod)
{
    LL res = 1;
    for (; b; b >>= 1, a = a * a % mod)
        if (b & 1)res = res * a % mod;
    return res;
}
void YYCH()
{
    jc[0] = jc[1] = inv[0] = inv[1] = 1;
    for (int i = 2; i <= M; ++i)jc[i] = jc[i - 1] * i % mod;
    inv[M] = ksm(jc[M], mod - 2, mod);
    for (int i = M - 1; i >= 1; --i)inv[i] = inv[i + 1] * (i + 1) % mod;
}
LL C(LL n, LL m) {if (n < m)return 0; return jc[n] * inv[m] % mod * inv[n - m] % mod;}
void suan(LL x, LL y)
{
    if (((r - x) & 1) || ((c - y) & 1))return;
    ans += C(n, x) * C(m, y) % mod * C(((r - x) >> 1) + n - 1, n - 1) % mod * C(((c - y) >> 1) + m - 1, m - 1) % mod, ans %= mod;
}
DB jue(DB x) {return x > 0 ? x : -x;}
int zheng(DB x)
{
    return jue(x - (int)x) < 1e-3;
}
signed main()
{
    freopen("matrix.in", "r", stdin);
    freopen("matrix.out", "w", stdout);
    cin >> n >> m >> r >> c >> k;
    YYCH();
    for (int x = (r & 1); x <= n; x += 2)
    {
        if (n == 2 * x)
        {
            if (x * m == k) for (int y = (c & 1); y <= m; y += 2)suan(x, y);
        }
        else
        {
            DB y = (DB)(k - x * m) / (n - 2 * x);
            if ((int)y < 0 || !zheng(y))continue;
            suan(x, y);
        }
    }
    cout << ans;
    fclose(stdin); fclose(stdout);
    return 0;
}

T3
前置题目线段树做法
首先离线...
原来的题目限制的只有自己这个位置,现在变成了它及它前边的k个位置。
线段树维护 区间取min,单点查询 即可。
考场上没开的空间直接凉凉...
好像这道题莫队跑得挺快的。

#include<algorithm>
#include<iostream>
#include<cstdio>
#define lson (k<<1)
#define rson ((k<<1)|1)
#define LL long long
#define DB double
using namespace std;
int n, m, q, k;
const int N = 400010, inf = 1e9;
int vis[N], a[N], ans[N], to[N][11], las[N], tr[N << 2], lz[N << 2];
struct Ask {int l, r, ans, id;} Q[N];
int my1(const Ask &a, const Ask &b) {return a.l < b.l;}
int my2(const Ask &a, const Ask &b) {return a.id < b.id;}
inline int read()
{
    int res = 0; char ch = getchar(); bool XX = false;
    for (; !isdigit(ch); ch = getchar())(ch == '-') && (XX = true);
    for (; isdigit(ch); ch = getchar())res = (res << 3) + (res << 1) + (ch ^ 48);
    return XX ? -res : res;
}
void Write(int x, int opt)
{
    if (opt && !x)putchar('0');
    if (!x)return; Write(x / 10, 0);
    putchar((x - x / 10 * 10) + '0');
}
void build(int k, int l, int r)
{
    lz[k] = inf;
    if (l == r)
    {
        tr[k] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(lson, l, mid); build(rson, mid + 1, r);
}
inline void cd(int k)
{
    lz[lson] = min(lz[lson], lz[k]); lz[rson] = min(lz[rson], lz[k]);
    lz[k] = inf;
}
void change(int k, int l, int r, int x, int y, int v)
{
    if (x <= l && r <= y)
    {
        lz[k] = min(lz[k], v);
        return;
    }
    if (lz[k] != inf)cd(k);
    int mid = (l + r) >> 1;
    if (x <= mid)change(lson, l, mid, x, y, v);
    if (mid + 1 <= y)change(rson, mid + 1, r, x, y, v);
}
int ask(int k, int l, int r, int pos)
{
    if (l == r)
    {
        return min(lz[k], tr[k]);
    }
    if (lz[k] != inf)cd(k);
    int mid = (l + r) >> 1;
    if (pos <= mid)return ask(lson, l, mid, pos);
    else return ask(rson, mid + 1, r, pos);
}
inline void solve2()
{
    for (int i = 1; i <= q; ++i)
    {
        Q[i].l = read(); Q[i].r = read(); Q[i].id = i;
    }
    sort(Q + 1, Q + 1 + q, my1);
    int now = 1;
    for (int i = 1; i <= m; ++i)
    {
        for (int j = max(1, a[i] - k + 1); j <= a[i]; ++j)
        {
            vis[j] = 1;
            to[las[j]][a[las[j]] - j] = i;
            las[j] = i;
        }
        while (vis[now])++now;
        ans[i] = now;
    }
    for (int i = 1; i <= n; ++i)to[las[i]][a[las[i]] - i] = m + 1;
    build(1, 1, m);
    now = 1; int pos;
    for (int i = 1; i <= m; ++i)
    {
        while (Q[now].l == i)
        {
            Q[now].ans = ask(1, 1, m, Q[now].r);
            ++now;
        }
        for (int j = max(1, a[i] - k + 1); j <= a[i]; ++j)
        {
            pos = to[i][a[i] - j] - 1;
            change(1, 1, m, i, pos, j);
        }
    }
    sort(Q + 1, Q + 1 + q, my2);
    for (int i = 1; i <= q; ++i)
    {
        if (Q[i].ans > n - k + 1)puts("-1");
        else Write(Q[i].ans, 1), putchar('\n');
    }
}
int main()
{
    freopen("stall.in", "r", stdin);
    freopen("stall.out", "w", stdout);
    cin >> n >> m >> q >> k;
    for (int i = 1; i <= m; ++i)a[i] = read();
    solve2();
    fclose(stdin); fclose(stdout);
    return 0;
}

原文地址:https://www.cnblogs.com/wljss/p/12173015.html

时间: 2024-08-30 17:42:58

2020.1.9考试总结的相关文章

脱产备考CPA是孤注一掷?应该如何备考2020年注册会计师考试?

在浩浩荡荡的CPA备考大军中,有朝九晚五想要寻求职业突破的上班族,有家务孩子一把抓的全职妈妈,也有想要奋力一搏的脱产人员--背景不同,面临的问题当然有所不同.而与其他人相比,脱产备考的考生心理压力总是格外的重,毕竟没有工作,没有收入,甚至可能得不到家人朋友的理解,如此全力以赴.孤注一掷的冒险,无非是希望自己能比别人多占据一些备考优势,那么脱产人员应该如何备考2020年注册会计师考试呢?老实说,对于选择脱产备考的人来说,时间确实足够充裕,但要想把时间充分利用起来,争取一次性过五科甚至六科,以下几个

2020.1.2考试总结

T1圆圈游戏 暴力DP有60分,设包含圆i的最小的圆是fa[i],那没最终会的得到一棵树,对于一棵子树,选了根节点就不能选子树内其它点,f[i]=max(w[i],\(\sum f[son]\)). 瓶颈就在怎么建图,因为圆不相交相切,所以扫描线的时候相对位置不会发生改变,用set维护一下就好啦. #include<algorithm> #include<iostream> #include<cmath> #include<queue> #include&l

2020.1.5考试总结

T1和T3不太可做..先只放一下T2 TMD考场上没算好空间直接MLE爆零... 操作1可以归到操作3里,并且几个人的操作可以合并到一块,用线段树挺好维护的. 对于询问的话可以对每一个节点开一个桶,记录区间内前缀数量,向上合并的时候左儿子直接加,右儿子异或后再加. 发现很多节点根本用不到,动态开点即可. #include<iostream> #include<cstring> #include<cstdio> #define lson (k<<1) #def

2020.1.11考试总结

恭贺 treAKer 在毒瘤之神的考验一题中rank1,成为新一届毒瘤之神! ...... 结果今天就考了 treAKer 的毒瘤题... T1 考场上看到1e6就想O(n)的做法,结果失败了... 正解思路很神奇,就是先对物品按照a来排序,询问按照m来排序,用双指针一起扫,同时维护\(f_i\) 当物品的和为i时 在所有的方案中,最小的b最大 的方案中的 b值.判一下\(f_i\)和m+s的大小关系即可. #include<algorithm> #include<cstring>

2020.3.1考试T1 多项式

出题人很凉心的把算法写成了题目名 首先我们可以发现每一维的贡献是独立的,这可以从 \(solve1\) 里看出来 然后我们可以考虑转化为 \(DP\) ,这可以从 \(solve2\) 里看出来 我们统计每一维能产生的贡献,就是 \(a\) 个 \(0\) 面, \(b\) 个 \(1\) 面, \(c\) 个 \(2\) 面这种形式,能写成一个多项式 \(ax^0+bx^1+cx^2\),而我们最终显然就是把所有的多项式都乘起来. 暴力一个一个乘就很 naive,分治 \(NTT\) 解决就好

2019OKR规划

转眼又一年过去了,回顾审视一年的得失,规划下一年的奋斗目标.Review And Planning,让全新的2019迎来全新的自己. O1 学习软件开发技术知识 KR1.1 阅读<CLR via C#(第四版)> KR1.2 阅读<代码整洁之道> KR1.3 阅读<VUE.js权威指南> KR1.4 阅读Python相关书籍1本 KR1.5 阅读<Microsoft.NET 企业级应用架构设计> KR1.6 阅读<.NET微服务:容器化.NET应用架构

【晨间日记】35计划第0004天(191206)

晨间日记:35计划第0004天(191206) 一.三早 1.早睡:11:30 2.早起:07:00 3.早读:英语口语练习.单词背诵 二.每日基础 1.晨间日记:每日早上写. 2.每日博客:每天至少写一篇博客(博客园.CSDN.简书). 3.每日学习:每天职业技能书籍至少学习一章. 4.每日阅读:每天阅读技术类博客 30 - 60 分钟. 5.学习计划:<操作系统>学习. 6.工作学习:PowerShell 学习. 三.昨日总结 1.晨间日记:完成 2.每日博客:[黑客基础]Windows

2020奕诚国家电网考试资料全套视频

链接:https://pan.baidu.com/s/1npAYuq7Yg6zSrdiQ55oVyA 提取码:ub4t 复制这段内容后打开百度网盘手机App,操作更方便哦 2020奕诚国家电网考试视频资料 综合(行测)(高清完整版) 2020奕诚国家电网考试视频资料 电路(高清完整版) 2020奕诚国家电网考试视频资料电工类 电分(高清完整版) 2020奕诚国家电网考试视频资料 继保(高清完整版) 2020奕诚国家电网考试视频资料 龙腾分科测试题讲解 电路 (高清完整版) 2020奕诚国家电网考

2020年出版专业技术人员职业资格考试,历年真题,考前复习,考试大纲,视频课程

各出版社.期刊社.新媒体单位.网络出版单位: 从2001年8月1日起,国家对出版专业技术人员实行职业资格制度,纳入全国专业技术人员职业资格制度的统一规划.同时在2016年3月10日,由国家新闻出版广电总局.中华人民共和国工业和信息化部联合发布的<网络出版服务管理规定>中,第二章第九条明确规定,从事网络出版服务单位,必须有8名以上具有<中华人民共和国出版专业技术人员职业资格证书>人员,其中中级以上人员不少于3名.<中华人民共和国出版专业技术人员职业资格证书>是传统出版行业