#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(void){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,s;
cin>>n>>s;
ll arr[n];
f(i,0,n){
cin>>arr[i];
}
vector<ii>ans;
if(s == 1){
ll pre = 0;
f(j,0,n){
ll maxi = -1;
ll pos = 0;
f(i,0,n-j){
maxi = max(maxi,arr[i] ^ pre);
if(maxi == (arr[i] ^ pre)){
pos = i;
}
}
pre = maxi;
f(i,0,n-j-1){
ans.pb(ii(i+1,i+2));
arr[i] ^= arr[i+1];
}
f(i,pos,n-j-1){
ans.pb(ii(i+2,i+1));
arr[i+1] ^= arr[i];
}
for(ll i = pos-1;i >= 1;i--){
ans.pb(ii(i,i+1));
arr[i-1] ^= arr[i];
}
}
for(ll i = n-2;i >= 0;i--){
ans.pb(ii(i+1,i+2));
arr[i] ^= arr[i+1];
}
}
else{
for(ll j = 19;j >= 0;j--){
bool ivra = 0;
f(i,0,n){
if(arr[i] & (1LL<<j)){
ivra = 1;
}
else if(ivra){
ans.pb(ii(i+1,i));
arr[i] ^= arr[i-1];
}
}
f(i,0,n-1){
if(arr[i] & (1LL<<j)){
ans.pb(ii(i+1,i+2));
arr[i] ^= arr[i+1];
}
}
n -= ivra;
}
}
cout<<ans.size()<<"\n";
for(auto x:ans){
cout<<x.F<<" "<<x.S<<"\n";
}
}
/*
5 1
3 2 8 4 1
5 2
4 4 2 0 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
896 KB |
Output is correct |
5 |
Correct |
5 ms |
848 KB |
Output is correct |
6 |
Correct |
5 ms |
848 KB |
Output is correct |
7 |
Correct |
5 ms |
848 KB |
Output is correct |
8 |
Correct |
5 ms |
848 KB |
Output is correct |
9 |
Correct |
5 ms |
848 KB |
Output is correct |
10 |
Correct |
5 ms |
848 KB |
Output is correct |
11 |
Correct |
5 ms |
920 KB |
Output is correct |
12 |
Correct |
5 ms |
848 KB |
Output is correct |
13 |
Correct |
5 ms |
848 KB |
Output is correct |
14 |
Correct |
5 ms |
976 KB |
Output is correct |
15 |
Correct |
5 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
896 KB |
Output is correct |
5 |
Correct |
5 ms |
848 KB |
Output is correct |
6 |
Correct |
5 ms |
848 KB |
Output is correct |
7 |
Correct |
5 ms |
848 KB |
Output is correct |
8 |
Correct |
5 ms |
848 KB |
Output is correct |
9 |
Correct |
5 ms |
848 KB |
Output is correct |
10 |
Correct |
5 ms |
848 KB |
Output is correct |
11 |
Correct |
5 ms |
920 KB |
Output is correct |
12 |
Correct |
5 ms |
848 KB |
Output is correct |
13 |
Correct |
5 ms |
848 KB |
Output is correct |
14 |
Correct |
5 ms |
976 KB |
Output is correct |
15 |
Correct |
5 ms |
848 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
5 ms |
848 KB |
Output is correct |
18 |
Correct |
9 ms |
1484 KB |
Output is correct |
19 |
Correct |
8 ms |
1356 KB |
Output is correct |
20 |
Correct |
8 ms |
1356 KB |
Output is correct |
21 |
Correct |
8 ms |
1484 KB |
Output is correct |
22 |
Correct |
8 ms |
1484 KB |
Output is correct |
23 |
Correct |
8 ms |
1356 KB |
Output is correct |
24 |
Correct |
8 ms |
1356 KB |
Output is correct |
25 |
Correct |
9 ms |
1356 KB |
Output is correct |
26 |
Correct |
8 ms |
1484 KB |
Output is correct |
27 |
Correct |
8 ms |
1356 KB |
Output is correct |
28 |
Correct |
8 ms |
1356 KB |
Output is correct |
29 |
Correct |
8 ms |
1356 KB |
Output is correct |
30 |
Correct |
8 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
7 ms |
1100 KB |
Output is correct |
6 |
Correct |
8 ms |
1100 KB |
Output is correct |
7 |
Correct |
6 ms |
1100 KB |
Output is correct |
8 |
Correct |
6 ms |
1100 KB |
Output is correct |
9 |
Correct |
7 ms |
1100 KB |
Output is correct |
10 |
Correct |
7 ms |
1100 KB |
Output is correct |
11 |
Correct |
7 ms |
1128 KB |
Output is correct |
12 |
Correct |
7 ms |
1168 KB |
Output is correct |
13 |
Correct |
7 ms |
1100 KB |
Output is correct |
14 |
Correct |
7 ms |
1196 KB |
Output is correct |
15 |
Correct |
8 ms |
1484 KB |
Output is correct |