QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#219374 | #5661. Multi-Ladders | JenniferLing# | RE | 0ms | 0kb | C++17 | 1.6kb | 2023-10-19 13:44:38 | 2023-10-19 13:44:39 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e6 + 5;
const int inf = 4e8 + 5;
int toggle[N], w[N];
int n, m, k, q;
int bit[N];
void upd(int x, int val) {
for (; x <= n + m + 1; x += x & (-x)) bit[x] += val;
}
int qry(int x) {
int res = 0;
for (; x; x -= x & (-x)) res += bit[x];
return res;
}
int sum(int l, int r) {
return qry(r) - qry(l - 1);
}
int dis(int x, int y) {
int res = inf;
if (x > y) swap(x, y);
if (x <= n && y <= n) res = min({res, sum(x, y - 1), sum(1, n) - sum(x, y - 1)});
if ((x == 1 || x == k || x > n) && (y == 1 || y == k || y > n)) {
if (x == 1) x = n;
else if (x == k) x = n + m + 1;
if (y == 1) y = n;
else if (y == k) y = n + m + 1;
if (x > y) swap(x, y);
res = min(res, sum(x + 1, y));
}
return res;
}
void solve() {
cin >> n >> k >> m >> q;
for (int i = 1; i <= n + m + 1; ++i) {
cin >> w[i];
upd(i, w[i]);
}
int x, y;
char op;
while (q--) {
cin >> op >> x;
if (op == 'q') {
cin >> y;
int res = dis(x, y);
for (int i = 1; i <= k; i += k - 1) {
for (int j = 1; j <= k; j += k - 1) {
res = min(res, dis(x, i) + dis(y, j) + dis(i, j));
}
}
if (res == inf) cout << "impossible\n";
else cout << res << "\n";
} else {
if (op == 'x') x += n + 1;
if (toggle[x]) upd(x, w[x] - inf);
else upd(x, inf - w[x]);
toggle[x] ^= 1;
}
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
// cin >> T;
while (T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
1 2 3 3