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. C++获取任务管理器信息,封装成DLL,C#调用例子

    C++代码 pch.h // pch.h: 这是预编译标头文件. // 下方列出的文件仅编译一次,提高了将来生成的生成性能. // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏 ...

  2. docker-compose转义相关

    环境变量值里面写$美元符号,用两个$符号来转义就可以了 下面的MYSQL_ROOT_PASSWORD的密码是lehuiguan!@#$,转义后写的变量就是lehuiguan!@#$$ environm ...

  3. 整合mybatis-spring需要的maven依赖配置

    创建maven项目,导入相关jar包 junit 1 <dependency> 2 <groupId>junit</groupId> 3 <artifactI ...

  4. 【已解决】Hadoop_03 解决Hadoop输入jps没有NameNode的问题

    问题描述: 解决方案: 1.先运行 stop-all.sh 2.格式化 namdenode(在这之前要先删除原目录,即core-site.xml下配置的<name>hadoop.tmp.d ...

  5. 03-【HAL库】STM32实现SYN6288模块语音播报.md

    一.什么是SYN6288模块 1.概述 ​ SYN6288 中文语音合成芯片是北京宇音天下科技有限公司于2010 年初推出的一款性/价比更高,效果更自然的一款中高端语音合成芯片.SYN6288 通过异 ...

  6. #斐波那契#洛谷 3424 [POI2005] SUM-Fibonacci Sums

    题目 已知\(x,y\)的斐波那契表示,求\(x+y\)的斐波那契表示 分析 显然得到两条性质: \(f_{i+1}=f_{i-1}+f_i\) \(2f_i=f_{i+1}+f_{i-2}\) 那么 ...

  7. Jetty的https模块

    启用https模块,执行如下命令: java -jar $JETTY_HOME/start.jar --add-modules=https 命令的输出,如下: INFO : https initial ...

  8. SQL DELETE 语句:删除表中记录的语法和示例,以及 SQL SELECT TOP、LIMIT、FETCH FIRST 或 ROWNUM 子句的使用

    SQL DELETE 语句 SQL DELETE 语句用于删除表中的现有记录. DELETE 语法 DELETE FROM 表名 WHERE 条件; 注意:在删除表中的记录时要小心!请注意DELETE ...

  9. Qt线程简单使用二:QObject~创建任务类

      需求: 点击QPushButton按钮,QLabel中的数字,不断累加,一直到999.   做法: 创建任务类,用来完成任务,创建子线程,将任务类放到子线程中,点击QPushButton后,先发送 ...

  10. npm发包教程

    1-npm注册账号 访问npm官网注册账号,邮件验证激活账号 npm官网 2-项目npm配置 在项目下打开终端,初始化npm npm init -y 此时项目下会生成package.json 配置文件 ...