QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#287647 | #5669. Traveling in Jade City | ThMinh__ | WA | 219ms | 57808kb | C++14 | 3.2kb | 2023-12-20 21:06:14 | 2023-12-20 21:06:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, k, m, q;
bool fix[N << 1];
int s[N << 1], g[N << 1], tr[N << 1];
struct rail {
int u, v, t;
} c[N << 1];
struct query {
char ch;
int i, u, v;
} Q[N];
void init() {
cin>>n>>k>>m>>q;
for(int i = 1; i <= n; ++i) {
int t; cin>>t;
c[i] = {i, i % n + 1, t};
}
for(int i = 0; i <= m; ++i) {
int t; cin>>t;
if(!i) c[n + i + 1] = {1, n + 1, t};
else if(i == m) c[n + i + 1] = {n + m, k, t};
else c[n + i + 1] = {n + i, n + i + 1, t};
}
for(int i = 1; i <= q; ++i) {
cin>>Q[i].ch;
if(Q[i].ch == 'q') cin>>Q[i].u>>Q[i].v;
else cin>>Q[i].i;
}
}
void up(int x, int val) {
while(x <= n + m + 1) {
tr[x] += val;
x += x & -x;
}
}
int get(int x) {
int res = 0;
while(x) {
res += tr[x];
x -= x & -x;
}
return res;
}
int dis(int f, int l) {
if(f > l) swap(f, l);
bool ok = 1;
if(f > n) ok = 0;
int sum = 1e9, cnt = get(l - 1) - get(f - 1);
if(ok) {
int val1 = cnt ? 1e9 : s[l - 1] - s[f - 1];
sum = min(sum, val1);
int val2 = (get(n) - cnt) ? 1e9 : s[n] - (s[l - 1] - s[f - 1]);
sum = min(sum, val2);
}
else if(!cnt) sum = min(sum, g[l - 1] - g[f - 1]);
return sum;
}
void solve() {
for(int i = 1; i <= n + m + 1; ++i) {
if(i <= n) s[i] = s[i - 1] + c[i].t;
if(i > n) g[i] = g[i - 1] + c[i].t;
}
for(int i = 1; i <= q; ++i) {
char ch = Q[i].ch;
if(ch == 'c') {
int j = Q[i].i;
int val = fix[j] ? -1 : 1;
up(j, val);
fix[j] ^= 1;
}
else if(ch == 'x') {
int j = Q[i].i;
int val = fix[n + j + 1] ? -1 : 1;
up(n + j + 1, val);
fix[n + j + 1] ^= 1;
}
else {
int u = Q[i].u;
int v = Q[i].v;
if(u > v) swap(u, v);
if(u == v) {
cout<<0<<"\n";
continue;
}
int ans = 1e9;
if(u <= n && v <= n) {
ans = min(ans, dis(u, v));
if(get(n + m + 1) - get(n) == 0) {
ans = min(ans, g[n + m + 1] + dis(1, u) + dis(k, v));
ans = min(ans, g[n + m + 1] + dis(k, u) + dis(1, v));
}
}
else if(u <= n && v > n) {
ans = min(ans, dis(v + 1, n + 1) + dis(1, u));
ans = min(ans, dis(v + 1, n + m + 2) + dis(k, u));
}
else {
ans = min(ans, dis(u + 1, v + 1));
int res = 1e9;
res = min(res, dis(n + 1, u + 1) + dis(v + 1, n + m + 2));
res = min(res, dis(n + m + 2, u + 1) + dis(v + 1, n + 1));
ans = min(ans, res + dis(1, k));
}
if(ans >= 1e9) cout<<"impossible\n";
else cout<<ans<<"\n";
}
}
}
int main () {
cin.tie(0)->sync_with_stdio(0);
if(fopen("Task.inp", "r")) {
freopen("Task.inp", "r", stdin);
freopen("WA.out", "w", stdout);
}
if(fopen("Train.inp", "r")) {
freopen("Train.inp", "r", stdin);
freopen("Train.out", "w", stdout);
}
init();
return solve(), 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5688kb
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: 1ms
memory: 5768kb
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: 219ms
memory: 57808kb
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 122264600 70328400 impossible -2094967096 impossible -2094967096 impossible impossible impossible impossible impossible 29295200 impossible 22163200 impossible impossible impossible 11422200 impossible 62579800 impossible 35339400 -2094967096 20157200 impossible impossible impossible -2094...
result:
wrong answer 5th lines differ - expected: 'impossible', found: '-2094967096'