比赛链接: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\) 个友谊关系

如果同时满足以下两个条件,则贵族被定义为易受攻击:

  • 贵族至少有一个朋友
  • 该贵族的所有朋友都拥有更高的权力。

三种操作:

  1. 增加贵族 \(u\) 和 \(v\)之间的友谊。

  2. 消除贵族 \(u\) 和 \(v\)之间的友谊。

  3. 计算以下过程的答案。

    过程:所有易受伤害的贵族同时被杀害,他们的友谊也随之结束。这样,剩余贵族就有可能变得脆弱。这个过程不断重复,直到没有贵族受到伤害。可以证明,这个过程将在有限的时间内结束。完成此过程后,您需要计算剩余贵族的数量。

但是该过程的结果不会在查询之间传递,也就是说,每个过程都以所有贵族都处于“活着”的状态!

看完题,感觉是并查集,不过模拟时发现就是一个 拓扑排序了,输出的答案也是当前 \(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的更多相关文章

  1. Codeforces Round #736 (Div. 2)

    A,B,C就不说了,又被D题卡住了..... 感觉怎么说呢,就是题解中的三个提示都已经想到了,就是不知道该怎么解决.... D. Integers Have Friends 简述题意:题目要求你找一个 ...

  2. 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 ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  10. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. Vite4+Typescript+Vue3+Pinia 从零搭建(4) - 代码规范

    项目代码同步至码云 weiz-vue3-template 要求代码规范,主要是为了提高多人协同和代码维护效率,结合到此项目,具体工作就是为项目配置 eslint 和 prettier. editorc ...

  2. Kubernetes 漫游:kube-scheduler

    概述 什么是 kube-scheduler ? Kubernetes 集群的核心组件之一,它负责为新创建的 Pods 分配节点.它根据多种因素进行决策,包括: 资源需求和限制:考虑每个 Pod 请求的 ...

  3. hive报错Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask[已解决]

    我的报错信息 Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask 解决1(可行):不走ya ...

  4. 有序对的LCP

    求\(\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n} LCP(s_i, s_j)\) 方法一 \(1.\)Trie . \(2.\)求\(cnt\),\(cnt[ ...

  5. 又有新框架上线了,测试、AI 通通有「GitHub 热点速览」

    本周热点之一可能就是 Apple 刚开源便获得 8k+ star 的机器学习框架 mlx,顺带官方开源的 mlx-example(示例仓)也在热门榜上有一席之位,据说它已经跑通了大模型 Llama 7 ...

  6. Win10遇到服务器启动失败 80端口被占用如何解决

    Win10提示"服务器启动失败,80端口被占用"怎么办?具体解决方法如下 步骤如下: 1.以管理员身份运行cmd; 2.输入:net stop http 注:如果提示是否真的需要停 ...

  7. ElasticSearch之cat segments API

    命令样例如下: curl -X GET "https://localhost:9200/_cat/segments?v=true&pretty" --cacert $ES_ ...

  8. 年底了,网站被挂马了,关于IIS被陌生DLL劫持(新人发帖,写的不好的地方,请多多担待)

    一上班被分到两个需要杀毒的站点,情况是SEO被劫持 出现一些博彩信息,但是打开确实正常内容,使用站长工具的网站被黑检测功能,发现网站的HEAD前面加载一对加密的东西 一开始我使用D盾扫描网站,删除了一 ...

  9. kubernetes之部署nginx+vue前端(一)

    kubernetes之部署nginx+vue前端(一) k8s系列项目的部署方式之一使用了kubernetes部署nginx+vue前端. 一.打包前端 将dist与Dockerfile放到同一目录下 ...

  10. JavaFx之全局异常捕获(二十)

    JavaFx之全局异常捕获(二十) javafx开发时,我们有时候需要捕获未处理的异常.手动抛出的异常,在main方法中添加下面代码: public static void main(String[] ...