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. RSA学习档案

    RSA 学习档案 基本原理 随机选择两个质数p,q模数n=p*qφ(n)=(p−1)(q−1)选择加密指数e: 1 < e < φ(n)计算机密指数d: e*d % φ(n) = 1c = ...

  2. 138.更改session的存储机制

    修改session的存储机制: 默认情况下,session数据时存储到数据库中,当然也可以将session数据存储到其他地方.可以通过设置SESSION_ENGINE来更改session的存储位置,这 ...

  3. linux - 服务器性能评估

    影响Linux服务器性能的因素 cpu 内存 磁盘IO 网络IO 系统性能评估标准 影响性能因素 好 坏 糟糕 CPU user% + sys%< 70% user% + sys%= 85% u ...

  4. 关闭Apache的目录浏览功能

    一.默认情况 默认情况下,Apache的配置文件C:\web\apache2.4\conf/httpd.conf中有如下参数: 引用 <Directory "/var/www/html ...

  5. Linux的VMware虚拟机无法上网问题

    很多时候,Linux无法上网,不管改成nat模式还是主机模式都不行.这时候可以选择进行重置: 首先点击编辑,之后点击虚拟网络编辑器, 然后移除VMnet0和VMnet8网络,点击确定: 然后再打开虚拟 ...

  6. 树莓派中安装ubuntu及相关设置

    一.下载并烧录系统 首先准备好我们要烧录的ubuntu_meta系统,可以在树莓派官网中下载https://www.raspberrypi.org/downloads/ 这里我们选择 Raspberr ...

  7. 使用pycharm搜索框和正则表达式匹配内容

    使用pycharm搜索框和正则表达式匹配内容原创薯饼__ 最后发布于2019-03-04 19:28:53 阅读数 660 收藏展开有时候我们要在爬虫网站中匹配各种各样的文本块,以获取需要的信息,每一 ...

  8. js中变量含(参数、数组)作用域传递问题

    js没有块级作用域(你可以自己闭包或其他方法实现),只有函数级作用域和全局作用域,函数外面的变量函数里面可以找到使用,函数里面的变量外面无法访问到. 写这个是因为ES6中的一个例子开始的.首先看下例子 ...

  9. [Arc068D/At2299] Card Eater - 结论

    [Arc068D/At2299] 有一堆牌,每张牌上有一个数字. 每次可以取出其中 \(3\) 张,丢掉数字最大的和数字最小的牌,把中间那张再放回牌堆. 要求最后所有剩余牌上的数字互不相同,求最多能剩 ...

  10. spring boot MySQL Public Key Retrieval is not allowed

    建议在链接url处添加对应的属性 jdbc:mysql://localhost:3306/book?allowPublicKeyRetrieval=true&useSSL=false