This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
const int nmax = 1e6 + 5, N = 1e5;
const ll oo = 1e9;
const int lg = 31, M = 2, mod = 1e6;
#define pii pair<ll, ll>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
#define endl "\n"
#define task "code"
using namespace std;
int n, k;
int a[nmax], c[nmax];
vector<pii> ans;
void add(int id, int i){
ans.push_back({id, i});
if(ans.size() > 1e4) cout << -1, exit(0);
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen(task".inp", "r", stdin);
// freopen(task".out", "w", stdout);
cin >> n >> k;
for(int i = 1; i <= n; ++i) cin >> a[i];
while(1){
bool ok = 1;
for(int i = 1; i <= n; ++i) ok &= (a[i] == 0);
if(ok) break;
for(int i = 2; i <= n; ++i){
while(a[i] < a[i -1]){
add(1, i);
a[i] += k;
}
}
for(int i = 1; i <= n; ++i) c[i] = a[i];
for(int i = 0; i <= a[n]; ++i){
int pos = upper_bound(a + 1, a + 1 + n, i) - a - 1;
while(pos >= k){
for(int j = pos - k + 1; j <= pos; ++j) c[j]++;
add(2, pos - k + 1);
pos -= k;
}
}
for(int i = 1; i < k; ++i){
while(c[i] < c[n]){
c[i] += k;
add(1, i);
}
}
int mi = oo;
for(int i = 1; i <= n; ++i){
mi = min(mi, c[i]);
}
for(int i = 1; i <= n; ++i) a[i] = c[i] - mi;
}
cout << ans.size() << endl;
for(auto [id, i] : ans) cout <<id << ' ' << i << endl;
}
/*
4 2
1 0 1 2
*/
Compilation message (stderr)
joiris.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |