QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#796772#5466. Permutation CompressionyyksamWA 0ms3880kbC++204.2kb2024-12-02 02:41:462024-12-02 02:41:46

Judging History

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

  • [2024-12-02 02:41:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3880kb
  • [2024-12-02 02:41:46]
  • 提交

answer

#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5 + 10;
const int inf = 0x3f3f3f3f;

int lowbit(int x) {
    return (x & (-x));
}

struct tree_array {
    int n;
    vector<ll> t1, t2;

    tree_array(int n) {
        this->n = n;
        t1.resize(n + 10);
        t2.resize(n + 10);
    }

    void insert(int l, int r, ll x) {
        update(l, x);
        update(r + 1, -x);
    }

    void update(int idx, ll x) {
        for (int i = idx; i <= n; i += lowbit(i)) {
            t1[i] += x;
            t2[i] += (ll)idx * x;
        }
    }

    ll getsum(int idx) {
        ll res = 0;
        for (int i = idx; i; i -= lowbit(i)) {
            res += ((ll)idx + 1) * t1[i] - t2[i];
        }
        return res;
    }
};

int stk[N], top, ix[N];
tree<pair<int, int>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> treap;

void work() {
    int n, m, k, cnt = 0;
    cin >> n >> m >> k;
    treap.clear();
    tree_array le(n), ri(n);
    vector<int> a(n + 10), b(m + 10), c(k + 10);
    vector<int> left(n + 10), right(n + 10);
    vector<int> cntl(n + 10), cntr(n + 10);
    vector<bool> isc(n + 10);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++) cin >> b[i];
    for (int i = 1; i <= k; i++) {
        cin >> c[i];
        treap.insert({c[i], ++cnt});
    }
    if (k < n - m) {
        cout << "NO\n";
        return;
    }
    int idx = 1;
    vector<pii> gai;
    for (int i = 1; i <= m; i++) {
        while (a[idx] != b[i] && idx <= n) {
            isc[idx] = true;
            gai.emplace_back(a[idx], idx);
            idx++;
        }
        if (idx > n) {
            cout << "NO\n";
            return;
        }
        idx++;
    }
    while (idx <= n) {
        gai.emplace_back(a[idx], idx);
        isc[idx++] = true;
    }
    //for (auto [num, dis] : gai) cout << num << " " << dis << '\n';
    sort(gai.begin(), gai.end(), [&](pii a, pii b) {
        return a.first > b.first;
    });
    auto bin_search = [&](int k, int def) {
        int l = 1, r = top, res = def;
        while (l <= r) {
            int mid = l + r >> 1;
            if (stk[mid] > k) {
                res = ix[mid];
                l = mid + 1;
            }
            else r = mid - 1;
        }
        return res;
    };
    top = 0;
    for (int i = 1; i <= n; i++) {
        if (isc[i]) {
            left[i] = i - bin_search(a[i], 0);
        }
        else {
            while (top && stk[top] <= a[i]) top--;
            stk[++top] = a[i];
            ix[top] = i;
        }
    }
    top = 0;
    for (int i = n; i >= 1; i--) {
        if (isc[i]) {
            right[i] = bin_search(a[i], n + 1) - i;
        }
        else {
            while (top && stk[top] <= a[i]) top--;
            stk[++top] = a[i];
            ix[top] = i;
        }
    }
    for (int i = 0; i < gai.size(); i++) {
        int num = gai[i].first, dis = gai[i].second;
        int l = 1, r = k - i, ans = -1;
        while (l <= r) {
            int mid = l + r >> 1;
            int len = (*treap.find_by_order(mid - 1)).first;
            if (len <= le.getsum(dis) - le.getsum(dis - 1) + ri.getsum(dis) - ri.getsum(dis - 1) + left[dis] + right[dis] - cntl[dis - left[dis]] - cntr[dis + right[dis]] - 1) {
                ans = len;
                l = mid + 1;
            }
            else r = mid - 1;
        }
        if (ans == -1) {
            //cout << left[dis] + right[dis] - cntl[dis - left[dis]] - cntr[dis + right[dis]] - 1 << '\n';
            cout << "NO\n";
            return;
        }
        treap.erase(treap.upper_bound({ans, 0}));
        if (left[dis] > 1) ri.insert(dis - left[dis] + 1, dis - 1, 1);
        if (right[dis] > 1) le.insert(dis + 1, dis + right[dis] - 1, 1);
        cntl[dis - left[dis]]++, cntr[dis + right[dis]]++;

    }
    cout << "YES\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        work();
    }
    return 0;
}

詳細信息

Test #1:

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

input:

3
5 2 3
5 1 3 2 4
5 2
1 2 4
5 5 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
3 2 2
3 1 2
3 2
2 3

output:

YES
YES
NO

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3880kb

input:

100
2 1 2
2 1
2
1 1
2 1 2
1 2
1
2 2
2 1 1
1 2
1
2
6 1 5
3 4 2 5 6 1
3
5 2 1 1 1
6 1 6
2 1 3 6 4 5
1
4 1 2 2 1 4
3 3 2
2 1 3
2 1 3
2 2
1 1 1
1
1
1
1 1 1
1
1
1
2 1 2
2 1
2
1 2
4 4 3
2 1 3 4
2 1 3 4
4 3 1
1 1 1
1
1
1
6 5 1
6 2 5 4 3 1
6 2 4 3 1
4
1 1 1
1
1
1
6 5 3
3 6 1 4 5 2
3 6 1 4 2
3 3 4
4 3 4
3 4 ...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
Y...

result:

wrong answer 58th lines differ - expected: 'NO', found: 'YES'