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^ ...
随机推荐
- hackintosh和windows时区问题
最近搞了几台黑苹果,驱动.平台.引导基本搞明白了.但安装成功之后,发现一个问题,切换系统之后,时间老是差了几个小时. 这肯定是时区设置的事儿!百度之后,发现简单地往Windows注册表中写了一条信息就 ...
- UVA1401 (字典树加简单dp)
#pragma GCC optimize(2) #include <bits/stdc++.h> #define ll long long using namespace std; ; ; ...
- http断点续传Range与Content-Range
今天用别人封装的libcurl库下载文件,发现下载下来的文件总是缺少头两个字节,用以下配置启用HTTP头信息打印后发现原来是设置了断点续传位置的原因 curl_easy_setopt(m_pCurl, ...
- RYU安装教程
一.使用pip的形式安装RYU 1.首先检查ubuntu中是否存在pip,命令为 sudo pip3 --version 2.如果存在则使用默认版本8.1.1就行不必跟新,否则自己下载一个pip 3. ...
- 云服务器 使用 onedrive 快速同步
重大更新:支持微软的onedrive网盘,可以自动实时双向同步数据,也可以多台服务器和网盘之间实时同步数据.新增了一个虚拟环境python367,支持pytorch1.2:-----------微软O ...
- 小I选宾馆
小 I 选宾馆 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 小 I 去天津玩啦,一路上,他跟他的同学发生了许多有趣的 ...
- [SDOI2006] 仓库管理员的烦恼 - 二分图最大权匹配
最小化代价,即最大化"本土"货物的数量 于是就是个二分图最大权匹配裸题 #include <bits/stdc++.h> using namespace std; #d ...
- No module named 'flask.ext'
在学习flask进行web开发的时候,遇到如下报错信息: No module named 'flask.ext' 原因:新版的flask不再支持flask.ext,所以,需要换种方式导入相应第三方库 ...
- mysql远程链接(可以在服务器上配置然后在本地连接远程服务器)
ps:如果一下的连接不成功原因:一定要关闭windows防火墙或者linux的防火墙 1.在服务器端授权(黄色标记的地方第一个是用户名,第二个的意思是可以远程连接,第三个是密码) GRANT ALL ...
- 将用户名密码邮箱制成表格,以用户名为q结束
print("输入用户名.密码.邮箱长度不能超过20个") s="" while True: v = input("用户名:") if v= ...