QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227283#7108. Couleurucup-team992AC ✓2677ms35628kbC++176.4kb2023-10-27 09:30:332023-10-27 09:30:34

Judging History

你现在查看的是最新测评结果

  • [2023-10-27 09:30:34]
  • 评测
  • 测评结果:AC
  • 用时:2677ms
  • 内存:35628kb
  • [2023-10-27 09:30:33]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long
typedef int uci;
#define int long long
#define F first
#define S second
typedef complex<double> cd;

seed_seq seq{
    (uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
    (uint64_t) __builtin_ia32_rdtsc(),
    (uint64_t) (uintptr_t) make_unique<char>().get()
};
mt19937 rng(seq);
// mt19937_64 lrng(seq);

struct debugger{
    template <typename T>
    debugger& operator<<(T &a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
    template <typename T>
    debugger& operator<<(T &&a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
} deb;

const double PI = acos(-1.0);
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

//! function insert

//THINK FIRST, CODE SECOND
//DON'T GET STUCK ON ONE STRATEGY
//CALM DOWNNN FOR ONCE IN YOUR LIFE
//REDUCE
//COUGH E??!?!?!! O.O
//uwu i see you ryan

void build(int v, int l, int r, vector<int> &a, vector<vector<int>> &seg){
    if(l > r)
        return;
    int mid = l + (r-l)/2;
    if(l != r){
        build(v*2, l, mid, a, seg);
        build(v*2+1, mid+1, r, a, seg);
    }
    seg[v] = vector<int>(r-l+1);
    int ind = l, ind2 = mid+1;
    int p{};
    while(ind <= mid && ind2 <= r){
        if(a[ind] < a[ind2])
            seg[v][p++] = a[ind++];
        else
            seg[v][p++] = a[ind2++];
    }

    while(ind <= mid)
        seg[v][p++] = a[ind++];
    while(ind2 <= r)
        seg[v][p++] = a[ind2++];
    for(int i{}; i < seg[v].size(); ++i)
        a[l+i] = seg[v][i];
}

int lt(int v, int val, int l, int r, int lq, int rq, vector<vector<int>> &seg){
    if(l > r || lq > r || rq < l)
        return 0;
    else if(lq <= l && r <= rq){
        auto it = lower_bound(seg[v].begin(), seg[v].end(), val);
        return it - seg[v].begin();
    }else{
        int mid = l + (r-l)/2;
        return lt(v*2, val, l, mid, lq, rq, seg) + lt(v*2+1, val, mid+1, r, lq, rq, seg);
    }
}

int gt(int v, int val, int l, int r, int lq, int rq, vector<vector<int>> &seg){
    if(l > r || lq > r || rq < l)
        return 0;
    else if(lq <= l && r <= rq){
        auto it = upper_bound(seg[v].begin(), seg[v].end(), val);
        return seg[v].end() - it;
    }else{
        int mid = l + (r-l)/2;
        return gt(v*2, val, l, mid, lq, rq, seg) + gt(v*2+1, val, mid+1, r, lq, rq, seg);
    }
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i{}; i < n; ++i)
        cin >> a[i];
    vector<int> q(n);
    for(int i{}; i < n; ++i)
        cin >> q[i];

    vector<int> b = a;
    vector<vector<int>> seg(4*n);
    build(1, 0, n-1, b, seg);
    
    int tot{};
    for(int i{1}; i < n; ++i){
        int diff = gt(1, a[i], 0, n-1, 0, i-1, seg);
        tot += diff;
    }

    set<ar<int, 3>> ints;
    ints.insert({0, n-1, tot});
    multiset<int> vals;
    vals.insert(tot);
    for(int i{}; i < n; ++i){
        cout << (*vals.rbegin()) << ' ';
        int ind = (*vals.rbegin())^q[i];
        ind--;
        //cerr <<(*vals.rbegin()) << ' ' <<  ind << '\n';
        auto it = ints.upper_bound({ind, n, 0});
        it--;

        ar<int, 3> val = *it;
        ints.erase(it);
        vals.erase(vals.find(val[2]));
        int indcontr = gt(1, a[ind], 0, n-1, val[0], ind-1, seg) + lt(1, a[ind], 0, n-1, ind+1, val[1], seg);
        //cerr << val[0] << ' ' << val[1] << ' ' << val[2] << '\n';
        if(ind - val[0] < val[1]-ind){
            int insidehere{};
            int across{};
            if(ind != val[0])
                across += lt(1, a[val[0]], 0, n-1, ind+1, val[1], seg);
            for(int j = val[0]+1; j < ind; ++j){
                insidehere += gt(1, a[j], 0, n-1, val[0], j-1, seg);
                across += lt(1, a[j], 0, n-1, ind+1, val[1], seg);
            }
            int insideother = val[2] - indcontr-insidehere-across;
            //cerr << indcontr << ' ' << insidehere << ' ' << across << ' ' << insideother << '\n';
            if(val[0] <= ind-1){
                vals.insert(insidehere);
                ints.insert({val[0], ind-1, insidehere});
            }
            if(val[1] >= ind+1){
                vals.insert(insideother);
                ints.insert({ind+1, val[1], insideother});
            }
        }else{
            int insidehere{};
            int across{};
            int insideother{};
            if(ind != val[1])
                across += gt(1, a[ind+1], 0, n-1, val[0], ind-1, seg);
            for(int j = ind+2; j <= val[1]; ++j){
                insideother += gt(1, a[j], 0, n-1, ind+1, j-1, seg);
                across += gt(1, a[j], 0, n-1, val[0], ind-1, seg);
            }
            insidehere = val[2] - indcontr-insideother-across;
            if(val[0] <= ind-1){
                vals.insert(insidehere);
                ints.insert({val[0], ind-1, insidehere});
            }
            if(val[1] >= ind+1){
                vals.insert(insideother);
                ints.insert({ind+1, val[1], insideother});
            }
        }
        //cerr << "end\n";
    }
    cout << '\n';
}

uci main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

/*
    random number generator stuff
    num = rng(); gives integer number
    num = uniform_int_distribution<int>(a, b)(rng); -> bounds [a, b]
    num = uniform_real_distribution<double>(a, b)(rng); -> bounds [a, b)
    can also instantiate distributions and call on generator:
    uniform_int_distribution<int> thing(a, b);
    num = thing(rng);
*/
// struct custom_hash {
//     static uint64_t splitmix64(uint64_t x) {
//         // http://xorshift.di.unimi.it/splitmix64.c
//         x += 0x9e3779b97f4a7c15;
//         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//         return x ^ (x >> 31);
//     }
//     size_t operator()(uint64_t x) const {
//         static const uint64_t FIXED_RANDOM = lrng();
//         return splitmix64(x + FIXED_RANDOM);
//     }
// };

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

input:

3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10

output:

7 0 0 0 0 
20 11 7 2 0 0 0 0 0 0 
42 31 21 14 14 4 1 1 1 0 0 0 0 0 0 

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 2677ms
memory: 35628kb

input:

11116
10
10 5 10 3 6 4 8 5 9 8
31 27 24 11 12 3 0 2 3 1
10
8 2 7 2 8 10 1 10 9 10
6 5 2 13 2 1 0 1 3 1
10
7 10 7 6 1 3 10 6 7 9
21 18 10 1 6 5 4 8 9 10
10
2 10 4 8 8 5 7 2 6 7
20 10 9 1 15 0 4 2 9 7
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10
1 2 3 4 5 6 7 8 9 10
6 3 5 2 7 10 9 1 4 8
10
1 10 1 3...

output:

21 18 16 12 10 6 4 1 1 0 
12 12 10 10 4 4 4 2 1 0 
20 16 9 5 3 3 3 0 0 0 
22 14 8 8 5 5 2 1 1 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
19 12 7 4 4 2 2 1 0 0 
20 18 8 3 1 1 0 0 0 0 
45 21 21 10 3 3 3 0 0 0 
17 11 8 2 1 1 1 0 0 0 
13 4 1 0 0 0 0 0 0 0 
29 27 22 15 9 7 4 3 1 0 
26 16 9 2 1 1 1 1 1 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed