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运算的性质的更多相关文章

  1. Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学

    题意:给出树 求最大的sigma(a)/k k是选取的联通快个数   联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值  这里先要满足最大平均值  而首先要满足最大  也就是一个数的时候可 ...

  2. 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 题意: 给出一颗点有权值的树 ...

  3. 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 题意: 给出一个 ...

  4. 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 ...

  5. Codeforces Round #525 (Div. 2)B. Ehab and subtraction

    B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减 ...

  6. 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,找 ...

  7. 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/ ...

  8. Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task

    传送门 https://www.cnblogs.com/violet-acmer/p/10068786.html 题意: 给定一个长度为 n 的数组a[ ],并且有两种操作: ①将前 i 个数全都加上 ...

  9. 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^ ...

随机推荐

  1. 巨杉数据库SequoiaDB】巨杉Tech | SequoiaDB 分布式事务实现原理简介

    1 分布式事务背景 随着分布式数据库技术的发展越来越成熟,业内对于分布式数据库的要求也由曾经只用满足解决海量数据的存储和读取这类边缘业务向核心交易业务转变.分布式数据库如果要满足核心账务类交易需求,则 ...

  2. Android_SQLite简单的增删改查

    SQLite数据库,和其他的SQL数据库不同, 我们并不需要在手机上另外安装一个数据库软件,Android系统已经集成了这个数据库,我们无需像 使用其他数据库软件(Oracle,MSSQL,MySql ...

  3. C语言实现链式二叉树静态创建,(先序遍历),(中序遍历),(后续遍历)

    #include <stdio.h>#include <stdlib.h> struct BTNode{ char data ; struct BTNode * pLchild ...

  4. H5_0009:关于HTML5中Canvas的宽、高设置问题

    关于HTML5中Canvas的宽.高设置问题 Canvas元素默认宽 300px, 高 150px, 设置其宽高可以使用如下方法(不会被拉伸): 方法一:        <canvas widt ...

  5. 51nod1326 遥远的旅途(spfa+dp)

    题意: 给出一个无向图,问从1到n是否存在一条长度为L的路径. n,m<=50,1<=路径长度<=10000,L<=10^18 思路: 改变一下思路,我们发现,假设从起点1走到 ...

  6. 广搜 BFS()

    极其简陋的BFS模板 void BFS(???){ queue<node>q; node start, next; start = ???; q.push(start); while(!q ...

  7. Jmeter-集合点与关联

    1.集合点 添加同步定时器(Synchronizing Timer) 注意:集合点需要放在需要集合的元件前面 2.关联 预先使用Badboy录制WebTours登录脚本 在登录前插入一个监听器:察看结 ...

  8. canvas转盘转动?

    怎么实现类似转盘转动的效果? 现在这种实现思路是,canvas每次draw()并不是让图形在旋转,而是让每一份的颜色改变到达好像是转动的效果, 但是现在有一个问题,一开始渲染的颜色数量于份数是相同的, ...

  9. early-stopping的使用

    early-stopping的使用 待办 https://blog.csdn.net/qq_37430422/article/details/103638681 github对应类导入,直接放在项目更 ...

  10. Quartz.NET 2.x教程

    第1课:使用Quartz第2课:工作和触发器第3课:关于工作和JobDetails的更多信息第4课:有关触发器的更多信息第5课:SimpleTriggers第6课:CronTriggers第7课:Tr ...