#include <bits/stdc++.h>
using namespace std;
int n,s,v[100005];
bool get_bit(int val, int b)
{
return ((val&(1<<b))!=0);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>s;
for(int i=1; i<=n; i++)
{
cin>>v[i];
}
/* if(s==1)
{
vector<pair<int,int>> rez;
for(int i=1; i<=n; i++)
{
int poz = i;
while(poz>1 && v[poz]<v[poz-1])
{
rez.push_back({poz,poz-1});
v[poz]^=v[poz-1];
rez.push_back({poz-1,poz});
v[poz-1]^=v[poz];
rez.push_back({poz,poz-1});
v[poz]^=v[poz-1];
--poz;
}
}
cout<<rez.size()<<'\n';
for(auto it : rez)
{
cout<<it.first<<' '<<it.second<<'\n';
}
return 0;
}
*/
vector<pair<int,int>> rez;
for(int b=0; b<20; b++)
{
for(int i=2; i<=n; i++)
{
if(get_bit(v[i-1],b)==0)
{
continue;
}
if(get_bit(v[i],b)==1 && get_bit(v[i-1],b)==1)
{
rez.push_back({i-1,i});
v[i-1]^=v[i];
continue;
}
if(get_bit(v[i],b)==0 && get_bit(v[i-1],b)==1)
{
rez.push_back({i,i-1});
v[i]^=v[i-1];
rez.push_back({i-1,i});
v[i-1]^=v[i];
}
}
}
cout<<rez.size()<<'\n';
for(auto it : rez)
{
cout<<it.first<<' '<<it.second<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Not sorted |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Not sorted |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
6 ms |
848 KB |
Output is correct |
6 |
Correct |
6 ms |
848 KB |
Output is correct |
7 |
Correct |
6 ms |
848 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
6 ms |
824 KB |
Output is correct |
10 |
Correct |
8 ms |
876 KB |
Output is correct |
11 |
Correct |
6 ms |
836 KB |
Output is correct |
12 |
Correct |
7 ms |
848 KB |
Output is correct |
13 |
Correct |
7 ms |
944 KB |
Output is correct |
14 |
Correct |
6 ms |
848 KB |
Output is correct |
15 |
Correct |
8 ms |
1080 KB |
Output is correct |