Submission #1060676

# Submission time Handle Problem Language Result Execution time Memory
1060676 2024-08-15T20:37:13 Z LilPluton Xor Sort (eJOI20_xorsort) C++14
25 / 100
7 ms 1788 KB
#include <bits/stdc++.h>
/// author: LilPluton auuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
using namespace std;
#define ll long long
#define ld long double
#define ar array
#define int ll
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define endll   '\n'
#define lb(a, x)    lower_bound(all(a), x) - a.begin();

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
     
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
struct BIT
{
    long long n;
    vector<long long> ft;
    BIT(long long N)
    {
        n = N;
        ft.assign(n + 5, 0);
    }
    void upd(long long pos, long long val)
    {
        while(pos <= n)
        {
            ft[pos] += val;
            pos += (pos & (-pos));
        }
        
    }
    long long sum(long long l, long long r)
    {
        if(l != 1)  return sum(1, r) - sum(1, l - 1);
        long long res = 0;
        while(r >= 1)
        {
            res +=  ft[r];
            r += (r | (-r));
        }
        return res;
    }
};
struct DSU
{
    vector<int>par, size;
    int n;
    DSU(int N)
    {
        n = N + 5;
        par.resize(n + 1, 0);
        size.assign(n + 1, 1);
        for(int i = 0; i <= n; ++i)
            par[i] = i;
    }
    int _find(int v)
    {
        if(par[v] == v)
            return v;
        return par[v] = _find(par[v]);
    }
    bool unite(int a, int b)
    {
        a = _find(a);
        b = _find(b);
        if(a != b)
        {
            if(size[a] < size[b])
                swap(a, b);
            size[a] += size[b];
            par[b] = a;
            return 1;
        }
        return 0;
    }
};
const long long INF = 1e18;
const int N = 3e5 + 5;
const int MAXM = 1e5 + 5;
const int modulo = 1000000007;


void solve(int test_case) { 
    int n, s;
    cin >> n >> s;
    vector<int>a(n);
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    vector<pair<int,int>> v;
    if(s == 1)
    {
        for(int i = 1; i <= n; ++i)
        {
            for(int j = n - 1; i <= j; --j)
            {
                if(a[j + 1] < a[j])
                {
                    v.push_back({j, j + 1});
                    v.push_back({j + 1, j});
                    v.push_back({j, j + 1});
                    swap(a[j], a[j+1]);
                }
            }
        }
        cout << v.size() << endll;
        for(auto i : v)
            cout << i.first << ' ' << i.second << endll;
    }
    else
    {
        for(int i = 1; i <= n; ++i)
        {
            for(int j = n - 1; i <= j; --j)
            {
                if(a[j + 1] < a[j])
                {
                    v.push_back({j, j + 1});
                    v.push_back({j + 1, j});
                    v.push_back({j, j + 1});
                    swap(a[j], a[j + 1]);
                }
            }
        }
        cout << v.size() << endll;
        for(auto i : v)
            cout << i.first << ' ' << i.second << endll;
    }
}





main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    for(int i = 1; i <= t; ++i)
        solve(i);
    return 0;
}

Compilation message

xorsort.cpp:148:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  148 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 736 KB Output is correct
5 Correct 2 ms 992 KB Output is correct
6 Correct 2 ms 992 KB Output is correct
7 Correct 2 ms 992 KB Output is correct
8 Correct 2 ms 992 KB Output is correct
9 Correct 2 ms 992 KB Output is correct
10 Correct 3 ms 988 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 4 ms 1500 KB Output is correct
13 Correct 6 ms 1496 KB Output is correct
14 Correct 4 ms 1500 KB Output is correct
15 Correct 5 ms 1496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 736 KB Output is correct
5 Correct 2 ms 992 KB Output is correct
6 Correct 2 ms 992 KB Output is correct
7 Correct 2 ms 992 KB Output is correct
8 Correct 2 ms 992 KB Output is correct
9 Correct 2 ms 992 KB Output is correct
10 Correct 3 ms 988 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 4 ms 1500 KB Output is correct
13 Correct 6 ms 1496 KB Output is correct
14 Correct 4 ms 1500 KB Output is correct
15 Correct 5 ms 1496 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 992 KB Output is correct
18 Correct 3 ms 1244 KB Output is correct
19 Correct 4 ms 1244 KB Output is correct
20 Correct 3 ms 1244 KB Output is correct
21 Correct 4 ms 1244 KB Output is correct
22 Correct 4 ms 1104 KB Output is correct
23 Correct 4 ms 1240 KB Output is correct
24 Correct 4 ms 1244 KB Output is correct
25 Correct 5 ms 1244 KB Output is correct
26 Incorrect 7 ms 1788 KB Integer 59568 violates the range [0, 40000]
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 608 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -