Submission #465966

# Submission time Handle Problem Language Result Execution time Memory
465966 2021-08-17T12:54:22 Z Sench2006 Xor Sort (eJOI20_xorsort) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define lb lower_bound
#define ub upper_bound

#define FOR(i, a, b) for(auto i = a; i < b; i++)
#define FORD(i, a, b) for(auto i = a - 1; i >= b; i--)
#define trav(x, v) for(auto x : v)

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

// ---------------------------------------- Solution ---------------------------------------- //

const int N = 1005;
int s, n;
int a[N];

void solve1() {
    vector <pair<int, int>> ans;
    vector <pair<int, int>> in;
    FOR(i, 1, n + 1) {
        in.push_back({a[i], i});
    }
    sort(rall(in));
    FOR(j, 0, in.size()) {
        int cur = in[j][1];
        FOR(i, p, n - 1) {
            a[i + 1] ^= a[i];
            ans.push_back({i + 1, i});
        }
        FORD(i, p, 0) {
            a[i] ^= a[i + 1];
            ans.push_back({i, i + 1});
        }
        FOR(i, j + 1, in.size()) {
            if (in[i][1] > cur) in[i][1]--;
        }
    }
    cout << ans.size() << endl;
    FOR(i, 0, ans.size()) {
       cout << ans[i].first << " " << ans[i].second << endl;
    }
}

void solve2() {
    vector <pair<int, int>> ans;
    for(int i = 1; i <= (1 << 20); i *= 2) {
        FOR(j, 1, n) {
            if((i&a[j])) {
                if(!(i&a[j + 1])) {
                    ans.push_back({j + 1,j});
                    a[j + 1] ^= a[j];
                }
                ans.push_back({j, j + 1});
                a[j] ^= a[j + 1];
            }
        }
    }
    cout << ans.size() << endl;
    FOR(i, 0, ans.size()) {
       cout << ans[i].first << " " << ans[i].second << endl;
    }
}

void solve() {
    cin >> n >> s;
    FOR(i, 1, n + 1) {
        cin >> a[i];
    }
    if (s == 1) solve1();
    else solve2();
}

int main() {
    fastio;
    
    int tests = 1;
    // cin >> tests;
    while (tests--) {
        solve();
    }

    return 0;
}

Compilation message

xorsort.cpp: In function 'void solve1()':
xorsort.cpp:12:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define FOR(i, a, b) for(auto i = a; i < b; i++)
......
   31 |     FOR(j, 0, in.size()) {
      |         ~~~~~~~~~~~~~~~                 
xorsort.cpp:31:5: note: in expansion of macro 'FOR'
   31 |     FOR(j, 0, in.size()) {
      |     ^~~
xorsort.cpp:32:24: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   32 |         int cur = in[j][1];
      |                        ^
xorsort.cpp:33:16: error: 'p' was not declared in this scope
   33 |         FOR(i, p, n - 1) {
      |                ^
xorsort.cpp:12:35: note: in definition of macro 'FOR'
   12 | #define FOR(i, a, b) for(auto i = a; i < b; i++)
      |                                   ^
xorsort.cpp:35:37: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   35 |             ans.push_back({i + 1, i});
      |                                     ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from xorsort.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
xorsort.cpp:37:17: error: 'p' was not declared in this scope
   37 |         FORD(i, p, 0) {
      |                 ^
xorsort.cpp:13:36: note: in definition of macro 'FORD'
   13 | #define FORD(i, a, b) for(auto i = a - 1; i >= b; i--)
      |                                    ^
xorsort.cpp:39:37: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   39 |             ans.push_back({i, i + 1});
      |                                     ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from xorsort.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
xorsort.cpp:12:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define FOR(i, a, b) for(auto i = a; i < b; i++)
......
   41 |         FOR(i, j + 1, in.size()) {
      |             ~~~~~~~~~~~~~~~~~~~         
xorsort.cpp:41:9: note: in expansion of macro 'FOR'
   41 |         FOR(i, j + 1, in.size()) {
      |         ^~~
xorsort.cpp:42:22: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   42 |             if (in[i][1] > cur) in[i][1]--;
      |                      ^
xorsort.cpp:42:38: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   42 |             if (in[i][1] > cur) in[i][1]--;
      |                                      ^
xorsort.cpp:12:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define FOR(i, a, b) for(auto i = a; i < b; i++)
......
   46 |     FOR(i, 0, ans.size()) {
      |         ~~~~~~~~~~~~~~~~                
xorsort.cpp:46:5: note: in expansion of macro 'FOR'
   46 |     FOR(i, 0, ans.size()) {
      |     ^~~
xorsort.cpp: In function 'void solve2()':
xorsort.cpp:12:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define FOR(i, a, b) for(auto i = a; i < b; i++)
......
   66 |     FOR(i, 0, ans.size()) {
      |         ~~~~~~~~~~~~~~~~                
xorsort.cpp:66:5: note: in expansion of macro 'FOR'
   66 |     FOR(i, 0, ans.size()) {
      |     ^~~