Codeforces Round 1059 (Div. 3)

news/2025/10/18 1:30:16/文章来源:https://www.cnblogs.com/maburb/p/19149080

A. Beautiful Average

点击查看代码
#include <bits/stdc++.h>using i64 = long long;void solve() {int n;std::cin >> n;std::vector<int> a(n);for (int i = 0; i < n; ++ i) {std::cin >> a[i];}int ans = 0;for (int i = 0; i < n; ++ i) {int sum = 0, cnt = 0;for (int j = i; j < n; ++ j) {sum += a[j];++ cnt;ans = std::max(ans, sum / cnt);}}std::cout << ans << "\n";
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;std::cin >> t;while (t -- ) {solve();}return 0;
}#include <bits/stdc++.h>using i64 = long long;void solve() {int n;std::cin >> n;std::vector<int> a(n);for (int i = 0; i < n; ++ i) {std::cin >> a[i];}int ans = 0;for (int i = 0; i < n; ++ i) {int sum = 0, cnt = 0;for (int j = i; j < n; ++ j) {sum += a[j];++ cnt;ans = std::max(ans, sum / cnt);}}std::cout << ans << "\n";
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;std::cin >> t;while (t -- ) {solve();}return 0;
}

B. Beautiful String

题意:一个\(01\)串,选一些位置出来,使得选出来的非递减,没选的组成一个回文。

\(0\)都选上或者把\(1\)都选上。

点击查看代码
#include <bits/stdc++.h>using i64 = long long;void solve() {int n;std::cin >> n;std::string s;std::cin >> s;std::vector<int> ans;for (int i = 0; i < n; ++ i) {if (s[i] == '0') {ans.push_back(i);}}std::cout << ans.size() << "\n";for (auto & x : ans) {std::cout << x + 1 << " \n"[x == ans.back()];}
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;std::cin >> t;while (t -- ) {solve();}return 0;
}

C. Beautiful XOR

题意:给你\(a, b\),每次使得\(a\)异或一个小于等于\(a\)的数,最后使得\(a\)变成\(b\)

如果\(b\)的最高位大于\(a\)的最高位,则无解。
否则按位考虑就行,如果这一位\(a, b\)不同,则这一位异或一个\(1\)

点击查看代码
#include <bits/stdc++.h>using i64 = long long;void solve() {int a, b;std::cin >> a >> b;std::vector<int> ans;for (int i = 0; (1 << i) <= a; ++ i) {if ((a >> i & 1) != (b >> i & 1)) {ans.push_back(1 << i);a ^= 1 << i;}}if (a != b) {std::cout << -1 << "\n";} else {std::cout << ans.size() << "\n";for (auto & x : ans) {std::cout << x << " \n"[x == ans.back()];}}
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;std::cin >> t;while (t -- ) {solve();}return 0;
}

D. Beautiful Permutation

题意:交互题。一个排列,把一个区间都加上了\(1\)。求这个区间。你可以询问原排列一个区间的和或者操作后的排列的一个区间的和。最多\(40\)次。

考虑分治,先求\([1, n]\)操作前和操作后的值,就可以知道这个区间有多长。然后每次询问左半边,如果左半边被操作过,看被操作的区间有多长,如果都在左半边则递归左半边,否则就可以知道这个区间横跨左右两边,然后因为知道了左边有长,于是就知道了区间的左右端点。否则左边没被操作 过则递归右边。询问\(2log_n\)次。

点击查看代码
#include <bits/stdc++.h>using i64 = long long;i64 ask(int t, int l, int r) {std::cout << t << " " << l << " " << r << std::endl;i64 res;std::cin >> res;return res;
}void solve() {int n;std::cin >> n;i64 len = ask(2, 1, n) - ask(1, 1, n);std::vector<int> a;auto dfs = [&](auto && self, int l, int r) -> void {if (l == r) {a.push_back(l);return;}int mid = l + r >> 1;i64 v1 = ask(1, l, mid), v2 = ask(2, l, mid);if (v1 == v2) {self(self, mid + 1, r);} else if (v2 - v1 < len) {a.push_back(mid - (v2 - v1) + 1);a.push_back(mid + len - (v2 - v1));return;} else {self(self, l, mid);}};dfs(dfs, 1, n);std::ranges::sort(a);std::cout << "! " << a[0] << " " << a.back() << std::endl;
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;std::cin >> t;while (t -- ) {solve();}return 0;
}

E. Beautiful Palindromes

题意:一个长度为\(n\)值域为\([1, n]\)的数组,你要操作\(k\)次,每次在末尾加上\([1, n]\)的某个数。最后使得整个数组的回文子数组最少。

记录每个数最后出现位置的值,没出现过的记为\(-1\)。那么每次拿最后出现位置最前的放最后面。线段树维护一下就行了。
证明就是如果选的数没有出现过,显然不会多回文数组。如果选的数出现过,那么要构成回文当前位置要和这个数最后出现的位置构成回文数组的两端,那么意味这中间的数构成了回文,如果一开始有数没有出现过,那么我们每次都没有构成回文,所以中间的数不会是回文;如果是一开始所有数就出现过了,那么因为数组长度为\(n\),则每个数恰好出现一次,则第一步会把\(a_1\)放到最后,因为中间数两两不同,所以中间也不是回文,同理后面也不会操作出回文。所以回文子数组增加\(0\)个。

点击查看代码
#include <bits/stdc++.h>using i64 = long long;template <class Info>
struct SegmentTree {struct Node {int l, r;Info info;};std::vector<Node> tr;SegmentTree() {};SegmentTree(int n) {init(n);}SegmentTree(std::vector<Info> & info) {init(info);}void init(int n) {tr.assign(n << 2, {});build(0, n - 1);}void init(std::vector<Info> & info) {int n = info.size();tr.assign(n << 2, {});std::function<void(int, int, int)> build = [&](int l, int r, int u) -> void {tr[u] = {l, r, {}};if (l == r) {tr[u].info = info[l];return;}int mid = l + r >> 1;build(l, mid, u << 1); build(mid + 1, r, u << 1 | 1);pushup(u);};build(0, n - 1, 1);}void pushup(int u) {tr[u].info = tr[u << 1].info + tr[u << 1 | 1].info;}void build(int l, int r, int u = 1) {tr[u] = {l, r, {}};if (l == r) {tr[u].info.min = -1;tr[u].info.p = l;return;}int mid = l + r >> 1;build(l, mid, u << 1); build(mid + 1, r, u << 1 | 1);pushup(u);}void modify(int p, const Info & info, bool set = false) {int u = 1;while (tr[u].l != tr[u].r) {int mid = tr[u].l + tr[u].r >> 1;if (p <= mid) {u = u << 1;} else {u = u << 1 | 1;}}if (set) {tr[u].info = info;} else {tr[u].info = tr[u].info + info;}u >>= 1;while (u) {pushup(u);u >>= 1;}}Info query(int l, int r, int u = 1) {if (l <= tr[u].l && tr[u].r <= r) {return tr[u].info;}int mid = tr[u].l + tr[u].r >> 1;if (r <= mid) {return query(l, r, u << 1);} else if (l > mid) {return query(l, r, u << 1 | 1);}return query(l, r, u << 1) + query(l, r, u << 1 | 1);}
};struct Info {int min = -1, p;
};Info operator + (const Info & l, const Info & r) {Info res{};res = l.min < r.min || (l.min == r.min && l.p < r.p) ? l : r;return res;
}void solve() {int n, k;std::cin >> n >> k;std::vector<int> a(n);for (int i = 0; i < n; ++ i) {std::cin >> a[i];-- a[i];}SegmentTree<Info> tr(n);std::vector<int> last(n, -1);for (int i = 0; i < n; ++ i) {last[a[i]] = i;}for (int i = 0; i < n; ++ i) {if (last[i] != -1) {tr.modify(i, Info{last[i], i}, true);}}for (int i = 0; i < k; ++ i) {auto [_, p] = tr.query(0, n - 1);std::cout << p + 1 << " \n"[i == k - 1];last[p] = n + i;tr.modify(p, Info{last[p], p}, true);}
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;std::cin >> t;while (t -- ) {solve();}return 0;
}

F. Beautiful Intervals

