QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328230#4936. Shopping ChangesAnthonyQwOCompile Error//C++232.6kb2024-02-15 18:27:282024-02-15 18:27:29

Judging History

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

  • [2024-02-15 18:27:29]
  • 评测
  • [2024-02-15 18:27:28]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define int long long
#define lowbit(x) (x&-x)
using namespace std;

const int MAXN = 3e5 + 5;

struct BIT {
    int n;
    vector<int> bit;
    BIT(int _n):n(_n), bit(n+1) {}
    void update( int x, int val ) {
        if(x <= 0) return;
        for(;x <= n; x += lowbit(x)) bit[x] += val;
    }
    void range_update( int L, int R, int val ) {
        update(L,val), update(R+1,-val);        
    }
    int query( int x ) {
        int res = 0;
        for(;x; x -= lowbit(x)) res += bit[x];
        return res;
    }
    int range_query( int L, int R ) {
        return query(R)-query(L-1);
    }
};

int f(int l, int r, vector<int>& arr) {
    if( r-l <= 1 ) return 0;
    int m = (l+r)>>1, ret = f(l,m,arr) + f(m,r,arr);
    for(int i = l, j = m; i < m; i++) {
        while(j < r && arr[i] > arr[j]) j++;
        ret += j-m;
    }
    sort(arr.begin()+l, arr.begin()+r);
    return ret;
}

int inv(vector<int>& arr) {
    int n = arr.size();
    return f(0, n, arr);
}

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m, k, INV = 0;
    cin >> n >> m;
    vector<int> arr(n), val;
    vector<vector<int>> aarr;
    BIT bit(MAXN);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
        val.push_back(arr[i]);
    }
    INV = inv(arr);
    for(int i = 0; i < m; i++) {
        cin >> k;
        vector<int> tmp(k);
        for(int j = 0; j < k; j++) {
            cin >> tmp[j];
            val.push_back(tmp[j]);
        }
        aarr.push_back(tmp);
    }
    sort(val.begin(), val.end());
    val.resize(unique(val.begin(), val.end())-val.begin());
    for(int i = 0; i < n; i++) {
        int x = lower_bound(val.begin(), val.end(), arr[i]) - val.begin() + 1;
        bit.update(x, 1);
    }
    for(int i = 0; i < m; i++) {
        int k = aarr[i].size(), s = 0, ret = 0;
        vector<int> f(k), b(k);
        for(int j = 0; j < k; j++) {
            int x = lower_bound(val.begin(), val.end(), aarr[i][j] ) - val.begin() + 1;
            f[j] = bit.query(x-1), b[j] = bit.range_query(x+1, MAXN);
            s += b[j];
        }
        // cout << ret << '\n';
        // for(int i : f) cout << i << ' '; cout << '\n';
        // for(int i : b) cout << i << ' '; cout << '\n'; 
        ret += s;
        for(int j = 0; j < k; j++) {
            ret = min(ret, s);
            s = s + f[j] - b[j];
        }
        ret = min(ret, s);
        cout << ret + inv(aarr[i]) + INV << '\n';
    }
}

详细

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:3:
/usr/include/c++/13/bits/allocator.h: In destructor ‘constexpr std::_Vector_base<long long int, std::allocator<long long int> >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘constexpr std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = long long int]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~