Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task 数学 mod运算的性质
C. Ehab and a 2-operation task 数学 mod运算的性质
题意: 有两种对前缀的运算
1.对前缀每一个\(a +x\)
2.对前缀每一个\(a\mod(x)\)
其中x任选
思路:这里只有加法 所以膜运算可以看作是减法 而膜运算当成减法使用需要合理运用其性质
\(a[i]=k*n+b\)
\(a[i]\equiv{b}\pmod{m}\)
只要使得\(a[i]==i\)即可满足题意
而由上式我们知道\(a[i]\equiv{b}\pmod{m}\) 只要看\(b\)和\(a[i]\)的对应位置i相差多少 加上即可 最后在对整个区间进行\(\mod(n)\)
其中注意膜注意取正值 也就是\((i-b+n)\mod(n)\) 最后一个数%n ==0要特殊处理一下
从后往前使得一个一个满足即可
#include<bits/stdc++.h>
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
#define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
#define F first
#define S second
#define pii pair<int ,int >
#define mkp make_pair
#define pb push_back
#define arr(zzz) array<ll,zzz>
using namespace std;
typedef long long ll;
const int maxn=1e5;
int a[maxn];
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
ll presum=0;
if(n==1){cout<<0;return 0;
}
cout<<n+1<<endl;
for(int i=n;i>=1;i--){
a[i]+=presum;
a[i]%=n;
int tmp=i-a[i];
if(tmp<=0)tmp+=n;
//cout<<tmp<<endl;
presum+=tmp;
printf("%d %d %d\n",1,i,tmp);
}
printf("2 %d %d\n",n-1,n);
return 0;
}
Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task 数学 mod运算的性质的更多相关文章
- Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学
题意:给出树 求最大的sigma(a)/k k是选取的联通快个数 联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值 这里先要满足最大平均值 而首先要满足最大 也就是一个数的时候可 ...
- Codeforces Round #525 (Div. 2) F. Ehab and a weird weight formula
F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树 ...
- Codeforces Round #525 (Div. 2)E. Ehab and a component choosing problem
E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...
- Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem
D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...
- Codeforces Round #525 (Div. 2)B. Ehab and subtraction
B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减 ...
- Codeforces Round #525 (Div. 2)A. Ehab and another construction problem
A. Ehab and another construction problem 题目链接:https://codeforc.es/contest/1088/problem/A 题意: 给出一个x,找 ...
- Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)
参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/ ...
- Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task
传送门 https://www.cnblogs.com/violet-acmer/p/10068786.html 题意: 给定一个长度为 n 的数组a[ ],并且有两种操作: ①将前 i 个数全都加上 ...
- Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(交互题 异或)
题目 题意: 0≤a,b<2^30, 最多猜62次. 交互题,题目设定好a,b的值,要你去猜.要你通过输入 c d : 如果 a^c < b^d ,会反馈 -1 : 如果 a^c = b^ ...
随机推荐
- Mac下各种编程环境的配置问题(python java)
首先,去官网下载安装包.直接运行安装.安装完成后,启动器中会多两个应用程序IDLE和Python Launcher. 如果,你习惯在IDLE,直接运行即可. 但你在Terminal中运行python3 ...
- PAT (Basic Level) Practice (中文)1031 查验身份证 (15 分)
一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8, ...
- IDEA常用的几个插件
目录 1. 阿里巴巴代码检测插件 2. Json转Pojo插件 3. mybatis辅助插件 4. 翻译插件 5. markdown插件 6. RestfulToolKit插件 IDEA常用插件 1. ...
- ctf-ping命令执行绕过
题目连接:http://ctf.klmyssn.com/challenges#Ping 命令执行绕过,试了试过滤了一些:一些命令 但是反引号可以执行命令 通过拼接,可以拼接出来:ls 命令 127.0 ...
- [CF527D] Clique Problem - 贪心
数轴上有n 个点,第i 个点的坐标为xi,权值为wi.两个点i,j之间存在一条边当且仅当 abs(xi-xj)>=wi+wj. 你需要求出这张图的最大团的点数. Solution 把每个点看作以 ...
- [Code+#4] 最短路 - 建图优化,最短路
最短路问题,然而对于任意\(i,j\),从\(i\)到\(j\)可以只花费\((i xor j) \cdot C\) 对每个点\(i\),只考虑到\(j\)满足\(j=i xor 2^k, j \le ...
- navicat 连接报2059错误
原因 navicat不支持mysql新版本的加密规则,mysql8 之前的版本中加密规则是mysql_native_password, mysql8之后,加密规则是caching_sha2_passw ...
- linux - mysql - 卸载:RPM包安装方式的MySQL卸载
(1)检查是否安装了MySQL组件 [root@DB-Server init.d]# rpm -qa | grep -i mysql MySQL-devel-5.6.23-1.linux_glibc2 ...
- (转)classload和class.forname()区别
转自:http://carl-java.iteye.com/blog/978680 java中class.forName和classLoader都可用来对类进行加载.前者除了将类的.class文件加载 ...
- Cron表达式及其使用注意事项
Cron表达式简介 Cron表达式全程Crontab表达式,是描述Crontab定时任务执行周期的一种语法格式.而Cron表达式严格上来说有许多特别的版本.如:Linux的.Spring的.Quart ...