QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#103481 | #5669. Traveling in Jade City | cardinal_city# | WA | 1107ms | 42308kb | C++17 | 4.6kb | 2023-05-06 04:36:16 | 2023-05-06 04:36:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size();
#define rep(i,j,k) for (int i = j; i < (k); i++)
#define in(mp, v) (mp.find(v) != mp.end())
#define smx(a, b) a = max(a, b)
#define smn(a, b) a = min(a, b)
#define pb push_back
#define endl '\n'
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, k, m, q; cin >> n >> k >> m >> q;
vector<ll> cpf(n+1), xpf(m+1);
for (int i = 1; i <= n; i++) {
cin >> cpf[i];
cpf[i] += cpf[i-1];
}
for (int i = 0; i <= m; i++) {
cin >> xpf[i];
if (i > 0) xpf[i] += xpf[i-1];
}
set<int> bkc, bkx;
auto qrc = [&](int a, int b) {
if (a > b) return 0ll;
auto lb = bkc.lower_bound(a);
if (lb != bkc.end() && *lb <= b) return MOD;
return cpf[b] - cpf[a-1];
};
auto qrx = [&](int a, int b) {
if (a > b) return 0ll;
auto lb = bkx.lower_bound(a);
if (lb != bkx.end() && *lb <= b) return MOD;
if (a <= 0) return xpf[b];
return xpf[b] - xpf[a-1];
};
for (int qi = 0; qi < q; qi++) {
string qt; cin >> qt;
if (qt[0] == 'c') {
int x; cin >> x;
if (in(bkc, x)) {
bkc.erase(x);
} else {
bkc.insert(x);
}
} else if (qt[0] == 'x') {
int x; cin >> x;
if (in(bkx, x)) {
bkx.erase(x);
} else {
bkx.insert(x);
}
} else {
int i, j; cin >> i >> j;
if (i > j) swap(i, j);
if (i > n && j > n) {
// case 1: both on line
i -= n; j -= n;
ll a1 = qrx(i, j-1);
ll xout = qrx(0, i-1) + qrx(j, m);
ll a2 = qrc(1, k-1) + xout;
ll a3 = qrc(k, n) + xout;
ll ans = min({a1, a2, a3});
if (ans >= MOD) cout << "impossible\n";
else cout << ans << '\n';
} else if (i <= n && j > n) {
// case 2: one on line, one off
ll xt = qrx(0, j-1), xb = qrx(j, m);
j -= n;
if (i < k) {
// case 2.1: off line is less than k
ll ct = qrc(1, i-1);
ll a1 = xt + ct;
ll a2 = xb + qrc(i, k-1);
ll a3 = xt + qrc(i, n);
ll a4 = xb + qrc(k, n) + ct;
ll ans = min({a1, a2, a3, a4});
if (ans >= MOD) cout << "impossible\n";
else cout << ans << '\n';
} else {
// case 2.2: off line is greater than k
ll ct = qrc(i, n);
ll a1 = xt + ct;
ll a2 = xb + qrc(k, i-1);
ll a3 = xt + qrc(1, i-1);
ll a4 = xb + qrc(1, k-1) + ct;
ll ans = min({a1, a2, a3, a4});
if (ans >= MOD) cout << "impossible\n";
else cout << ans << '\n';
}
} else if (i < k && j >= k) {
// case 3: on different sides of line
ll xt = qrx(0, m);
ll ct = qrc(j, n);
ll cb = qrc(1, i-1);
ll a1 = qrc(i, j-1);
ll a2 = cb + ct;
ll a3 = qrc(i, k-1) + xt + ct;
ll a4 = cb + xt + qrc(k, j-1);
ll ans = min({a1, a2, a3, a4});
if (ans >= MOD) cout << "impossible\n";
else cout << ans << '\n';
} else if (i < k && j < k) {
// case 4.1: both right of line
ll a1 = qrc(i, j-1);
ll ct = qrc(1, i-1);
ll a2 = ct + qrc(j, n);
ll a3 = ct + qrx(0, m) + qrc(j, k-1);
ll ans = min({a1, a2, a3});
if (ans >= MOD) cout << "impossible\n";
else cout << ans << '\n';
} else {
// case 4.2: both left of line
ll a1 = qrc(i, j-1);
ll ct = qrc(j, n);
ll a2 = ct + qrc(1, i-1);
ll a3 = ct + qrx(0, m) + qrc(k, i-1);
ll ans = min({a1, a2, a3});
if (ans >= MOD) cout << "impossible\n";
else cout << ans << '\n';
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3408kb
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: 2ms
memory: 3504kb
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: 1107ms
memory: 42308kb
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 33565400 26009600 impossible impossible impossible impossible impossible impossible impossible impossible impossible 10227400 impossible 10485200 impossible impossible impossible 11422200 impossible 62579800 impossible 35339400 impossible 20157200 impossible impossible impossible impossibl...
result:
wrong answer 2nd lines differ - expected: '122264600', found: '33565400'