QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#287234 | #5669. Traveling in Jade City | ItsJerr | WA | 2ms | 9832kb | C++17 | 3.0kb | 2023-12-20 02:26:51 | 2023-12-20 02:26:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
int c[N], x[N], prefc[N], prefx[N];
int n, k, m, q;
bool bannedC[N], bannedK[N];
set<int> banC, banK;
bool checkC(int L, int R) {
if (L > R) return !bannedC[n] && checkC(L, n) && checkC(1, R);
if (L == R) return 1;
if (banC.lower_bound(L) == banC.end()) return 1;
return *banC.lower_bound(L) >= R;
}
int sumC(int L, int R) {
if (L > R) return sumC(L, n) + c[n] + sumC(1, R);
return prefc[R - 1] - prefc[L - 1];
}
bool checkK(int L, int R) {
L -= n, R -= n;
if (L == R) return 1;
if (banK.lower_bound(L) == banK.end()) return 1;
return *banK.lower_bound(L) >= R;
}
int sumK(int x, int y) {
return prefx[y - n - 1] - prefx[x - n - 1];
}
int direct(int x, int y) {
int ret = 1e9;
if (x <= n && y <= n) {
if (checkC(x, y)) ret = min(ret, sumC(x, y));
if (checkC(y, x)) ret = min(ret, sumC(y, x));
}
else {
if (x > y) swap(x, y);
if (checkK(x, y)) ret = min(ret, sumK(x, y));
}
return ret;
}
int k1() {
int ret = direct(1, k);
if (!banK.size()) ret = min(ret, prefx[m]);
return ret;
}
int d1(int x) {
if (x <= n) return direct(1, x);
if (bannedK[0] || !checkK(n + 1, x)) return 1e9;
return prefx[x - n - 1];
}
int dk(int x) {
if (x <= n) return direct(x, k);
if (bannedK[m] || !checkK(x, n + m)) return 1e9;
return prefx[m] - prefx[x - n - 1];
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("qoj_5669.inp", "r")) {
freopen("qoj_5669.inp", "r", stdin);
freopen("qoj_5669.out", "w", stdout);
}
#ifdef LOCAL_MACHINE
if (fopen("task.inp", "r")) {
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
}
#endif
cin >> n >> k >> m >> q;
for (int i = 1; i <= n; ++i) {
cin >> c[i];
prefc[i] = prefc[i - 1] + c[i];
}
for (int i = 0; i <= m; ++i) {
cin >> x[i];
prefx[i] = (i ? prefx[i - 1] : 0) + x[i];
}
while (q--) {
char type; cin >> type;
if (type == 'q') {
int x, y; cin >> x >> y;
int res = 1e9;
if (x > y) swap(x, y);
if (!(x <= n && y > n)) res = min(res, direct(x, y));
res = min(res, d1(x) + d1(y));
res = min(res, dk(x) + dk(y));
res = min(res, d1(x) + k1() + dk(y));
res = min(res, dk(x) + k1() + d1(y));
if (res == 1e9) cout << "impossible\n";
else cout << res << "\n";
}
else if (type == 'c') {
int x; cin >> x;
if (bannedC[x]) banC.erase(x);
else banC.insert(x);
bannedC[x] ^= 1;
}
else {
int x; cin >> x;
if (bannedK[x]) banK.erase(x);
else banK.insert(x);
bannedK[x] ^= 1;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9832kb
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 -1294967296 6
result:
wrong answer 4th lines differ - expected: 'impossible', found: '-1294967296'