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 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- SPI扩展点在业务中的使用及原理分析
1 什么是SPI SPI 全称Service Provider Interface.面向接口编程中,我们会根据不同的业务抽象出不同的接口,然后根据不同的业务实现建立不同规则的类,因此一个接口会实现多个 ...
- 深入了解HMAC加密技术:原理、应用与实践
一.引言 在网络安全领域,消息认证码(MAC)是一种重要的技术手段.Hash-based Message Authentication Code(HMAC)作为其中的一种,凭借其简单.高效.安全的特性 ...
- [USACO2007FEB S] The Cow Lexicon S
题目描述 Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no ...
- [ABC274E] Booster
Problem Statement In a two-dimensional plane, there are $N$ towns and $M$ chests. Town $i$ is at the ...
- 34. 干货系列从零用Rust编写负载均衡及代理,异步测试在Rust中的实现
wmproxy wmproxy已用Rust实现http/https代理, socks5代理, 反向代理, 静态文件服务器,四层TCP/UDP转发,七层负载均衡,内网穿透,后续将实现websocket代 ...
- SpringBoot项目整合微信登录
一.开通微信登录 去微信开发者平台 1.注册 2.邮箱激活 3.完善开发者资料 4.开发者资质认证 准备营业执照,1-2个工作日审批.300元 5.创建网站应用 6.提交审核,7个工作日审批 7.熟悉 ...
- The second day learning summary
1.什么是接口测试? 接口测试是测试系统组件间接口的一种测试.接口测试主要用于外部系统与系统之间以及内部各个子系统之间的交互点,定义特定的交互点,然后通过这些交互点来,通过一些特殊的规则也就是协议,来 ...
- Celery周期性任务定义beat
通过celery beat可以使用周期性任务的定义. https://docs.celeryq.dev/en/stable/userguide/periodic-tasks.html 周期性任务bea ...
- 华企盾科技:智能AI自动化研判分析服务系统概述
由中企网安全资子公司北京华企盾科技有限责任公司开发的<智能AI自动化研判分析服务系统>,获得国家版权局颁发的计算机软件著作权登记证书. 智能AI自动化研判分析服务系统是基于人工智能.大数据 ...
- ios上架流程 详细通关教程 2021
记录此文是源于以下需求 1.已有app store开发者账号 (公司账号$99),需上架至app store 2.有商城实体商品支付功能(会员等虚拟支付另说) 3.有硬件交互功能 注:建议预留一周上架 ...