Submission #1216353

#TimeUsernameProblemLanguageResultExecution timeMemory
1216353tapilyocaThe Collection Game (BOI21_swaps)C++20
100 / 100
2 ms424 KiB
#include "swaps.h"
#include<bits/stdc++.h>
using namespace std;

template<typename T>
using vec = vector<T>;
using ll = long long;
using vll = vec<ll>;
using pll = pair<ll,ll>;
#define pb push_back
#define dbg(x) if(1) cerr << #x << ": " << x << endl

int n;
vector<pair<int,int>> grub;
vector<int> loc;
vector<int> personAt;

void sched(int a, int b) {
    if(a >= n or b >= n) return;
    grub.pb({personAt[a],personAt[b]});
    schedule(personAt[a]+1,personAt[b]+1);
}

void veset() {
    vector<int> x = visit();

    for(int i = 0; i < x.size(); i++) {
        if(x[i] == 0) { // i < j
            // swap
            ll a = grub[i].first;
            ll b = grub[i].second;
            swap(personAt[loc[a]], personAt[loc[b]]);
            swap(loc[a],loc[b]);
        }
    }

    grub = vector<pair<int,int>>();
}

void solve(int N, int V) {
    n = N;
    loc.resize(N);
    personAt.resize(N);
    iota(loc.begin(),loc.end(),0);
    iota(personAt.begin(),personAt.end(),0);

    int nPow = ceil(log2(N));
    int nPad = 1<<nPow;

    for(int i = 1; i <= nPow; i++) {
        // dbg(i);
        int blkSize = (1<<i);
        // query(1, n-k+1) for all the blocks
        
        for(int j = 0; j < N; j += blkSize) {
            for(int k = 0; k < blkSize/2; k++) {
                // dbg(j);
                // dbg(k);
                sched(j+k, j+blkSize-k-1);
            }
        }

        veset();

        if(i > 1) {
            for(int j = blkSize / 2; j >= 1; j >>= 1) { // block size
                bool flag = 0;
                for(int k = 0; k < n; k += j) { // for each block
                    for(int l = 0; l < j/2; l++) {  // the thing
                        // cerr << j << " " << k << " " << l << endl;
                        flag = 1;
                        sched(k+l, k+l+j/2);
                    }
                }
                if(flag) veset();
            }
        }


    }

    vec<int> ans(N);
    for(int i = 0; i < N; i++) {
        ans[i] = personAt[i]+1;
    }
    answer(ans);
}

/*

8 100
7 2 3 1 4 8 6 5

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...