题意:你要构造一个排列,然后有\(m\)个区间,每个区间的值为这个区间里的\(mex\)。然后使得所有区间的值的\(mex\)最小。

如果一个位置被所有区间覆盖,那么这个位置放\(0\)就行,则所有区间的\(mex > 0\),最后的\(mex = 0\)
否则,如果有一个位置\(i\)满足没有区间的右端点是\(i\),则\(i\)可以放\(0\)\(i+1\)\(1\)。这样覆盖\(i, i+1\)的区间\(mex > 1\),只覆盖\(i + 1\)的区间\(mex = 0\)。其它区间\(mex = 0\)。则最后\(mex = 1\)
再否则,把\(0, n - 1\)分别放两端,中间随便放,这样的话,不是\([1, n]\)这种区间的\(mex\)要么是\(0\)要么是\(1\)\([1, n]\)这个区间\(mex = n\)。最后\(mex = 2\)

点击查看代码
#include <bits/stdc++.h>using i64 = long long;void solve() {int n, m;std::cin >> n >> m;	std::vector<int> d(n + 2);std::vector<int> pre(n + 1), suf(n + 1);for (int i = 0; i < m; ++ i) {int l, r;std::cin >> l >> r;++ d[l];-- d[r + 1];pre[r] = 1;suf[l] = 1;}std::vector<int> ans(n + 1);for (int i = 1; i <= n; ++ i) {d[i] += d[i - 1];if (d[i] == m) {ans[i] = 0;for (int j = 1, x = 1; j <= n; ++ j) {if (i != j) {ans[j] = x ++ ;}std::cout << ans[j] << " \n"[j == n];}return;}}for (int i = 1; i + 1 <= n; ++ i) {if (!pre[i]) {ans[i] = 0;ans[i + 1] = 1;for (int j = 1, x = 2; j <= n; ++ j) {if (j != i && j != i + 1) {ans[j] = x ++ ;}std::cout << ans[j] << " \n"[j == n];}return;} else if (!suf[i + 1]) {ans[i] = 1;ans[i + 1] = 0;for (int j = 1, x = 2; j <= n; ++ j) {if (j != i && j != i + 1) {ans[j] = x ++ ;}std::cout << ans[j] << " \n"[j == n];}return;}}ans[1] = 0;ans[n] = 1;for (int i = 2; i < n; ++ i) {ans[i] = i;}for (int i = 1; i <= n; ++ i) {std::cout << ans[i] << " \n"[i == n];}
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;std::cin >> t;while (t -- ) {solve();}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/939260.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

升鲜宝生鲜配送供应链管理系统-----仓库作业任务模块开发文档

📦 仓库作业任务模块开发文档 一、模块概述 本模块涵盖三类核心作业任务:🟩 上架任务(Putaway) 🟦 下架任务(Pickdown) 🟥 移库任务(Move)每类任务均包括:主表(Task)—— 用于存储任务基本信息; 明…

24 Hongkong B and 2023 ICPC Shenyang

24 Hongkong B and 2023 ICPC Shenyang 24 Hongkong B 我们能造成的伤害范围比较小,考虑从这一点入手。如果每次都造成 1 点伤害,则 \(max\{a_i + b_i\}\) 次后就能击败所有敌人,最后造成 \(max\{a_i + b_i\}\) 点伤…

应急响应-vulntarget-k-03

应急响应-vulntarget-k-03 这里通过history查看历史命令看到在这里进入了/opt下面创建了一个隐藏文件 .a 我们跟跟踪过去看看在这里有个程序start.sh 看这个隐藏目录下面有一个sendPacket.py ./sendPacket.py 192.168.…

共识的预锚点:AI元人文中的价值原语引导与自动化演进

共识的预锚点:AI元人文中的价值原语引导与自动化演进 我: 在价值原语博弈开始前,我们是否可以先开发一个引导环节,借助大模型为具体冲突预生成可能涉及的价值原语清单? 你: 这个想法非常关键!它解决了价值博弈的…

winserver备份到miniio

winserver 安装openssh备份代码 package org.hf.ywyt_minio.openssh;import com.jcraft.jsch.*; import io.minio.BucketExistsArgs; import io.minio.MakeBucketArgs; import io.minio.MinioClient; import io.minio.…

