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^ ...
随机推荐
- gulp常用插件之gulp-replace使用
更多gulp常用插件使用请访问:gulp常用插件汇总 gulp-replace这是一款gulp3的字符串替换插件. 更多使用文档请点击访问gulp-replace工具官网. 安装 一键安装不多解释 n ...
- sql注入常见绕过技巧
参考链接:https://blog.csdn.net/huanghelouzi/article/details/82995313 https://www.cnblogs.com/vincy99/p/9 ...
- ansible-jinjia2模板
1. 含义 是基于python的模板引擎,包含变量和表达式两部分,这两者在模板求值的时候会被替换为值: 模板中还有标签,控制模板的逻辑 2. 基础语法 - 模板的表达式都包含在分隔符"{{ ...
- ovs安装教程
原文链接:https://www.cnblogs.com/goldsunshine/p/10331606.html Open vSwitch系列之二 安装指定版本ovs Open vSwitch系 ...
- oracle Insert 一次插入多条记录
oracle Insert 一次插入多条记录有两种方法: 1)Insert All Into table_name values ... insert all into table_name valu ...
- php如何获取单选复选和选择框的值
1.很久没有写基础的东西了复习一下(往往简单的东西才复杂) <body> 选择语句 <form action="demo.php" method="po ...
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- mybatis一级缓存和二级缓存(二)
注意事项与示例配置 一级缓存 Mybatis对缓存提供支持,但是在没有配置的默认情况下,它只开启一级缓存,一级缓存只是相对于同一个SqlSession而言.所以在参数和SQL完全一样的情况下,我们使用 ...
- Spring boot unable to determine jdbc url from datasouce
1. 首先删除 @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) 2. 在配置文件里添加完整的dataso ...
- 【转】Java(多)线程中注入Spring的Bean
问题说明 今天在web应用中用到了Java多线程的技术来并发处理一些业务,但在执行时一直会报NullPointerException的错误,问题定位了一下发现是线程中的Spring bean没有被注入 ...