Codeforces Round #736 (Div. 2) A~D
比赛链接:Here
1549A. Gregor and Cryptography
不难,观察一下就容易得知要想使得 \(p\pmod a = p\pmod b\) 令 \(a = 2,b=p - 1\) 即可。
1549B. Gregor and the Pawn Game
一开始想叉了,直接贪心就可以
const int N = 2e5 + 10;
char s[N], s1[N];
int main() {
// cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n; cin >> n;
scanf("%s%s", s + 1, s1 + 1);
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (s1[i] == '0') continue;
if (s[i - 1] == '1') s[i - 1] = '2', ans++;
else if (s[i] == '0') s[i] = '2', ans++;
else if (s[i + 1] == '1') s[i + 1] = '2', ans++;
}
cout << ans << "\n";
}
}
1549C. Web of Lies
看过权游的话大概很快就理解题意了(笑
\(n\) 个贵族,每个贵族有力量(权力) \(i\) ;
\(m\) 个友谊关系
如果同时满足以下两个条件,则贵族被定义为易受攻击:
- 贵族至少有一个朋友
- 该贵族的所有朋友都拥有更高的权力。
三种操作:
增加贵族 \(u\) 和 \(v\)之间的友谊。
消除贵族 \(u\) 和 \(v\)之间的友谊。
计算以下过程的答案。
过程:所有易受伤害的贵族同时被杀害,他们的友谊也随之结束。这样,剩余贵族就有可能变得脆弱。这个过程不断重复,直到没有贵族受到伤害。可以证明,这个过程将在有限的时间内结束。完成此过程后,您需要计算剩余贵族的数量。
但是该过程的结果不会在查询之间传递,也就是说,每个过程都以所有贵族都处于“活着”的状态!
看完题,感觉是并查集,不过模拟时发现就是一个 拓扑排序了,输出的答案也是当前 \(deg_i = 0\) 的个数
理解到是这个方面以后代码就很好写了
const int N = 2e5 + 10;
int deg[N];
void solve() {
int n, m; cin >> n >> m;
for (int i = 1, x, y; i <= m; ++i) {
cin >> x >> y;
if (x > y) swap(x, y);
deg[x]++;
}
int ans = 0;
for (int i = 1; i <= n; ++i) if (deg[i] == 0) ans ++;
int q; cin >> q;
while (q--) {
int op, x, y; cin >> op;
if (op == 1) {
cin >> x >> y;
if (x > y) swap(x, y);
deg[x]++;
if (deg[x] == 1)ans--;
} else if (op == 2) {
cin >> x >> y;
if (x > y) swap(x, y);
deg[x]--;
if (deg[x] == 0)ans++;
} else cout << ans << "\n";
}
}
1549D.Integers Have Friends
不太会,赛后看了一下社区的解释
这道题的关键在于构建一个大小为 \(n\) 的差分数组 \(D\) ,\(D[i] = abs(a[i + 1] - a[i])\)
同时如果给定的数组子序列是一个友元序列,每个差就是某个 \(m\) 的倍数(因为 \(a\) 数组每个元素值都不同,所以可以不用管 \(D[i] = 0\) 的情况)
然后针对上面的结论,可以将其转化为 GCD 问题,当且仅当 \(m = \gcd(D[i,...,j-1] > 1\) 时,\(a[i,...j]\) 为友元序列 .
为了解决这个问题,我们可以使用一个稀疏表或一个段树来查找从i开始的最大可能子数组,然后对所有子数组的答案进行最大化以得到最终答案。
【Code】
const int N = 2e5 + 10, LG = 17;
ll a[N], st[N][18], lg[N];
ll gcd(ll a, ll b) {
if (b == 0)return a;
else return gcd(b, a % b);
}
ll query(int l, int r) {
int c = lg[r - l + 1];
return gcd(st[l][c], st[r - (1 << c) + 1][c]);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n; cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i < n; i++)a[i] = abs(a[i + 1] - a[i]); n--;
for (int i = 1; i <= n; i++)st[i][0] = a[i];
for (int j = 1; j <= LG; j++)
for (int i = 1; i <= n - (1 << j) + 1; i++)
st[i][j] = gcd(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
lg[1] = 0; for (int i = 2; i <= n; i++)lg[i] = lg[i >> 1] + 1;
int l = 1, ans = 0;
for (int r = 1; r <= n; r++) {
while (l <= r && query(l, r) == 1)l++;
ans = max(ans, r - l + 1);
}
cout << ans + 1 << "\n";
}
}
const int inf = 1e9+10;
const ll inf_ll = 1e18+10;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define cmax(x, y) (x = max(x, y))
#define cmin(x, y) (x = min(x, y))
template<typename it, typename bin_op>
struct sparse_table {
using T = typename remove_reference<decltype(*declval<it>())>::type;
vector<vector<T>> t; bin_op f;
sparse_table(it first, it last, bin_op op) : t(1), f(op) {
int n = distance(first, last);
t.assign(32-__builtin_clz(n), vector<T>(n));
t[0].assign(first, last);
for (int i = 1; i < t.size(); i++)
for (int j = 0; j < n-(1<<i)+1; j++)
t[i][j] = f(t[i-1][j], t[i-1][j+(1<<(i-1))]);
}
// returns f(a[l..r]) in O(1) time
T query(int l, int r) {
int h = floor(log2(r-l+1));
return f(t[h][l], t[h][r-(1<<h)+1]);
}
};
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) {
ll n; cin >> n;
vector<ll> a(n), d(n-1);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n-1; i++)
d[i] = abs(a[i+1]-a[i]);
sparse_table g(all(d), [](ll x, ll y){
return __gcd(x, y);
});
int j = 0, ans = 1;
for (int i = 0; i < n-1; i++) {
while (j <= i && g.query(j, i) == 1) j++;
cmax(ans, i-j+2);
}
cout << ans << "\n";
}
}
Codeforces Round #736 (Div. 2) A~D的更多相关文章
- Codeforces Round #736 (Div. 2)
A,B,C就不说了,又被D题卡住了..... 感觉怎么说呢,就是题解中的三个提示都已经想到了,就是不知道该怎么解决.... D. Integers Have Friends 简述题意:题目要求你找一个 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- Modbus 转PROFIBUS DP网关在工厂自动温度控制系统中的应用案例
Modbus 转PROFIBUS DP 网关PM-160 在工厂自动温度控制系统中的应用案例 摘要 随着科技的发展和工业生产水平的提高,自动温度控制系统在纺织.化工.机械等各类工业控制过程中得到了广泛 ...
- Pix4Dmapper空间三维模型的应用实例:GIS选址分析
本文介绍基于无人机影像建模完成后的结果,利用ArcMap软件进行空间选址分析,从而实现空间三维模型应用的方法. 目录 1 空间分析目标确立 2 基于基本约束条件的选址求解 2.1 坡度计算与提取 ...
- [CD随身听] 1984年~2005年索尼全系列Discman+CD_WALKMAN珍贵资料
文章转载自:家电论坛https://jdbbs.com(由网友xieminjie整理提供) https://jdbbs.com/forum.php?mod=viewthread&tid=295 ...
- java桌面小闹钟
写了个桌面的小闹钟,在运行环境可以编译,但是打包成jar文件,想用批处理命令直接调用报错"找不到或无法加载主类". 需求 为防止整天久坐,编写一个桌面闹钟.该闹钟功能很简单,一个小 ...
- 如何用.net制作一个简易爬虫抓取华为应用市场数据
公司最近要做一款手机,手机需要制作一个应用市场.那么问题来了,自己制作应用市场,数据从哪来呢?作为一个创业型公司.搜集数据变成为了难题. 于是突然想到能不能通过程序去抓取别人应用市场的数据-- 那么我 ...
- dfs之迭代加深
为什么要用迭代加深 \(dfs\) 每次会选择搜索树的一个分支,不断深入,直到达到递归边界条件:但这种搜索策略带有一定的缺陷性: 如果搜索树的某一个分支中的节点个数特别多,但是答案并不在这棵子树里面, ...
- puppeteer的简单使用
引言 对于编写应用程序,尤其是要部署上线投入生产使用的应用,QA是其中重要的一环,在过去的工作经历中,我参与的项目开发,大多是由测试同学主要来把控质量的,我很少编写前端方面的测试代码,对于测试工具的使 ...
- 日常Bug排查-集群逐步失去响应
前言 日常Bug排查系列都是一些简单Bug排查.笔者将在这里介绍一些排查Bug的简单技巧,同时顺便积累素材_ Bug现场 最近碰到一个产线问题,表现为某个应用集群所有的节点全部下线了.导致上游调用全部 ...
- 亿级日活业务稳如磐石,华为云CodeArts PerfTest发布
摘要:近日,华为云性能测试服务CodeArts PerfTest全新上线,提供低门槛.低成本的一站式云化性能测试解决方案. 本文分享自华为云社区<亿级日活业务稳如磐石,华为云CodeArts P ...
- 3个轻量级物联网新品实验,带您深度体验IoT开发
摘要:一键创建实验环境,开发者通过实验手册指导,快速体验华为云IoT服务,在云端即可实现云服务的实践.调测和验证等开发流程. 本文分享自华为云社区<物联网云上实验上新,带您深度体验华为云IoT服 ...