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. 【题解】Luogu P4450 双亲数

    原题传送门 这题需要运用莫比乌斯反演(懵逼钨丝繁衍) 设F(t)表示满足gcd(x,y)%t=0的数对个数,f(t)表示满足gcd(x,y)=t的数对个数,实际上答案就是f(d) 这就满足莫比乌斯反演 ...

  2. Nginx:论高并发,在座各位都是渣渣

    NGINX 在网络应用中表现超群,在于其独特的设计.许多网络或应用服务器大都是基于线程或者进程的简单框架,NGINX突出的地方就在于其成熟的事件驱动框架,它能应对现代硬件上成千上万的并发连接. NGI ...

  3. python简说(十)json模块

    常用模块: 一个python文件就是一个模块 1.标准模块,python自带的 2.第三方模块,需要安装 3.自己写的python文件 json,就是一个字符串 1.json转为字典 json_str ...

  4. python简说(七)元组,集合

    一.元组 元组也是一个list,但是它的值不能改变 定义元组的时候,只有一个元素,后面得加逗号 oracle_info = (123,) 二.集合 1.集合天生就可以去重,集合是无序的 2.#交集 r ...

  5. Microsoft Visual Studio 2010(vs10)安装与使用

    安装1.下载软件: 云盘分享http://pan.baidu.com/s/1i4JL9GT 2.安装 打开Microsoft Visual Studio 2010目录,双击setup.exe ,运行 ...

  6. python --- 03 整型 bool 字符串 for循环

    一.整型(int) 基本操作: 1.+ - * / % // ** 2.  .bit_length() 计算整数在内存中占⽤的⼆进制码的⻓度 如: 二.布尔值(bool) True  False 1. ...

  7. 内置函数之sorted,filter,map

    # 4,用map来处理字符串列表,把列表中所有人都变成sb,比方alex_sb # name=['oldboy','alex','wusir'] # print(list(map(lambda i:i ...

  8. eMMC ext4综述【转】

    本文转载自:https://blog.csdn.net/lieye_leaves/article/details/78214410 eMMC ext4综述一.系统的引导启动1.1系统的引导启动http ...

  9. windows进程中的几个杂项-hpguard 进程终止

    打印机后台进程 c:\windows\system32\spool printers,servers, tool等, 清空printers中的内容就可以正常打印; 锐爽的后视镜跟其他的车型的后视镜不一 ...

  10. 解决Visual Studio(2017)软件无法重新生成问题

    https://blog.csdn.net/qq_38265674/article/details/80539228 笔者用VS2017打开VS2015创建的工程,出现如下图的问题. 不小心没有升级平 ...