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 ...
随机推荐
- SpringBoot代码生成器,从此不用手撸代码
前言 通常在开始开发项目的时候,首先会建立好数据库相关表,然后根据表结构生成 Controller.Service.DAO.Model以及一些前端页面. 如果开发前没有强制的约束,而每个程序员都有自己 ...
- hdu6005找带权最小环
题意:给你点和边,让你找最小环的权值,其权值是所有边权的和,没环输出-1. 解法:枚举每一条边,找到其端点,做最短路.. #include<cstdio> #include<cstr ...
- poj1966枚举源汇点 求最小点割DInic
Cable TV Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4854 Accepted: 2241 ...
- Istio 将被捐赠给开源基金会 | 云原生生态周报 Vol. 47
作者 | 陈俊.徐迪.陈有坤.李鹏.敖小剑 业界要闻 1.Google Cloud CEO 表示将把 Istio 项目捐赠给基金会 Istio 项目找到了理想的发展方向: 捐赠给开源基金会. 2.Ko ...
- 【转】团队项目的Git分支管理规范
原文地址: http://blog.jboost.cn/git-branch.html 分支管理 创建项目时(一般是服务型项目,工具型或辅助型项目可以简单一些),会针对不同环境创建三个常设分支: de ...
- 0506static【重点】
static[重点] [重点] 1.[没有对象] [没有对象] [没有对象] 2.static 修饰的是一个资源共享类型的变量 3.静态成员变量的基本使用规范 static修饰的成员变量只能通过静态方 ...
- 5.CSS的引入方式
CSS的三种样式表 按照CSS样式书写的位置(或者引入的方式),CSS的样式表可以分为三大类: 1.行内样式表(行内式) <div style="color:red: font-siz ...
- linux 多线程 信号
一个老系统的问题,用的system v消息队列同步等响应,通过alarm信号来进行超时控制.现在系统进行升级改造(所谓云化),原来进程处理的逻辑全部改成了线程框架,问题就出现了.alarm信号发出的时 ...
- matlab单目相机标定——标定步骤以及参数含义
参考博客园的一篇文章: https://www.cnblogs.com/flyinggod/p/8470407.html#commentform
- python通用数据库操作工具 pydbclib
pydbclib是一个通用的python关系型数据库操作工具包,使用统一的接口操作各种关系型数据库(如 oracle.mysql.postgres.hive.impala等)进行增删改查,它是对各个p ...