QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#183745#5669. Traveling in Jade Cityreal_sigma_team#WA 527ms50156kbC++203.8kb2023-09-19 19:54:422023-09-19 19:54:43

Judging History

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

  • [2023-09-19 19:54:43]
  • 评测
  • 测评结果:WA
  • 用时:527ms
  • 内存:50156kb
  • [2023-09-19 19:54:42]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

using ll = long long;

#define int long long

struct fenwick {
    int n;
    vector<int> fenw;

    fenwick() = default;
    fenwick(int n) : n(n) {
        fenw.assign(n, 0);
    }

    void upd(int k, int x) {
        for (; k < n; k = (k | (k + 1))) {
            fenw[k] += x;
        }
    }

    int get(int k) {
        int res = 0;
        for (; k >= 0; k = (k & (k + 1)) - 1) {
            res += fenw[k];
        }
        return res;
    }

    int get(int l, int r) {
        return get(r) - get(l - 1);
    }
};

void solve() {
    int n, k, m, q;
    cin >> n >> k >> m >> q;
    --k;
    vector<int> c(n), x(m + 1);
    for (auto& i : c) cin >> i;
    for (auto& i : x) cin >> i;
    vector<bool> co(n, 0), xo(m + 1, 0);
    fenwick flenc(n), flenx(m + 1), foc(n), fox(m + 1);
    for (int i = 0; i < n; ++i) {
        flenc.upd(i, c[i]);
    }
    for (int i = 0; i <= m; ++i) {
        flenx.upd(i, x[i]);
    }
    auto checkc = [&](int u, int v) -> bool {
        if (u <= v) return foc.get(u, v - 1) == 0;
        return foc.get(0, n - 1) - foc.get(v, u - 1) == 0;
    };
    auto checkx = [&](int u, int v) -> bool {
        if (u > v) swap(u, v);
        return fox.get(u, v - 1) == 0;
    };
    auto distc = [&](int u, int v) -> int {
        if (!checkc(u, v)) return 1e15;
        if (u <= v) return flenc.get(u, v - 1);
        return flenc.get(0, n - 1) - flenc.get(v, u - 1);
    };
    auto distx = [&](int u, int v) -> int {
        if (u > v) swap(u, v);
        if (!checkx(u, v)) return 1e15;
        return flenx.get(u, v - 1);
    };
    auto dist0 = [&](int u) -> int {
        if (u >= n) return distx(0, u - n + 1);
        return min(distc(0, u), distc(u, 0));
    };
    auto distk = [&](int u) -> int {
        if (u >= n) return distx(m, u - n + 1);
        return min(distc(k, u), distc(u, k));
    };
    while (q--) {
        char qq;
        cin >> qq;
        if (qq == 'c') {
            int k;
            cin >> k;
            --k;
            if (!co[k]) {
                co[k] = 1;
                foc.upd(k, 1);
            } else {
                co[k] = 0;
                foc.upd(k, -1);
            }
        } else if (qq == 'x') {
            int k;
            cin >> k;
            if (!xo[k]) {
                xo[k] = 1;
                fox.upd(k, 1);
            } else {
                xo[k] = 0;
                fox.upd(k, -1);
            }
        } else {
            int u, v;
            cin >> u >> v;
            --u, --v;
            int ans = 1e15;
            ans = min(ans, dist0(u) + dist0(v));
            ans = min(ans, distk(u) + distk(v));
            ans = min(ans, dist0(u) + distx(0, m + 1) + distk(v));
            ans = min(ans, dist0(v) + distx(0, m + 1) + distk(u));
            ans = min(ans, dist0(u) + distc(0, k) + distk(v));
            ans = min(ans, dist0(u) + distc(k, 0) + distk(v));
            ans = min(ans, dist0(v) + distc(0, k) + distk(u));
            ans = min(ans, dist0(v) + distc(k, 0) + distk(u));
            if (max(u, v) < n) {
                ans = min(ans, distc(u, v));
                ans = min(ans, distc(v, u));
            }
            if (min(u, v) >= n) {
                ans = min(ans, distx(u - n + 1, v - n + 1));
            }
            if (ans == 1e15) cout << "impossible\n";
            else cout << ans << '\n';
        }
    }
}

int32_t main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#else
    freopen("input.txt", "r", stdin);
#endif
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3556kb

input:

4 3 1 9
2 3 8 4
1 1
q 3 4
x 0
q 3 4
c 3
q 3 4
c 1
q 3 4
x 0
q 3 4

output:

6
8
9
impossible
6

result:

ok 5 lines

Test #2:

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

input:

4 3 1 9
2 3 8 4
1 1
q 3 4
x 0
q 3 4
c 3
q 3 4
c 1
q 3 4
x 0
q 3 4

output:

6
8
9
impossible
6

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 527ms
memory: 50156kb

input:

1000000 999999 1000000 1000000
200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 2...

output:

177406400
122264400
70328200
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
29295200
impossible
22163200
impossible
impossible
impossible
11422200
impossible
62579800
impossible
35339200
impossible
20157200
impossible
impossible
impossible
impossib...

result:

wrong answer 2nd lines differ - expected: '122264600', found: '122264400'