Codeforces Round 927 (Div. 3) EFG
E:Link
题意:给定长度小于 \(4 \times 10^5\) 的整数 \(n\),求从 \(0\) 到 \(n\) 各数位变化次数之和。
如:\(n = 12345\)
个位变化 \(12345\) 次,十位变化 \(1234\) 次,百位变化 \(123\) 次,以此类推。
考虑如何快速计算。
1 2 3 4 5
0 1 2 3 4
0 0 1 2 3
0 0 0 1 2
0 0 0 0 1
按列来算,可将复杂度降为 \(O(length)\)。
void solve() {
int n; cin >> n;
string s; cin >> s;
vector<int> a;
int t = 0;
for(auto &c : s) {
t += c - '0';
a.pb(t);
}
vector<int> ans;
reverse(All(a));
rep(i, 0, n - 2) {
a[i + 1] += a[i] / 10;
ans.pb(a[i] % 10);
}
t = a.back();
while(t) {
ans.pb(t % 10);
t /= 10;
}
reverse(All(ans));
int f = 0;
for(int &x : ans) {
if(x != 0) f = 1;
if(f) cout << x;
}
cout << '\n';
}
F:Link
简单的数据结构优化 dp。
题意:\(m\) 条线段,选若干点,选一个点的同时会选中所有覆盖他的全部线段,每条线段只能被选一次,最大化被选线段数量。
- \(dp[i]\) 表示 \([1, i]\) 中的答案。
- \(cnt[i]\) 表示覆盖 \(i\) 的线段数量。
- \(L[i]\) 表示所有覆盖 \(i\) 的线段左端点最小值。
那么
\]
\(L[i]\) 等价于右端点为 \([i, n]\) 的线段左端点最小值,从后往前扫一遍即可。
可以用树状数组实现。
void solve() {
cin >> n >> m;
a.init(n);
vector<vector<int>> qr(n + 1);
rep(i, 1, m) {
int l, r; cin >> l >> r;
qr[r].pb(l);
a.add(l, 1), a.add(r + 1, -1);
}
int minL = n + 1;
per(i, n, 1) {
for(int l : qr[i]) {
minL = min(minL, l);
}
L[i] = min(i + 1, minL);
}
dp.init(n);
rep(i, 1, n) {
if(L[i] <= i) {
dp.mod(i, dp.max(L[i] - 1) + a.sum(i));
}
}
cout << dp.max(n) << '\n';
}
树状数组代码。
struct Fenwick_Tree {
int t[N], n;
int lowbit(int x) {
return x & -x;
}
void init(int x, int v = 0) {
n = x;
rep(i, 1, n) t[i] = v;
}
void mod(int p, int v) {
while(p <= n) {
t[p] = std::max(t[p], v);
p += lowbit(p);
}
}
int max(int p) {
int ret = 0;
while(p) {
ret = std::max(ret, t[p]);
p -= lowbit(p);
}
return ret;
}
void add(int p, int v) {
while(p <= n) {
t[p] += v;
p += lowbit(p);
}
}
int sum(int p) {
int ret = 0;
while(p) {
ret += t[p];
p -= lowbit(p);
}
return ret;
}
} a, dp;
G:拓欧求边权,跑 dij
Codeforces Round 927 (Div. 3) EFG的更多相关文章
- Codeforces Round #552 (Div. 3) EFG(链表+set,dp,枚举公因数)
E https://codeforces.com/contest/1154/problem/E 题意 一个大小为n(1e6)的数组\(a[i]\)(n),两个人轮流选数,先找到当前数组中最大的数然后选 ...
- 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 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 深度探索.NET Feature Management功能开关的魔法
前言 .NET Feature Management 是一个用于管理应用程序功能的库,它可以帮助开发人员在应用程序中轻松地添加.移除和管理功能.使用 Feature Management,开发人员可以 ...
- java中 YYYY与yyyy 区别
大多数情况下格式日期都是用的SimpleDateFormat,比如说把一个日期格式成"yyyy-MM-dd"的形式. 对于年份来说,大写的Y和小写的y其意义是不同的. y 是Yea ...
- C# 中文文字识别OCR
效果 完整Demo下载https://download.csdn.net/download/lw112190/81743333 1. Vs2017打开OcrLiteOnnxCs.sln. 2. 解决方 ...
- Java事件侦听器学习记录
前言 我们监听事件之前要有事件源source,创建事件源(Event),发布事件(publishEvent),然后才能到监听事件. 事件驱动机制是观察者模式(称发布订阅)具体实现,事件对象(Event ...
- date_histogram,es按照时间分组统计
日期直方图聚合(date_histogram) 与histogram相似,es中内部将日期表示为一个long值,所以有时候可以用histogram来达到相同的目的,但往往没有date_histogra ...
- DW:优化目标检测训练过程,更全面的正负权重计算 | CVPR 2022
论文提出自适应的label assignment方法DW,打破了以往耦合加权的惯例.根据不同角度的一致性和非一致性指标,动态地为anchor分配独立的pos权重和neg权重,可以更全面地监督训练.此外 ...
- 才储性格测试(INTJ 专家型——追求能力与独立)
INTJ 专家型--追求能力与独立 一.你的荣格理论图形 二.基本描述 才储分析:您的性格类型倾向为" INTJ "(内向 直觉 思维 判断 倾向度: I60 N56 T74 J5 ...
- OpenHarmony持久化存储UI状态:PersistentStorage
前两个小节介绍的LocalStorage和AppStorage都是运行时的内存,但是在应用退出再次启动后,依然能保存选定的结果,是应用开发中十分常见的现象,这就需要用到PersistentStor ...
- 详讲openGauss 5.0 单点企业版如何部署_Centos7_x86
本文分享自华为云社区<openGauss 5.0 单点企业版部署_Centos7_x86>,本文作者:董小姐 本文档环境:CentOS7.9 x86_64 4G1C40G python2. ...
- Qt调用动态库的三种方式(linux)
本文章主要记录Qt在linux电脑上调用so库的三种调用方式 方式一:静态加载so库 方式二:动态加载so库(QLibrary) 方式三:动态加载so库(dlopen) 其他: 封装的so库叫做: ...