AtCoder Beginner Contest 380 (A~E)题解
A - 123233
遍历字符串统计出现次数即可。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n, m, k;
int a[N];
signed main() {
string s;
cin >> s;
map<char, int> mp;
for (auto t : s) {
mp[t]++;
}
if (mp['2'] == 2 && mp['1'] == 1 && mp['3'] == 3) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
B - Hurdle Parsing
直接计数,遇到 $ | $ 输出即可。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n, m, k;
int a[N];
signed main() {
string s;
cin >> s;
int cnt = 0, f = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '|') {
if (f == 1)
cout << cnt << ' ';
cnt = 0;
f = 1;
}
if (s[i] != '|') {
cnt++;
}
}
}
C - Move Segment
题意是将第 $ k $ 个连续的字符 $ 1 $ 段与第 $ k-1 $个段合并。
用 $ vector $ 存储一下连续的每一段然后根据题目要求顺序即可。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n, m, k;
int a[N];
signed main() {
string s;
cin >> n >> k;
cin >> s;
string now1 = "", now2 = "";
vector<string> a;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
now1 += s[i];
if (now2.size() != 0) {
// cout << now2 << '\n';
a.push_back(now2);
now2 = "";
}
}
if (s[i] == '0') {
now2 += s[i];
if (now1.size() != 0) {
a.push_back(now1);
// cout << now1 << '\n';
now1 = "";
}
}
}
if (now1.size())
a.push_back(now1);
if (now2.size())
a.push_back(now2);
// for (auto t : a) {
// cout << t << ' ';
// }
cout << '\n';
int cnt = 0, d1 = 0, d2 = 0;
for (int i = 0; i < a.size(); i++) {
if (a[i][0] == '1') {
cnt++;
if (cnt == k - 1) {
d1 = i;
}
if (cnt == k) {
d2 = i;
for (int j = 0; j <= d1; j++) {
cout << a[j];
}
cout << a[d2];
for (int j = d1 + 1; j < a.size(); j++) {
if (j != d2) {
cout << a[j];
}
}
return 0;
}
}
}
}
D - Strange Mirroring
利用对称的思想,观察每次查询的第 $ k $ 个字符最初是由哪个字符演变过来的,并记录演变次数,根据次数判断字符大小写。可以观察发现,每次我们都可以通过对称使得字符串长度减少 $ n*2^x $ 的长度,该长度通过二分查找,多次缩短我们便能找到最初的字符。
时间复杂度:$ O(q*log k) $。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n, m, k;
int a[N];
int b[100];
signed main() {
string s;
cin >> s;
n = s.size();
s = ' ' + s;
int q;
cin >> q;
vector<int> a;
int x = n;
for (int i = 1; i <= 64; i++) {
if (x > 1e18) break;
a.push_back(x);
x *= 2;
}
for (int i = 0; i < a.size(); i++) {
b[i + 1] = a[i];
}
while (q--) {
cin >> k;
int d = 0;
int cnt = 0;
for (int i = 1; i <= 100; i++) {
int x = lower_bound(b + 1, b + 1 + (int)a.size(), k) - b;
x -= 1;
k -= b[x];
// cout << x << '\n';
if (b[x] != 0)
cnt++;
if (k <= n) break;
}
// cout << k << '\n';
// cout << cnt << '\n';
char x = s[k];
if (cnt % 2 == 0) {
cout << x << ' ';
} else {
if (x >= 'a' && x <= 'z')
cout << (char)(x - 32) << ' ';
else
cout << (char)(x + 32) << ' ';
}
// cout << '\n';
}
}
E - 1D Bucket Tool
使用两个 $ set $ 维护 $ l $ 和 $ r $ 区间,用 $ set<pair<int,int>> $ 维护存在的颜色的区间,使用 $ map<pair<int,int>> $ 维护颜色区间的颜色。每次修改通过二分查找出 $ x $ 分类讨论所在区间段再根据左右区间段颜色 $ c $ ,判断是否需要合并区间,每次修改完成后更新 $ sum $ 数组的值,不断维护 $ stl $ 容器的值,注意不要出现越界的问题,思路不乱维护好就可以了。
真是一次酣畅淋漓的 $ set $ 练习
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n, m, k;
int sum[N];
set<pair<int, int>> col;
set<int> sel, ser;
map<pair<int, int>, int> mp;
void work(pair<int, int> l, pair<int, int> b, pair<int, int> r, int x) {
sel.erase(l.first), sel.erase(b.first), sel.erase(r.first);
ser.erase(l.second), ser.erase(b.second), ser.erase(r.second);
int a = mp[ {l.first, l.second}], bt = x, c = mp[ {r.first, r.second}];
int be = mp[ {b.first, b.second}];
sum[be] -= b.second - b.first + 1;
sum[x] += b.second - b.first + 1;
if (a == bt && bt == c) {
pair<int, int> f = {l.first, r.second};
mp.erase(b), mp.erase(l), mp.erase(r);
mp[f] = x;
col.erase(l), col.erase(r), col.erase(b);
col.insert(f);
sel.insert(l.first), ser.insert(r.second);
} else if (a == bt) {
pair<int, int> f = {l.first, b.second};
mp.erase(b), mp.erase(l);
col.erase(b), col.erase(l);
mp[f] = x;
col.insert(f);
sel.insert(l.first), ser.insert(b.second);
sel.insert(r.first), ser.insert(r.second);
} else if (bt == c) {
pair<int, int> f = {b.first, r.second};
mp.erase(b), mp.erase(r);
col.erase(b), col.erase(r);
mp[f] = x;
col.insert(f);
sel.insert(b.first), ser.insert(r.second);
sel.insert(l.first), ser.insert(l.second);
} else {
pair<int, int> f = {b.first, b.second};
mp[f] = x;
sel.insert(r.first), ser.insert(r.second);
sel.insert(l.first), ser.insert(l.second);
sel.insert(b.first), ser.insert(b.second);
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
sel.insert(i), ser.insert(i);
col.insert({i, i});
mp[ {i, i}] = i;
sum[i] += 1;
}
while (m--) {
int op, x, c;
cin >> op;
if (op == 1) {
cin >> x >> c;
auto it1 = sel.lower_bound(x);
auto it2 = ser.lower_bound(x);
if (it1 == sel.end()) {
it1 = --sel.end();
}
if (*it1 > x) it1--;
auto it3 = col.lower_bound({*it1, *it2});
pair<int, int> b = *it3, l, r;
pair<int, int> ed = *--col.end(), be = *col.begin();
if (b != ed) {
it3++;
auto t = col.lower_bound(*it3);
it3--;
r = *t;
}
if (b != be) {
it3--;
auto t = col.lower_bound(*it3);
it3++;
l = *t;
}
work(l, b, r, c);
} else {
cin >> c;
cout << sum[c] << '\n';
}
}
}
AtCoder Beginner Contest 380 (A~E)题解的更多相关文章
- AtCoder Beginner Contest 238 A - F 题解
AtCoder Beginner Contest 238 \(A - F\) 题解 A - Exponential or Quadratic 题意 判断 \(2^n > n^2\)是否成立? S ...
- AtCoder Beginner Contest 221 A~E题解
目录 A - Seismic magnitude scales B - typo C - Select Mul D - Online games E - LEQ 发挥比较好的一场,就来搓篇题解. F ...
- AtCoder Beginner Contest 215 F题题解
F - Dist Max 2 什么时候我才能突破\(F\)题的大关... 算了,不说了,看题. 简化题意:给定\(n\)个点的坐标,定义没两个点的距离为\(min(|x_i-x_j|,|y_i-y_j ...
- AtCoder Beginner Contest 213 F题 题解
F - Common Prefixes 该题也是囤了好久的题目了,看题目公共前缀,再扫一眼题目,嗯求每个后缀与其他后缀的公共前缀的和,那不就是后缀数组吗?对于这类问题后缀数组可是相当在行的. 我们用后 ...
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解
KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
随机推荐
- win10缺少SNMP服务解决办法
一,以管理员的身份启动Powershell 第一步在win10系统任务栏上,点击搜索图标,输入"PowerShell",如下图所示: 2 第二步搜索到PowerShell之后,鼠标 ...
- Transformer模型:Position Embedding实现
在自然语言处理(NLP)中,Transformer 模型是一个非常重要的里程碑,它通过自注意力(self-attention)机制极大地提高了处理序列数据的能力.在 Transformer 模型中,词 ...
- 折腾 Quickwit,Rust 编写的分布式搜索引擎 - 可观测性之日志管理
Quickwit 从底层构建,旨在 高效地索引非结构化数据,并在云存储上轻松搜索这些数据. 此外,Quickwit 开箱即支持 OpenTelemetry gRPC 和 HTTP(仅 protobuf ...
- WPF性能优化之UI虚拟化
@ 目录 前言 一.VirtualizingStackPanel 1.1 虚拟化功能介绍 1.在Window中添加一个ListBox控件. 2.在设计视图中用鼠标选中ListBox控件并右健依次单击& ...
- ubuntu 20.04安装GCC G++ 6.2,支持c++ 14
1. 下载源码包 wget http://ftp.gnu.org/gnu/gcc/gcc-6.2.0/gcc-6.2.0.tar.bz2 2. 解压 tar jxf gcc-6.2.0.tar.bz2 ...
- nRF24L01芯片驱动记录
nRF24L01芯片驱动记录 学习完了usb,了解了部分元器件的功能以及用途后,打算在端午假期用一天的时间完成一个小目标,不过实际上是花了一天半才成功实现,现将驱动nRF24L01芯片的整个过程记 ...
- Git 客户端基本使用及新手常见问题
Git作为一个版本管理工具,在企业中的应用越来越普遍.作为一个测试工程师,不可避免会需要接触到Git的相关操作,以下整理Git客户端的常见操作,以及应用中新手常碰到的一些问题. 1.环境安装及配置 G ...
- SpringMVC —— 日期类型参数传递
日期类型参数传递 相关注解 类型转换器
- spring 拦截器实现token校验登录
pom文件 <dependency> <groupId>com.auth0</groupId> <artifactId>java-jwt</art ...
- DevNow: Search with Lunrjs
前言 假期真快,转眼国庆假期已经到了最后一天.这次国庆没有出去玩,在北京看了看房子,原先的房子快要到期了,找了个更加通透一点的房子,采光也很好. 闲暇时间准备优化下 DevNow 的搜索组件,经过上一 ...