QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#208489#4936. Shopping ChangesBeevo#TL 0ms3688kbC++231.7kb2023-10-09 17:48:172023-10-09 17:48:17

Judging History

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

  • [2023-10-09 17:48:17]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3688kb
  • [2023-10-09 17:48:17]
  • 提交

answer

#include <bits/stdc++.h>

#define el '\n'
#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef long double ld;

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll INF = 1e18;
const int N = 2e5 + 5;

int n, l, c[N], w[N];
ordered_multiset<int> st;

ll solve(int m) {
    st.clear();

    ll cnt = 0;

    for (int i = 0; i < m; i++)
        cnt += st.size() - st.order_of_key(w[i] + 1), st.insert(w[i]);

    for (int i = 0; i < n; i++)
        cnt += st.size() - st.order_of_key(c[i] + 1), st.insert(c[i]);

    for (int i = m; i < l; i++)
        cnt += st.size() - st.order_of_key(w[i] + 1), st.insert(w[i]);

    return cnt;
}

void testCase() {
    int m;
    cin >> n >> m;

    for (int i = 0; i < n; i++)
        cin >> c[i];

    int s, e, m1, m2;
    ll sol, sol1, sol2;
    for (int i = 0; i < m; i++) {
        cin >> l;

        for (int j = 0; j < l; j++)
            cin >> w[j];

        s = 0, e = l, sol = INF;
        while (s <= e) {
            m1 = s + (e - s) / 3;
            m2 = e - (e - s) / 3;

            sol1 = solve(m1), sol2 = solve(m2);

            sol = min({sol, sol1, sol2});

            if (sol1 < sol2)
                e = m2 - 1;
            else
                s = m1 + 1;
        }

        cout << sol << el;
    }
}

signed main() {
    Beevo

    int t = 1;
//    cin >> t;

    while (t--)
        testCase();
}

詳細信息

Test #1:

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

input:

3 3
5 6 7
6 2 3 4 8 9 10
2 100 99
3 5 6 7

output:

0
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3688kb

input:

3 2
7 6 5
6 2 3 4 8 9 10
6 10 9 8 4 3 2

output:

3
27

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3688kb

input:

1 1
589284012
1 767928734

output:

0

result:

ok single line: '0'

Test #4:

score: -100
Time Limit Exceeded

input:

10000 9999
298772847 712804102 869795012 527998188 804246450 598105371 843966934 639805471 937482040 887551242 254734680 188704975 17408126 626523673 553956319 697723205 231690822 637079761 232393146 377026277 962223856 338922458 912529500 710873344 942955137 51167037 195729799 529674367 990599310 4...

output:


result: