Submission #775798

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
7757982023-07-07 02:23:39vjudge1Xor Sort (eJOI20_xorsort)C++17
100 / 100
5 ms1040 KiB
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> tt;
int a[1001], re[1001];
void op(int i, int j)
{
tt.push_back(make_pair(i, j));
a[i] ^= a[j];
}
bool getbit(int num, int bit)
{
return (num >> bit)&1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, s;
cin>>n>>s;
for(int i = 1; i <= n; i++) cin>>a[i];
if(s == 2){
int last = n;
for(int bit = 19; bit >= 0; bit--){
int c = 0;
for(int i = 1; i <= last; i++) if(getbit(a[i], bit) == 1) c = i;
if(c == 0) continue;
for(int i = c-1; i >= 1; i--) if(getbit(a[i], bit) == 0) op(i, i+1);
for(int i = c+1; i <= last; i++) if(getbit(a[i], bit) == 0) op(i, i-1);
for(int i = 2; i <= last; i++) op(i-1, i);
last--;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compilation message (stderr)

xorsort.cpp: In function 'int main()':
xorsort.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int i = 0; i < tt.size(); i++) cout<<tt[i].first<<" "<<tt[i].second<<'\n';
      |                    ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...