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\) 的线段左端点最小值。

那么

\[dp[i] = dp[j] + cnt[i] \ \ \ \ \ (j < L[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的更多相关文章

  1. Codeforces Round #552 (Div. 3) EFG(链表+set,dp,枚举公因数)

    E https://codeforces.com/contest/1154/problem/E 题意 一个大小为n(1e6)的数组\(a[i]\)(n),两个人轮流选数,先找到当前数组中最大的数然后选 ...

  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. logback 日志输出配置

    application.properties文件中  logging.config=classpath:logback-spring-dev.xml logback-spring-dev.xml &l ...

  2. mybatis 中 if else 写法

    mybaits 中没有else要用chose when otherwise 代替 <choose> <when test=""> //... </wh ...

  3. KingbaseES 查看函数中最耗时的sql

    测试 创建测试环境所需表及函数 create table test1(id int); INSERT INTO test1(id) VALUES (generate_series(1, 10000)) ...

  4. 队列(ArrayQueue)

    队列是一种 先进先出(First In First Out,FILO) 的种线性数据结构 . 代码是在动态数组二次封装,先阅读底层实现体验更佳 Array.h 点它 代码清单 #ifndef C___ ...

  5. .net和java串口通讯压力测试对比

    最近由于工作要求,需要对一个串口通讯设备进行压力测试,要求连续持续对串口设备发送指令,无间隔,测试设备是否会死机. 要求做到毫秒级,测试第三方的工具,基本上都无法达到毫秒级,最少的也是10毫秒. 于是 ...

  6. #链表#CF706E Working routine

    题目 给出一个 \(n*m\) 的矩阵,每次交换两个等大的矩阵,输出 \(q\) 次操作后的矩阵 分析 维护向右和向下的指针,考虑最后输出只需要从每行的头指针向右跳, 那么修改实际上是将矩阵左边一列. ...

  7. 2023 LGR 非专业级别软件能力认证第一轮(初赛)S组

    计算器.背包.代码都不能带进考场 禁赛三年并全国通报 B选项符合while语句 弱类型编程语言指的是可以进行类型转换,可以参与各种类型变量的运算 \[3\times 60(秒)\times 44.1\ ...

  8. C++ 条件与 If 语句:掌握逻辑判断与流程控制精髓

    C++ 条件和 If 语句 您已经知道 C++ 支持数学中的常见逻辑条件: 小于:a < b 小于或等于:a <= b 大于:a > b 大于或等于:a >= b 等于:a = ...

  9. HDC2021技术分论坛:跨端分布式计算技术初探

    作者:zhengkai,分布式通信首席技术专家 当今的移动应用都向着智能化和多样化方向发展,例如AI辅助,VR/AR应用,沉浸式游戏等.然而现实中的移动设备,因为便携性要求受限于尺寸.电池容量以及温控 ...

  10. Centos8防火墙配置、端口、进程管理

    Centos8停用.启用.查看当前启用的端口 firewall-cmd --zone=public --add-port=5672/tcp --permanent # 开放5672端口 firewal ...