2020.1.5考试总结

Posted wljss

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2020.1.5考试总结相关的知识,希望对你有一定的参考价值。

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

#include<iostream>
#include<cstring>
#include<cstdio>
#define lson (k<<1)
#define rson ((k<<1)|1)
using namespace std;
int n, m, r, q, opt, x, y, v, ans, To, tot;
const int N = 130005;
int sum[N << 2][1 << 6], lz[N << 2];
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;
}
struct ju 
{
    int c[3][4];
    friend ju operator ^(const ju &a, const ju &b) 
    {
        ju c;
        memset(c.c, 0, sizeof(c.c));
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= m; ++j)
                c.c[i][j] = a.c[i][j] ^ b.c[i][j];
        return c;
    }
} to, tmp, tr[N << 2];
inline void fu(ju &x, int v) 
{
    memset(x.c, 0, sizeof(x.c));
    if (v <= n)
        for (int i = 1; i <= m; ++i)x.c[v][i] = 1;
    else 
    {
        v -= n;
        for (int i = 1; i <= n; ++i)x.c[i][v] = 1;
    }
}
inline int to1(ju x) 
{
    int res = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            res = (res << 1) | x.c[i][j];
    return res;
}
inline ju to2(int x) 
{
    ju res;
    memset(res.c, 0, sizeof(res.c));
    for (int i = n; i >= 1; --i)
        for (int j = m; j >= 1; --j)
            res.c[i][j] = (x & 1), x >>= 1;
    return res;
}
inline void upd(int k) 
{
    int tmp;
    tr[k] = tr[lson] ^ tr[rson];
    for (int i = 0; i < tot; ++i)sum[k][i] = sum[lson][i];
    tmp = to1(tr[lson]);
    for (int i = 0; i < tot; ++i)sum[k][i ^ tmp] += sum[rson][i];
}
void build(int k, int l, int r) 
{
    lz[k] = -1;
    if (l == r) 
    {
        fu(tr[k], 1); sum[k][to1(tr[k])] = 1;
        return;
    }
    int mid = (l + r) >> 1;
    build(lson, l, mid); build(rson, mid + 1, r);
    upd(k);
}
inline void work(int k, int l, int r, int v) 
{
    tr[k] = to2((r - l + 1) & 1 ? v : 0);
    lz[k] = v;
    for (int i = 0; i < tot; ++i)sum[k][i] = 0;
    sum[k][v] = (r - l + 2) >> 1; sum[k][0] = (r - l + 1) - sum[k][v];
}
inline void cd(int k, int l, int r) 
{
    int mid = (l + r) >> 1;
    work(lson, l, mid, lz[k]); work(rson, mid + 1, r, lz[k]);
    lz[k] = -1;
}
void change(int k, int l, int r, int x, int y, int v) 
{
    if (x <= l && r <= y) 
    {
        work(k, l, r, v);
        return;
    }
    if (lz[k] != -1)cd(k, l, r);
    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);
    upd(k);
}
int ask2(int k, int l, int r, int x, int y, int val) 
{
    if (x <= l && r <= y)return sum[k][val];
    if (lz[k] != -1)cd(k, l, r);
    int res = 0, mid = (l + r) >> 1;
    if (x <= mid)res += ask2(lson, l, mid, x, y, val);
    if (mid + 1 <= y)res += ask2(rson, mid + 1, r, x, y, val ^ to1(tr[lson]));
    return res;
}
void solve2() 
{
    ju tmp;
    build(1, 1, r);
    while (q--) 
    {
        opt = read();
        if (opt == 0) 
        {
            x = read(); y = read();
            fu(tmp, y);
            change(1, 1, r, x, x, to1(tmp));
        }
        if (opt == 1) 
        {
            x = read(); y = read();
            printf("%d
", ask2(1, 1, r, x, y, To));
        }
        if (opt == 2) 
        {
            x = read(); y = read(); v = read();
            fu(tmp, v);
            change(1, 1, r, x, y, to1(tmp));
        }
    }
}
int main() 
{
    cin >> n >> m; tot = (1 << (n * m));
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            to.c[i][j] = read();
    To = to1(to);
    cin >> r >> q;
    solve2();
    fclose(stdin); fclose(stdout);
    return 0;
}

以上是关于2020.1.5考试总结的主要内容,如果未能解决你的问题,请参考以下文章

python常用代码片段总结

BootStrap有用代码片段(持续总结)

扫地阿姨看完都学会了!java高级架构师考试

BootStrap实用代码片段(持续总结)

回归 | js实用代码片段的封装与总结(持续更新中...)

考试总结 模拟30