#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;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
3 ms |
588 KB |
Output is correct |
5 |
Correct |
4 ms |
592 KB |
Output is correct |
6 |
Correct |
4 ms |
592 KB |
Output is correct |
7 |
Correct |
4 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
592 KB |
Output is correct |
9 |
Correct |
4 ms |
720 KB |
Output is correct |
10 |
Correct |
4 ms |
592 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
976 KB |
Output is correct |
13 |
Correct |
7 ms |
848 KB |
Output is correct |
14 |
Correct |
7 ms |
976 KB |
Output is correct |
15 |
Correct |
7 ms |
976 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 |
3 ms |
588 KB |
Output is correct |
5 |
Correct |
4 ms |
592 KB |
Output is correct |
6 |
Correct |
4 ms |
592 KB |
Output is correct |
7 |
Correct |
4 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
592 KB |
Output is correct |
9 |
Correct |
4 ms |
720 KB |
Output is correct |
10 |
Correct |
4 ms |
592 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
976 KB |
Output is correct |
13 |
Correct |
7 ms |
848 KB |
Output is correct |
14 |
Correct |
7 ms |
976 KB |
Output is correct |
15 |
Correct |
7 ms |
976 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
4 ms |
592 KB |
Output is correct |
18 |
Correct |
7 ms |
848 KB |
Output is correct |
19 |
Correct |
6 ms |
848 KB |
Output is correct |
20 |
Correct |
6 ms |
848 KB |
Output is correct |
21 |
Correct |
6 ms |
848 KB |
Output is correct |
22 |
Correct |
6 ms |
848 KB |
Output is correct |
23 |
Correct |
7 ms |
848 KB |
Output is correct |
24 |
Correct |
6 ms |
848 KB |
Output is correct |
25 |
Correct |
6 ms |
848 KB |
Output is correct |
26 |
Incorrect |
13 ms |
1244 KB |
Integer 59568 violates the range [0, 40000] |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
7 ms |
896 KB |
Output is correct |
6 |
Correct |
7 ms |
984 KB |
Output is correct |
7 |
Correct |
7 ms |
856 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
6 ms |
876 KB |
Output is correct |
10 |
Correct |
7 ms |
848 KB |
Output is correct |
11 |
Correct |
6 ms |
848 KB |
Output is correct |
12 |
Correct |
7 ms |
840 KB |
Output is correct |
13 |
Correct |
7 ms |
848 KB |
Output is correct |
14 |
Correct |
7 ms |
884 KB |
Output is correct |
15 |
Correct |
9 ms |
976 KB |
Output is correct |