A. Short Program

起床困难综合征,随便构造一下就好了。

#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;typedef long long LL;
typedef pair <int, int> pii;inline int Read()
{int x = 0, f = 1, c = getchar();for (; !isdigit(c); c = getchar())if (c == '-')f = -1;for (;  isdigit(c); c = getchar())x = x * 10 + c - '0';return x * f;
}int n, x, y = 1023;
char opt[3];int main()
{
#ifdef wxh010910freopen("data.in", "r", stdin);
#endifn = Read();for (int i = 1, z; i <= n; i ++){scanf("%s", opt), z = Read();if (opt[0] == '&')x &= z, y &= z;else if (opt[0] == '|')x |= z, y |= z;elsex ^= z, y ^= z;}puts("2");printf("& %d\n", x ^ y);printf("^ %d\n", x);return 0;
}

B. Teams Formation

先用栈把内部的消掉,剩下的一定是消一头一尾。

消的时候如果一头一尾的出现次数加起来恰好为 k k就消下去,注意一些边界情况。

#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;typedef long long LL;
typedef pair <int, int> pii;inline int Read()
{int x = 0, f = 1, c = getchar();for (; !isdigit(c); c = getchar())if (c == '-')f = -1;for (;  isdigit(c); c = getchar())x = x * 10 + c - '0';return x * f;
}const int MAXN = 100005;int n, m, q, c, a[MAXN], b[MAXN];
LL ans;int main()
{
#ifdef wxh010910freopen("data.in", "r", stdin);
#endifn = Read(), m = Read(), q = Read();for (int i = 1, x; i <= n; i ++)if ((x = Read()) == a[c]){b[c] ++;if (b[c] == m)c --;}elsec ++, a[c] = x, b[c] = 1;if (!c)return puts("0"), 0;int tot = 0, del = 0, pos = 0;for (int i = 1; i <= c; i ++)tot += b[i];for (int i = 1; i < c + 1 - i; i ++)if (a[i] == a[c + 1 - i] && b[i] + b[c + 1 - i] == m)del += m;else{pos = i;break;}if (pos){if (a[pos] == a[c + 1 - pos] && b[pos] + b[c + 1 - pos] > m)del += m;ans = 1LL * tot * q - 1LL * del * (q - 1);}else{ans = 1LL * b[(c >> 1) + 1] * q % m;if (ans)ans += tot - b[(c >> 1) + 1];}cout << ans << endl;return 0;
}

C. Tournament

题目名字提示类似竞赛图。

首先变成图论问题,ii能赢 j j连边(i,j)(i, j),可以赢的人一定能到达所有点。

两个点之间至少有一条边,就是说缩环之后是一条链。

新加一个点可能带来缩掉若干个SCC,对于每个SCC维护每种属性的最大最小值,用set维护一下链上的相对位置关系,暴力缩环即可。

#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;typedef long long LL;
typedef pair <int, int> pii;inline int Read()
{int x = 0, f = 1, c = getchar();for (; !isdigit(c); c = getchar())if (c == '-')f = -1;for (;  isdigit(c); c = getchar())x = x * 10 + c - '0';return x * f;
}const int MAXN = 50005;int n, m, siz[MAXN], l[MAXN][10], r[MAXN][10];
set <pii> s;inline bool Win(int x, int y)
{for (int i = 0; i < m; i ++)if (r[x][i] > l[y][i])return true;return false;
}inline void Insert(int x)
{siz[x] = 1;while (true){auto it = s.lower_bound(mp(l[x][0], x));if (it != s.end() && Win(x, it -> yy)){for (int i = 0; i < m; i ++)l[x][i] = min(l[x][i], l[it -> yy][i]), r[x][i] = max(r[x][i], r[it -> yy][i]);siz[x] += siz[it -> yy];s.erase(it);}elsebreak;}while (true){auto it = s.lower_bound(mp(l[x][0], x));if (it != s.begin()){it --;if (Win(it -> yy, x)){for (int i = 0; i < m; i ++)l[x][i] = min(l[x][i], l[it -> yy][i]), r[x][i] = max(r[x][i], r[it -> yy][i]);siz[x] += siz[it -> yy];s.erase(it);}elsebreak;}elsebreak;}s.insert(mp(l[x][0], x));
}int main()
{
#ifdef wxh010910freopen("data.in", "r", stdin);
#endifn = Read(), m = Read();for (int i = 1; i <= n; i ++)for (int j = 0; j < m; j ++)l[i][j] = r[i][j] = Read();for (int i = 1; i <= n; i ++)Insert(i), printf("%d\n", siz[(-- s.end()) -> yy]);return 0;
}

D. Magic Breeding

考虑将 ai a_i变成 0/1 0/1,那么取 max \max和 min \min相当于 or or和 and and操作。

每个序列可以用一个 2k 2^k位二进制数表示,第 S S位表示初始的0/10/1状态为 S S,那么这个序列的状态是什么,用bitset加速即可。

#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;typedef long long LL;
typedef pair <int, int> pii;inline int Read()
{int x = 0, f = 1, c = getchar();for (; !isdigit(c); c = getchar())if (c == '-')f = -1;for (;  isdigit(c); c = getchar())x = x * 10 + c - '0';return x * f;
}const int MAXN = 100005;
const int MAXM = 4100;int n, m, q, c, a[12][MAXN];
bitset <MAXM> b[MAXN];int main()
{
#ifdef wxh010910freopen("data.in", "r", stdin);
#endifm = Read(), n = c = Read(), q = Read();for (int i = 0; i < n; i ++)for (int j = 0; j < m; j ++)a[i][j] = Read();for (int i = 0; i < n; i ++)for (int j = 0; j < 1 << n; j ++)if (j >> i & 1)b[i][j] = 1;for (int i = 1, opt, x, y; i <= q; i ++)if ((opt = Read()) == 1)x = Read() - 1, y = Read() - 1, b[n ++] = b[x] | b[y];else if (opt == 2)x = Read() - 1, y = Read() - 1, b[n ++] = b[x] & b[y];else{x = Read() - 1, y = Read() - 1;int ans = 0;for (int j = 0; j < c; j ++){int cur = 0;for (int k = 0; k < c; k ++)if (a[k][y] >= a[j][y])cur |= 1 << k;if (b[x][cur])ans = max(ans, a[j][y]);}printf("%d\n", ans);}return 0;
}

E. Numbers on the blackboard

首先单次询问可以倒着贪心做,如果是负数就把它乘二加到答案(最后合并),否则去和前一个合并。

求出ii往前这样做一步的长度,倍增加速询问。

注意代码里虽然写了 2 2层for,但是均摊下来应该是nlognnlogn的。

#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;typedef long long LL;
typedef pair <int, int> pii;inline int Read()
{int x = 0, f = 1, c = getchar();for (; !isdigit(c); c = getchar())if (c == '-')f = -1;for (;  isdigit(c); c = getchar())x = x * 10 + c - '0';return x * f;
}const int MAXN = 100005;
const int mod = 1e9 + 7;int n, m, a[MAXN], bin[MAXN], inv[MAXN], s[MAXN], f[18][MAXN], g[18][MAXN];inline int Get(int l, int r)
{return 1LL * (s[r] - s[l - 1] + mod) * inv[l - 1] % mod;
}inline int Solve(int l, int r)
{int ret = 0;for (int i = 17; ~i; i --)if (f[i][r] >= l)ret = (ret + g[i][r]) % mod, r = f[i][r];ret = (ret + Get(l, r)) % mod;return ret;
}int main()
{
#ifdef wxh010910freopen("data.in", "r", stdin);
#endifn = Read(), m = Read(), bin[0] = inv[0] = 1;for (int i = 1; i <= n; i ++)a[i] = Read(), bin[i] = (bin[i - 1] << 1) % mod, inv[i] = 1LL * inv[i - 1] * (mod + 1 >> 1) % mod, s[i] = (1LL * bin[i] * (a[i] + mod) + s[i - 1]) % mod;for (int i = 1; i <= n; i ++){LL cur = 0;for (int j = i; j; j --){cur = 2 * (cur + a[j]);if (cur <= 0){f[0][i] = j - 1, g[0][i] = (cur % mod + mod) % mod;break;}else if (cur > 2000000000){f[0][i] = -1;break;}}}for (int i = 1; i < 18; i ++)for (int j = 1; j <= n; j ++)if (!~f[i - 1][j])f[i][j] = -1;elsef[i][j] = f[i - 1][f[i - 1][j]], g[i][j] = (g[i - 1][j] + g[i - 1][f[i - 1][j]]) % mod;while (m --){int l = Read(), r = Read(), ret = (a[l] + Solve(l + 1, r)) % mod;printf("%d\n", (ret + mod) % mod);}return 0;
}

质量挺高的…感觉姿势不对这场每个题(除了A)细节都会比较鬼畜…

CodeForces 878 简要题解相关推荐

  1. c语言1106回文数,Codeforces 1106 简要题解

    A题 传送门 读错题还能过样例我给自己点个赞. 题意简述:给一个010101网格SSS,问满足Si,j=Si+1,j+1=Si+1,j−1=Si−1,j−1=Si−1,j+1S_{i,j}=S_{i+ ...

  2. Codeforces 1110 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 G题 传送门 众所周知ldxoildxoildxoi这种菜鸡选手是不会写HHH题的,因此该篇博客只有AAA题至GGG题的题解,实在抱歉. A题 传送门 题 ...

  3. Codeforces 837 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 G题 传送门 并没有找到难度评级但感觉是div3div3div3场. A题 题意:一个单词的价值是里面大写字母的个数,一篇文章的价值是里面所有单词的价值的 ...

  4. CodeForces 1089 简要题解

    Alice the Fan 预处理 f(wina,winb,scorea,scoreb)f(win_a, win_b, score_a, score_b)f(wina​,winb​,scorea​,s ...

  5. Codeforces 1065 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 G题 传送门 GGG题略难,膜了一波 zhouyuyang{\color{red} zhouyuyang}zhouyuyang巨佬的代码. 其余都挺清真的 ...

  6. Codeforces 1086 简要题解

    文章目录 A题 B题 C题 D题 E题 传送门 这场比赛原地爆炸了啊!!! 只做了两道. A题 传送门 手贱没关freopenfreopenfreopen于是wawawa了一次,死活调不出错. 题意: ...

  7. Codeforces 1198 简要题解

    文章目录 E F 传送门 前四题对应这套题的CCC~FFF E 传送门 考虑用扫描线的思想将原图分成若干小矩形,然后就可以利用行列二分图匹配+差分的思想建图,最后用dinicdinicdinic跑最小 ...

  8. Codeforces 1106 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 传送门 A题 传送门 读错题还能过样例我给自己点个赞. 题意简述:给一个010101网格SSS,问满足Si,j=Si+1,j+1=Si+1,j−1=Si− ...

  9. CodeForces 997 简要题解

    Convert to Ones 翻转操作实际就是合并两段 000 ,特判全 1" role="presentation" style="position: re ...

最新文章

  1. Linux那些事儿之我是Sysfs(3)设备模型上层容器
  2. Spring Boot 2.4版本前后的分组配置变化及对多环境配置结构的影响
  3. Python 提取数据库(Postgresql)并邮件发送
  4. nssl1305-最大值【dp,数学】
  5. Kafka 分布式环境搭建
  6. html5shiv.js css3,Modernizr, html5shiv, ie7.js, and CSS3 Pie. Which to use and when?
  7. c++ 将引用赋值给引用_5分钟掌握 Python 对象的引用
  8. 关于背景色半透明的实现
  9. JS每日一题: Vue中mixin怎么理解?
  10. lopatkin俄大神精简中文系统Windows 7 Enterprise SP1 7601.23934 x86-x64 ZH-CN PIP
  11. 免疫算法(matlab)
  12. 《舵机控制基本原理》
  13. 编译原理 语法分析程序LL(1)和LR(0)实现
  14. blockly -- 颜色(Block colour)
  15. mysql数据库初始化 error Found option without preceding group in config file
  16. 南京大学计算机学类,并未开放计算机专业:南京大学2020年强基计划政策分析...
  17. 国科大学习资料--多媒体分析与理解(卢汉请)-2019期末考试题
  18. Linux九阴真经之大伏魔拳残卷5 nginx
  19. YouVideo在线视频平台
  20. c++ 的vector、array和数组的比较

热门文章

  1. STC8单片机OLED通过SPI硬件中断方式驱动——优化
  2. 框架—— Serverlet
  3. 山东春考计算机专业课知识点,山东省春季高考计算机专业学习方法
  4. ubuntu小技巧6--如何修复Ubuntu系统引导项
  5. 惠普linux进入bios设置u盘启动,hp惠普笔记本进入bios设置u盘启动装系统的方法步骤详细教程 - 系统家园...
  6. 《小王爱迁移》文章链接
  7. Bolb转String
  8. python输出换行
  9. 最新版本EasyRecovery15个人免费版电脑数据恢复工具
  10. D. Rescue Nibel(cf) 区间覆盖 + 组合数学