CF306B.Optimizer
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A process RAM is a sequence of bytes that are indexed from 1 to n. Polycarpus's program contains such instructions as "memset", that is, the operations of filling memory cells on a segment with some value. The details are: the code only contains m instructions that look like "set13 a_i l_i". Instruction i fills a continuous memory segment of length l__i, starting from cell number a__i, (that it cells with numbers a__i, a__i + 1, ..., a__i + l__i - 1) with values 13.
In Polycarpus's code, the optimizer's task is to remove the maximum number of instructions from his code in such a way that the remaining instructions set value 13 in all the memory bytes that got this value from the code before the optimization. Also, the value 13 should be set only in the memory bytes that got this value from the code before the optimization. Your task is to implement the optimizer for such program.
进程 RAM 是一个字节数组,其索引从 1 到 $ n $。Polycarpus 的程序中包含类似 “memset” 的指令,即对某一段内存区域执行赋值操作。具体而言:该程序仅包含 $ m $ 条形如 “set13 $ a_i $ $ l_i $” 的指令。第 $ i $ 条指令将起始于地址 $ a_i $、长度为 $ l_i $ 的连续内存段(即地址为 $ a_i,, a_i + 1,, \dots,, a_i + l_i - 1 $ 的内存单元)全部赋值为 13。
在 Polycarpus 的代码中,优化器的任务是:从原代码中移除尽可能多的指令,使得剩余指令所设置为 13 的内存字节集合,与原始代码中所有被设置为 13 的内存字节集合完全一致(即:优化后,所有原本被设为 13 的字节仍被设为 13;且没有额外的字节被错误地设为 13)。你的任务是为该程序实现这样一个优化器。
输入格式
The first line contains integers n and m (1 ≤ n ≤ 2·106, 1 ≤ m ≤ 2·105) — the number of bytes (memory cells) and the number of instructions in Polycarpus's code. Then m lines follow, each line contains a pair of integers a__i, l__i (1 ≤ a__i ≤ n, 1 ≤ l__i ≤ n - a__i + 1).
第一行包含两个整数 n 和 m(1 ≤ n ≤ 2⋅106,1 ≤ m ≤ 2⋅105)—— 分别表示字节数(内存单元数)和 Polycarpus 程序中的指令数。接下来有 m 行,每行包含一对整数 ai、li(1 ≤ ai ≤ n,1 ≤ li ≤ n − ai + 1)。
输出格式
Print in the first line the sought maximum number of instructions that can be removed from the code. In the second line print the numbers of the instructions. The instructions are numbered from 1 to m in the order they appeared in the input. If there are multiple solutions, print any of them.
第一行输出可以从代码中删除的指令的最大数量。
第二行输出这些指令的编号。指令按输入中的顺序从 1 到 m 编号。若存在多种解,输出任意一种即可。
输入输出样例
输入#1
10 4 3 3 3 1 4 1 9 2
输出#1
2 2 3
输入#2
1 1 1 1
输出#2
0
输入解题思路,AI测评打分。不知道怎么写?