QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#638842#5669. Traveling in Jade Citywmw#WA 293ms48668kbC++172.1kb2024-10-13 17:02:472024-10-13 17:02:47

Judging History

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

  • [2024-10-13 17:02:47]
  • 评测
  • 测评结果:WA
  • 用时:293ms
  • 内存:48668kb
  • [2024-10-13 17:02:47]
  • 提交

answer

//
// Created by 조문성 on 2024. 10. 13..
//
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define prs(v) sort(all(v)); v.erase(unique(all(v)), v.end())
using namespace std;
using ll = long long;
const int tN = 1 << 21;
ll t1[tN], t2[tN];

void update(int i, ll k, int op) {
    for (; i < tN; i += i & -i)(op ? t1 : t2)[i] += k;
}

ll query(int i, int op) {
    ll res = 0;
    for (; i; i -= i & -i)res += (op ? t1 : t2)[i];
    return res;
}

ll qry(int l, int r, int op) {
    return query(r, op) - query(l - 1, op);
}

const int N = 1'000'000;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, k, m, Q;

    cin >> n >> k >> m >> Q;
    assert(n != 1);

    vector<ll> W1(n + 1), W2(m + 2), S(m + 2);
    vector<int> on1(n + 1, 1), on2(m + 2, 1);
    for (int s = 1; s <= n; s++)cin >> W1[s];
    for (int s = 1; s <= m + 1; s++)cin >> W2[s], S[s] = S[s - 1] + W2[s];
    for (int s = 1; s <= n; s++)update(s, W1[s], 1);
    auto dist = [&](int u, int v) {
        if (u > v)swap(u, v);
        ll l = qry(u, v - 1, 1);
        ll r = qry(1, u - 1, 1) + qry(v, n, 1);
        return min(l, r);
    };
    for (int q = 1; q <= Q; q++) {
        char op;
        cin >> op;
        if (op == 'q') {
            int u, v;
            cin >> u >> v;
            if (u > v)swap(u, v);
            ll c = dist(u, v);
            ll l = qry(1, m + 1, 0);
            ll a = dist(u, 1) + dist(k, v) + (l ? 1e9 : S[m + 1]);
            ll b = dist(u, k) + dist(1, v) + (l ? 1e9 : S[m + 1]);
            ll mn = min({c, a, b});
            if (mn >= 1e9)cout << "impossible\n";
            else cout << mn << '\n';
        } else if (op == 'c') {
            int i;
            cin >> i;
            if (on1[i])update(i, -W1[i], 1), update(i, 1e9, 1), on1[i] = 0;
            else update(i, -1e9, 1), update(i, W1[i], -1), on1[i] = 1;
        } else {
            int i;
            cin >> i;
            i++;
            if (on2[i])update(i, 1, 0), on2[i] = 0;
            else update(i, -1, 0), on2[i] = 1;
        }
    }
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 17936kb

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: 17936kb

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: 293ms
memory: 48668kb

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
33565800
26009200
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
10227000
impossible
10484800
impossible
impossible
impossible
0
impossible
0
impossible
0
impossible
0
impossible
impossible
impossible
impossible
impossible
0
impossible
im...

result:

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