E - Addition on Segments

思路:

dp

dp[i]表示构成i的区间的右端点

先将询问按r排序

然后,对于每次询问,每次枚举 i 从 n-x 到 1,如果dp[i] >= l , 那么 dp[i+x] = max(dp[i+x], dp[j])

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 1e4 + ;
struct node {
int l, r, x;
bool operator < (const node & t) const {
return r < t.r;
}
}Q[N];
int dp[N];
int main() {
int n, q, l, r, x;
scanf("%d%d", &n, &q);
for (int i = ; i <= q; i++) {
scanf("%d%d%d", &Q[i].l, &Q[i].r, &Q[i].x);
}
sort(Q+, Q++q);
for (int i = ; i <= q; i++) {
l = Q[i].l;
r = Q[i].r;
x = Q[i].x;
for (int j = n-x; j >= ; j--) {
if(dp[j] >= l) dp[j+x] = max(dp[j+x], dp[j]);
}
dp[x] = r;
}
int ans = ;
for (int i = ; i <= n; i++) ans += (dp[i]>);
printf("%d\n", ans);
for (int i = ; i <= n; i++) if(dp[i]) printf("%d ", i);
return ;
}

Codeforces 981 E - Addition on Segments的更多相关文章

  1. Codeforces 981 D.Bookshelves(数位DP)

    Codeforces 981 D.Bookshelves 题目大意: 给n个数,将这n个数分为k段,(n,k<=50)分别对每一段求和,再将每个求和的结果做与运算(&).求最终结果的最大 ...

  2. Codeforces 981 共同点路径覆盖树构造 BFS/DP书架&最大值

    A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...

  3. Codeforces Round #535 E2-Array and Segments (Hard version)

    Codeforces Round #535 E2-Array and Segments (Hard version) 题意: 给你一个数列和一些区间,让你选择一些区间(选择的区间中的数都减一), 求最 ...

  4. CodeForces - 981E Addition on Segments

    考虑每个点i在什么情况下会成为最大值. 当选的区间子集是 包含i的区间的一个子集的时候,i肯定会是最大值. 所以我们就可以用这种方法得到所有点的可能的最大值是多少... 也就是说,最后的局面可以仅由一 ...

  5. Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化

    D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...

  6. Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】

    任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...

  7. 【20.51%】【codeforces 610D】Vika and Segments

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. codeforces A. Strange Addition 解题报告

    题目链接:http://codeforces.com/problemset/problem/305/A 题目意思:给出一个序列,需要从中选择一些数,这些数需要满足:任意的两个数中每一位至少有一个数满足 ...

  9. Codeforces Round #337 Vika and Segments

    D. Vika and Segments time limit per test:  2 seconds     memory limit per test:  256 megabytes input ...

随机推荐

  1. 从percona server 5.7换到mariadb 10.2

    过去两年半一直推荐使用percona server,今天开始,因为一些mysql迟迟不不愿意支持的特性,打算换回mariadb 10.2了,具体哪些不说了,总之非常关键,mariadb都支持一两年了, ...

  2. python之字符编码(四)

    一.字符编码的使用: 1.文本编辑器 unicode----->encode-------->utf-8 utf-8-------->decode---------->unic ...

  3. 利用shell脚本通过ssh绕过输入密码直接登录主机

    shell #!/usr/bin/expect spawn ssh root@192.168.137.141 expect "*password:" send "lizh ...

  4. vector at()函数比 []运算符操作安全

    转载:https://blog.csdn.net/chenjiayi_yun/article/details/18507659 []操作符的源码 reference operator[](size_t ...

  5. 解决跨域(CORS)问题

    为什么会有跨域问题 是因为浏览器的同源策略是对ajax请求进行阻拦了,但是不是所有的请求都给做跨域,像是一般的href属性,a标签什么的都不拦截 解决跨域问题的两种方式 JSONP   推荐参考 CO ...

  6. repo回退当前分支下所有仓库到指定日期前的最新代码版本【转】

    本文转载自:https://blog.csdn.net/u011006622/article/details/70272087 执行下面这样的repo命令就行了:  repo forall -c 'c ...

  7. luogu P2486 [SDOI2011]染色

    树剖做法: 就是两个dfs+一个线段树 难度的取决基本==线段树的维护难度 所以对有点线段树基础的,树剖也不难做吧 这里操作有二 一:两点间路径染色 线段树的区间赋值操作 二:查询路径段的个数 考虑线 ...

  8. Docker 搭建Spark 依赖sequenceiq/spark:1.6镜像

    使用Docker-Hub中Spark排行最高的sequenceiq/spark:1.6.0. 操作: 拉取镜像: [root@localhost home]# docker pull sequence ...

  9. 【做题】agc002D - Stamp Rally——整体二分的技巧

    题意:给出一个无向连通图,有\(n\)个顶点,\(m\)条边.有\(q\)次询问,每次给出\(x,y,z\),最小化从\(x\)和\(y\)开始,总计访问\(z\)个顶点(一个顶点只计算一次),经过的 ...

  10. Linux/shell: Concatenate multiple lines to one line

    $ cat file START Unix Linux START Solaris Aix SCO 1. Join the lines following the pattern START with ...