Ehab and a 2-operation task【数论思想】
You're given an array aa of length nn. You can perform the following operations on it:
- choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (0≤x≤106)(0≤x≤106), and replace ajaj with aj+xaj+x for all (1≤j≤i)(1≤j≤i), which means add xx to all the elements in the prefix ending at ii.
- choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (1≤x≤106)(1≤x≤106), and replace ajaj with aj%xaj%x for all (1≤j≤i)(1≤j≤i), which means replace every element in the prefix ending at ii with the remainder after dividing it by xx.
Can you make the array strictly increasing in no more than n+1n+1 operations?
Input
The first line contains an integer nn (1≤n≤2000)(1≤n≤2000), the number of elements in the array aa.
The second line contains nn space-separated integers a1a1, a2a2, ……, anan (0≤ai≤105)(0≤ai≤105), the elements of the array aa.
Output
On the first line, print the number of operations you wish to perform. On the next lines, you should print the operations.
To print an adding operation, use the format "11 ii xx"; to print a modding operation, use the format "22 ii xx". If ii or xx don't satisfy the limitations above, or you use more than n+1n+1 operations, you'll get wrong answer verdict.
Examples
Input
3
1 2 3
Output
0
Input
3
7 6 3
Output
2
1 1 1
2 2 4
Note
In the first sample:
the array is already increasing so we don't need any operations.
In the second sample:
In the first step: the array becomes [8,6,3][8,6,3].
In the second step: the array becomes [0,2,3][0,2,3].
思路:
先将输入的 a[i] 全部加上 MAX=1e6
然后从i=1 开始到 i=n 每次将 a[i]%(a[i]-i)
这样可以保证每次取余前面的每个值都不受影响(怎么也想不到这样……)
例如:
a[i]: 3 6 4 9
a[i]+MAX: 1000003 1000006 1000004 1000009
a[i]%(a[i]-i) : 1 2 3 4
AC代码:
#include<stdio.h>
const int MAX=1e6;
int main()
{
int a[MAX+5],n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
printf("%d\n",n+1);
printf("1 %d %d\n",n,MAX);
for(int i=0;i<n;i++){
printf("2 %d %d\n",i+1,a[i]+MAX-(i+1));
}
return 0;
}
Ehab and a 2-operation task【数论思想】的更多相关文章
- Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...
- Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
- codeforces-473D Mahmoud and Ehab and another array construction task (素数筛法+贪心)
题目传送门 题目大意:先提供一个数组,让你造一个数组,这个数组的要求是 1 各元素之间都互质 2 字典序大于等于原数组 3 每一个元素都大于2 思路: 1.两个数互质的意思就是没有公因子.所以每 ...
- 959F - Mahmoud and Ehab and yet another xor task xor+dp(递推形)+离线
959F - Mahmoud and Ehab and yet another xor task xor+dp+离线 题意 给出 n个值和q个询问,询问l,x,表示前l个数字子序列的异或和为x的子序列 ...
- D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学
D. Mahmoud and Ehab and another array construction task 因子分解模板 题意 给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!= ...
- uva 11728 - Alternate Task(数论)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/36409469 option=com_onli ...
- CF959D Mahmoud and Ehab and another array construction task 数学
Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same l ...
- Codeforces 959 D Mahmoud and Ehab and another array construction task
Discription Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of ...
随机推荐
- Java流程控制以及顺序、选择、循环结构
目录 用户交互Scanner Scanner对象 hasNext()与next() hasNextLine()与nextLine() Scanner进阶用法 求和与平均数 顺序结构 选择结构 if单选 ...
- Angular SPA基于Ocelot API网关与IdentityServer4的身份认证与授权(三)
在前面两篇文章中,我介绍了基于IdentityServer4的一个Identity Service的实现,并且实现了一个Weather API和基于Ocelot的API网关,然后实现了通过Ocelot ...
- javascript代码重构需要考虑的问题(一)
1.将数组的长度进行存储,循环时就不用每次去读取一次数组长度,从而提升性能 例如: for (var i = 0, len = arr.length; i < len; i++) { //do ...
- opencv3学习1:opencv3.4.10与vs2017环境配置
原教程网址:https://jingyan.baidu.com/article/dca1fa6f13bd55f1a44052b9.html 具体教程网上很多,我也相信大家的搜素能力,作为一个初入C++ ...
- rfind()的使用
今天学了一个新函数 rfind 使用: str=123/456 str.rfind('/',1,6) 返回的是从1到6找最后一个/的位置
- 【Java】向*.txt文档里面重复添加同一个字符串
闺蜜说让我用代码写五万个对不起给她~~ import java.io.FileWriter; import java.io.IOException; /** * Created by lenovo o ...
- unicode、encode、decode
1.encode与decode:unicode经过encode -> utf-8,反过来为decode. 爬虫读取网页内容和pandas读取csv时,会把读取到的文字内容转成unicode,当我 ...
- LM NTML NET-NTLM2理解及hash破解
LM Windows Vista / Server 2008已经默认关闭,在老版本可以遇到,但根据windwos的向下兼容性,可以通过组策略启用它(https://support.microsoft. ...
- raw_input和input
昨天在OJ上做CTF的题目,发现有道python的题目很有意思,让我知道了raw_input和input的区别,并且能干一些别的事情. 官方文档上说,input()相当于eval(raw_input( ...
- C#中值类型,引用类型,字符串类型的区别(内存图解)
如果用图片来解释值类型,引用类型和字符串类型(引用类型的一种)的区别的话 值类型: 引用类型: string类型: