首页 > 其他分享 >Codeforces Round 976 (Div. 2)

Codeforces Round 976 (Div. 2)

时间:2024-10-03 14:49:37浏览次数:1  
标签:tmp 976 ll 10 int mo Codeforces Div id

C. Bitwise Balancing (C)

先求出 \(b - c\) 的值,再考虑 \(a\) 的每个二进制位取0或1对答案的影响。vp的时候不知道为什么错了很多次。

void solve() {
    ll b, c, d;
    scanf("%lld%lld%lld", &b, &c, &d);
    if(b - c > d) {
        printf("-1\n");
        return;
    }
    ll x = d - (b - c), cst = 0;
    for(int r = 0; r < 61; r++) {
        ll y = 1ll << r;
        if((y & b) == 0 && (y & c)) cst |= y;
    }
    x -= cst;
    if(x < 0) {
        printf("-1\n");
        return;
    }
    ll add = 0, sub = 0;
    for(int r = 0; r <= 61; r++) {
        ll y = 1ll << r;
        if((y & b) == 0 && (y & c) == 0) add |= y;
        else if((y & b) && (y & c)) add |= y, sub |= y;
    }
    if((x & add) == x && (x ^ sub) <= (1ll << 61)) printf("%lld\n", x ^ sub);
    else printf("-1\n");
}

D. Connect the Dots (D)

注意到 \(d \leq 10\),用10个并查集保存连边操作为 \(d_i\) 时的连通情况,同时维护每个并查集的右端点,每次从当前并查集最右侧开始遍历,可避免 \(d_i\) 相同时、对同一个点多次操作导致TLE. 最后合并每层的信息即可。

const int N = 2e5 + 10;
int f[12][N], r[12][N];
int find(int id, int i) {
    if(f[id][i] == i) return i;
    return f[id][i] = find(id, f[id][i]);
}
void merge(int id, int x, int y) {
    int fx = find(id, x), fy = find(id, y);
    f[id][fy] = fx;
    r[id][fx] = max(r[id][fx], r[id][fy]);
}
void solve() {
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i <= 10; i++) {
        for(int j = 1; j <= n; j++) {
            r[i][j] = f[i][j] = j;
        }
    }
    while(m--) {
        int a, d, k;
        scanf("%d%d%d", &a, &d, &k);
        if(find(d, a) != find(d, a + d * k)) {
            for(int i = a + d;;) {
                merge(d, a, i);
                if(find(d, a) == find(d, a + d * k)) break;
                int x = r[d][find(d, i)];
                i = x + d;
            }
        }
    }
    for(int i = 1; i <= 10; i++) {
        for(int j = 1; j <= n; j++) {
            int fa = find(i, j);
            if(fa != j) merge(0, j, fa);
        }
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
        if(f[0][i] == i) cnt++;
    }
    printf("%d\n", cnt);
}

E. Expected Power (E)

\(f(s)^2 = \sum\limits_{i = 0} ^ 9 \sum\limits_{j = 0} ^ 9 b_ib_j \times 2^{i + j}\),对每个二进制位,\(b_i\) 和 \(b_j\) 最多有4种不同的组合,维护每位每种情况的概率即可求得期望。

void solve() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    ll b = inv(10000);
    memset(dp, 0, sizeof(dp));
    for(int i = 1; i <= n; i++) {
        int p;
        scanf("%d", &p);
        p1[i] = p * b % mo;
        p0[i] = (1 - p1[i] + mo) % mo;
    }
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            dp[i][j][0][0] = 1;
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < 10; j++) {
            for(int k = 0; k < 10; k++) {
                int t1 = (a[i] >> j) & 1, t2 = (a[i] >> k) & 1;
                ll tmp[2][2];
                for(int p : {0, 1}) {
                    for(int q : {0, 1}) {
                        tmp[p][q] = dp[j][k][p][q] * p0[i] % mo + dp[j][k][p ^ t1][q ^ t2] * p1[i] % mo;
                        if(tmp[p][q] >= mo) tmp[p][q] -= mo;
                    }
                }
                for(int p : {0, 1}) {
                    for(int q : {0, 1}) {
                        dp[j][k][p][q] = tmp[p][q];
                    }
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            ans += dp[i][j][1][1] * (1 << i + j) % mo;
            if(ans >= mo) ans -= mo;
        }
    }
    printf("%lld\n", ans);
}

