codeforces 354 D. Transferring Pyramid
3 seconds
256 megabytes
standard input
standard output
Vasya and Petya are using an interesting data storing structure: a pyramid.
The pyramid consists of n rows, the i-th row contains i cells. Each row is shifted half a cell to the left relative to the previous row. The cells are numbered by integers from 1 to
as shown on the picture below.
An example of a pyramid at n = 5 is:

This data structure can perform operations of two types:
- Change the value of a specific cell. It is described by three integers: "t i v", where t = 1 (the type of operation), i — the number of the cell to change and v the value to assign to the cell.
- Change the value of some subpyramid. The picture shows a highlighted subpyramid with the top in cell 5. It is described by s + 2numbers: "t i v1 v2 ... vs", where t = 2, i — the number of the top cell of the pyramid, s — the size of the subpyramid (the number of cells it has), vj — the value you should assign to the j-th cell of the subpyramid.
Formally: a subpyramid with top at the i-th cell of the k-th row (the 5-th cell is the second cell of the third row) will contain cells from rows from k to n, the (k + p)-th row contains cells from the i-th to the (i + p)-th (0 ≤ p ≤ n - k).
Vasya and Petya had two identical pyramids. Vasya changed some cells in his pyramid and he now wants to send his changes to Petya. For that, he wants to find a sequence of operations at which Petya can repeat all Vasya's changes. Among all possible sequences, Vasya has to pick the minimum one (the one that contains the fewest numbers).
You have a pyramid of n rows with k changed cells. Find the sequence of operations which result in each of the k changed cells being changed by at least one operation. Among all the possible sequences pick the one that contains the fewest numbers.
The first line contains two integers n and k (1 ≤ n, k ≤ 105).
The next k lines contain the coordinates of the modified cells ri and ci (1 ≤ ci ≤ ri ≤ n) — the row and the cell's number in the row. All cells are distinct.
Print a single number showing how many numbers the final sequence has.
4 5
3 1
3 3
4 1
4 3
4 4
10
7 11
2 2
3 1
4 3
5 1
5 2
5 5
6 4
7 2
7 3
7 4
7 5
26
One of the possible solutions of the first sample consists of two operations:
2 4 v4 v7 v8
2 6 v6 v9 v10
The picture shows the changed cells color-highlighted. The subpyramid used by the first operation is highlighted blue and the subpyramid used by the first operation is highlighted yellow:

————————————————————————
这道题的中文题解似乎没有,贡献一篇
终于体现了板子的优越性【?】



这样的话我们就可以愉快的做完这道题
不过写起来真的超。多。坑。
建议大家写一写,跳一跳坑,有助于代码能力的成长
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#define inf 0x7f7f7f7f
//#define ivorysi
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
using namespace std;
int n,k;
vector<int> c[];
int ans;
int f[];
int sum[],cost[];//数组不要开小qwq
void init() {
scanf("%d %d",&n,&k);
int a,b;
siji(i,,k) {
scanf("%d%d",&a,&b);
c[b].push_back(n-a+);
}
ans=*k;
}
void solve() {
init();
int t;
siji(i,,n) {
t=min(n-i+,);
memset(sum,,sizeof(sum));
cost[]=f[];
xiaosiji(z,,c[i].size()) {if(c[i][z]<=t)sum[c[i][z]]=;}
//因为我们枚举只到了(6k)^0.5,所以这以后的都不再统计,防止爆数组
siji(z,,t+) sum[z]+=sum[z-];
siji(z,,t) cost[z]=max(cost[z-],f[z]);
if(i==) {
siji(z,,t+) f[z]=-inf;
}
xiaosiji(j,,t) {
if(j==) {
f[j]=max(f[j+],cost[]-)+*sum[j+];
f[j]=max(f[j],cost[]);//0是我们选择不在这一列放的唯一途径
}
else {
f[j]=max(f[j+],cost[j]-(j+)*(j+)/-)+*sum[j+];
}
} }
printf("%d\n",ans-f[]);
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
solve();
return ;
}
codeforces 354 D. Transferring Pyramid的更多相关文章
- codeforces 354 DIV2
B - Pyramid of Glasses n层杯子,问k分钟能流满多少个杯子?和到香槟一样的过程? 思路:应为水的流速为每分钟一立方体(YY),可以做个转化,把最上层的杯子最原始的容积看成K,每个 ...
- codeforces 354 div2 C Vasya and String 前缀和
C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #354 (Div. 2) B. Pyramid of Glasses 模拟
B. Pyramid of Glasses 题目连接: http://www.codeforces.com/contest/676/problem/B Description Mary has jus ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #354 (Div. 2)-B
B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...
- Codeforces Round #354 (Div. 2)
贪心 A Nicholas and Permutation #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 ...
- Codeforces Round #354 (Div. 2)-D
D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived t ...
- Codeforces Round #354 (Div. 2)-C
C. Vasya and String 题目链接:http://codeforces.com/contest/676/problem/C High school student Vasya got a ...
- Codeforces Round #354 (Div. 2)-A
A. Nicholas and Permutation 题目链接:http://codeforces.com/contest/676/problem/A Nicholas has an array a ...
随机推荐
- Hadoop生态圈-hive优化手段-作业和查询优化
Hadoop生态圈-hive优化手段-作业和查询优化 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.
- js 正则表达式 整数或小数
非零开头的整数或小数 /^[1-9][0-9]*([.][0-9]+)?$/ 非零开头的整数或两位小数 /^[1-9][0-9]*([.][0-9]{1,2})?$/ /^[1-9][0-9]*([. ...
- NOI2006 最大获利(最大权闭合子图)
codevs 1789 最大获利 2006年NOI全国竞赛 时间限制: 2 s 空间限制: 128000 KB 题目描述 Description 新的技术正冲击着手机通讯市场,对于各大运营商来 ...
- 细说 struct和typedef struct
细说 struct和typedef struct 参考原文:http://www.cnblogs.com/qyaizs/articles/2039101.html,有些小改动~ 1 首先://注意在C ...
- iframe元素的学习(笔记)
什么是iframe:iframe元素即内联框架,iframe是内联的并且承前启后,对于外围的页面,iframe是一个普通的元素,对于iframe里面的内容,又是一个五脏俱全的页面.重下面的写法可以看出 ...
- 【专题】平衡树(Treap,fhq-treap)
[旋转] 平衡树中的旋转是指在不改变中序遍历的前提下改变树的形态的方式.(中序遍历=排名顺序) 右旋将当前点的左节点旋上来,左旋反之.(图侵删) void rturn(int &k){ int ...
- 20155209 2016-2017-2 《Java程序设计》第五周学习总结
20155209 2016-2017-2 <Java程序设计>第五周学习总结 教材学习内容总结 try语句用大括号{}指定了一段代码,该段代码可能会抛弃一个或多个例外. catch语句的参 ...
- 微服务深入浅出(5)-- 声明式调用Feign
Feign的使用 Feign采用了声明式的API接口的风格,将Java Http客户端绑定到它的内部,从而调用过程变的简单. 配置文件: spring: application: name: eure ...
- 某大型网络社区传播性XSS分析
某大型网络社区传播性XSS分析 这个XSS存在于天涯某个不起眼的子论坛,通过发布新帖子可以触发. 漏洞分析 论坛针对XSS有一定过滤措施,例如转义单双引号,过滤左右尖括号等等.所 ...
- 【hdu6334】【2018Multi-University-Training Contest04】Problem C. Problems on a Tree
维护1边的联通块和2边的联通块,合并的时候直接启发式合并. cdqz的大爷好强啊. #include<bits/stdc++.h> #define lson (o<<1) #d ...