C. Ehab and a 2-operation task
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You're given an array aa of length nn. You can perform the following operations on it:
- choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (0≤x≤106)(0≤x≤106), and replace ajaj with aj+xaj+x for all (1≤j≤i)(1≤j≤i), which means add xx to all the elements in the prefix ending at ii.
- choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (1≤x≤106)(1≤x≤106), and replace ajaj with aj%xaj%x for all (1≤j≤i)(1≤j≤i), which means replace every element in the prefix ending at ii with the remainder after dividing it by xx.
Can you make the array strictly increasing in no more than n+1n+1 operations?
Input
The first line contains an integer nn (1≤n≤2000)(1≤n≤2000), the number of elements in the array aa.
The second line contains nn space-separated integers a1a1, a2a2, ……, anan (0≤ai≤105)(0≤ai≤105), the elements of the array aa.
Output
On the first line, print the number of operations you wish to perform. On the next lines, you should print the operations.
To print an adding operation, use the format "11 ii xx"; to print a modding operation, use the format "22 ii xx". If ii or xx don't satisfy the limitations above, or you use more than n+1n+1 operations, you'll get wrong answer verdict.
Examples
input
Copy
3 1 2 3
output
Copy
0
input
Copy
3 7 6 3
output
Copy
2 1 1 1 2 2 4
Note
In the first sample, the array is already increasing so we don't need any operations.
In the second sample:
In the first step: the array becomes [8,6,3][8,6,3].
In the second step: the array becomes [0,2,3][0,2,3].
题意:
两个操作
1.前i个数均+x
2.前i个数均%x
要求不超过n+1次把n个数变成严格单调的
分析:
这道题过得不容易。
全部加上一个很大的数D,比原先数都大就行
每一次模一个数D+a[i]−i之后就能使得ai变成i,这里就要把它放到一个for循环里去了
那么前面已经弄好的数不会受到影响。
操作数刚好n+1
这一种思想,没想好在比赛wa十几次(上面是对的,只不过每想明白)
换了一种,我们先把都变成0 (a[i]%1)
然后都+2*n,现在都变成2*n
都让(2*n)%(2*n-1)==1
(2*n)%(2*n-2)==2
(2*n)%(2*n-3)==3
。。。。。。
#include<cstdio> #include<iostream> #include<fstream> #include<algorithm> #include<functional> #include<cstring> #include<string> #include<cstdlib> #include<iomanip> #include<numeric> #include<cctype> #include<cmath> #include<ctime> #include<queue> #include<stack> #include<list> #include<set> #include<map> using namespace std; #define N 100000+5 #define rep(i,n) for(int i=0;i<n;i++) #define sd(n) scanf("%d",&n) #define sll(n) scanf("%lld",&n) #define pd(n) scanf("%d\n",n) #define pll(n) scanf("%lld\n",n) #define MAX 26 typedef long long ll; const ll mod=1e6; ll n,m; ll a[N]; ll b[N]; int main() { //string s; //cin>>s; ll ans=0; //ll sum=0; ll x,y,d; scanf("%lld",&n); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); } printf("%lld\n",n+1); printf("2 %lld 1\n",n); printf("1 %lld %lld\n",n,2*n); ll sum=2*n; for(int i=1;i<n;i++) { printf("2 %d %lld\n",i,sum--); } /*for(int i=0;i<n;i++) { scanf("%lld%lld",&a[i],&b[i]); } */ //for(int i=1;i<=n;i++) // printf("%lld",a[i]); return 0; }#include<cstdio> #include<iostream> #include<fstream> #include<algorithm> #include<functional> #include<cstring> #include<string> #include<cstdlib> #include<iomanip> #include<numeric> #include<cctype> #include<cmath> #include<ctime> #include<queue> #include<stack> #include<list> #include<set> #include<map> using namespace std; #define N 100000+5 #define rep(i,n) for(int i=0;i<n;i++) #define sd(n) scanf("%d",&n) #define sll(n) scanf("%lld",&n) #define pd(n) scanf("%d\n",n) #define pll(n) scanf("%lld\n",n) #define MAX 26 typedef long long ll; int d = (int)5e5; int n; int main() { while (scanf("%d", &n) != EOF) { printf("%d\n", n + 1); printf("1 %d %d\n", n, d); for (int i = 1, x; i <= n; ++i) { scanf("%d", &x); printf("2 %d %d\n", i, (x + d - i)); } } return 0; }