F还没补

标签:tmp,976,ll,10,int,mo,Codeforces,Div,id
From: https://www.cnblogs.com/meowqwq/p/18445678

相关文章

  • Codeforces Round 976 (Div. 2)
    一万五参赛,VP赛时629(唐了,E没想出来)A.FindMinimumOperations简单题。注意特判,用除法统计答案即可。#include<bits/stdc++.h>usingnamespacestd;intT,n,k;intmain(){ scanf("%d",&T); while(T--){ scanf("%d%d",&n,&k); if(k==1||n......
  • Codeforces Round 976 (Div. 2) 题解
    CodeforcesRound976(Div.2)题解2020B一个常见的想法:开关灯=异或,虽然在这道题里没啥用注意到,第i盏灯的按钮被按的次数就是i的除它本身以外的因子个数而完全平方数的因子数为奇数,其他数的因子数为偶数点击查看更多信息#include<bits/stdc++.h>usingnamespacestd;voi......
  • 题解:CF1976D Invertible Bracket Sequences
    可以在cnblog中阅读。题意给一个合法括号序列,问有多少区间\([l,r]\),使得将区间内的每个括号翻转后,括号序列仍合法。分析十分套路地,我们将(看成\(+1\),将)看成\(-1\),则一个括号序列合法的充要条件是转换后的序列满足:前缀和任意位置非负;最后一项为\(0\)。考虑翻转......
  • CodeForces - 118D - dp
    这道题的思路可能来源于步兵后面必须跟骑兵,反之亦然,那么一个兵种当前的状态肯定是由另一个兵种上一个的状态推来的(即取用该当前取用的兵种之前)。接下来就要考虑怎么控制每次取用多少个人了,由题意可知,每次取用不得超过k1或k2,我们从1-n1和从1-n2表示骑兵和步兵当前的数量表示......
  • Codeforces Round 975 (Div. 2)
    一万四参赛,VP赛时60A.MaxPlusSize一定选择最大值,若有多个最大值,优先选在奇数位置的最大值,后间隔涂上红色。#include<bits/stdc++.h>usingnamespacestd;constintN=105;intT,n,a[N];intmain(){ scanf("%d",&T); while(T--){ scanf("%d",&n); intm......
  • 【LGR-197-Div.2】洛谷 10 月月赛 I &「SFMOI」Round I(A,B,C)
    A.StrangeCakeGame对于小W,往下走最赚,对于小M往右走最赚,于是路线形成了个折线,直接对应竖坐标位置去看看横坐标符不符合要求即可#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<queue>#include<deque>#include<math.h>#include<m......
  • Codeforces Global Round 19 E. Best Pair
    \(cnt\)的取值种类数不超过\(\sqrtn\)。因此我们可以枚举\(cnt\)然后贪心选最大的值。#include<bits/stdc++.h>usingnamespacestd;usingi32=int32_t;usingi64=longlong;#defineinti64usingvi=vector<int>;usingpii=pair<int,int>;voidsolve()......
  • CF2020(Codeforces Round 976 (Div. 2))
    CF2020A.FindMinimumOperations难度:红转换进制,每一位上数字相加。#include<bits/stdc++.h>#definelllonglongusingnamespacestd;llt,n,k,ans;intmain(){ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);cin>>t;while(t--){cin&......
  • [LeetCode] 1497. Check If Array Pairs Are Divisible by k
    Givenanarrayofintegersarrofevenlengthnandanintegerk.Wewanttodividethearrayintoexactlyn/2pairssuchthatthesumofeachpairisdivisiblebyk.ReturntrueIfyoucanfindawaytodothatorfalseotherwise.Example1:Input:arr......
  • pbootcms编辑器过滤div代码解决办法
    在使用PbootCMS建站时,如果需要在专题内容中加入含有HTML代码的文字,但发现编辑器将 div 标签转换成了 p 标签,可以通过以下步骤进行修改。修改步骤修改 ueditor.all.js 文件找到 core->extend->ueditor->ueditor.all.js 文件。在大约第10830行,将 allowDivTransToP......