软考中级 学习总结*(1)

一. 1.计算机由运算器,控制器,存储器,输入设备,输出设备组成 中央处理单元CPU CPU获取程序指令,并进行译码,也就是执行程序。 一个程序由多个指令组成 CPU功能:控制器:程序控制,操作控制,时间控制 运算器(…

【黑马python】基础 6.Python 容器:列表 元组 字符串 集合 字典

笔记汇总目录【黑马python】8天python从入门到精通 - 汇总Python 数据容器代码示例参考链接黑马-6.Python 容器 01-数据容器入门TBD

刷题日记—数字读取与判断

今天做了洛谷上有关统计数字个数的题,如下 这道题让我们统计在1到n的数中,给定数字x的出现次数,所以要考虑每一位上该数字出现的个数。对于这种读取每个数位上的数字,我们一般用% /结构。 即先让b=i,拷贝当前数值,…

Linux Mint -- LMDE6升级到LMDE7

Linux Mint -- LMDE6升级到LMDE72025年10月15日,LMDE7 Gigi版本正式发布了!!该操作系统我之前文章写过推荐的理由及该系统推荐的软件,有兴趣的点击此链接去看一下Linux Mint操作系统推荐。如下再介绍两种安装的方式…

OI 笑传 #19

Shinshiro今天是一些 CF。 CF2152D 除二加一什么的当然要放到二进制上。 如果没有小 R,那么操作的次数就是二进制位数减一加起来。 观察一下发现小 R 的加一是很弱小的,因为小 P 除二可以把整个二进制往下拉(右移)…

CF1133 合集

云落碎碎念题面翻译取自 luogu,本蒟蒻也会安置原题链接 不保证文章中不出现“显然”或者“注意到”,可能会出现“易证” 有写错的地方欢迎各位神犇指正前言 随机到一套 Div 3,愉悦一下身心 CF1133A 题解 题目传送门…

Note of Michael Artin Algebra Chapter 6 Symmetry (to complete)

6.1 SYMMETRY OF PLANE FIGURES Bilateral, rotational, translational, glide symmetry, and their combinations. 6.2 ISOMETRIES 6.2.1 Def. (Distance, Isometry) The distance between points of \(\mathbb{R}^n\…

10/18

学了外教课

实验一 现代C++基础编程

#任务1 ##代码 代码1// 现代C++标准库、算法库体验 // 本例用到以下内容: // 1. 字符串string, 动态数组容器类vector、迭代器 // 2. 算法库:反转元素次序、旋转元素 // 3. 函数模板、const引用作为形参 #include <…

CF1824D 题解

求 \(\sum\limits _ {i = l} ^ r \sum\limits _ {j = x} ^ y g(i,j)\)。 离线询问,扫描线 \(j\),线段树维护 \(g(i)\),那么,转换为求解 \(x\) 时刻到 \(y\) 时刻,线段树区间 \([l,r]\) 的区间和的历史和。 考虑扫…

CF1059 Codeforces Round 1059 (Div. 3) 游记

一次值得记录的失败。用以勉励。省流 一次值得记录的失败。用以勉励。10.17 内含剧透,请vp后再来。 不是题解!!!!!!! 赛前 非常困,回寝室睡了一会,再来就迟到了。于是一边安慰自己不算分一边想着还是写一下不…

newDay12

1.今天主要是合唱现场去演出,写写作业,背单词 2.明天时间多,多学学 3.睡得太晚了,导致醒来也已经很晚,时间管控不太好

PyTorch与卷积神经网络读书报告

PyTorch与卷积神经网络读书报告 近期,我观看了B站上适合新手的卷积神经网络(CNN)原理详解视频,并结合PyTorch相关知识进行学习,对CNN在PyTorch中的应用有了更深入的认识。 一、CNN核心原理 CNN通过卷积层用卷积核…

QOJ857 Social Distancing

题意简述 给定一颗 \(n\) 个点的树,和它的两个大小为 \(k\) 的独立集 \(A, B\)。 在一次操作中,可以选择一条树边 \((u, v)\),满足 \(u\in A\land v\notin A\),并使 \(A\leftarrow (A − \{u\})\cup\{v\}\)。同时,…