QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84123#5669. Traveling in Jade CityHOLIC#WA 1218ms76952kbC++203.5kb2023-03-05 17:19:572023-03-05 17:20:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-05 17:20:00]
  • 评测
  • 测评结果:WA
  • 用时:1218ms
  • 内存:76952kb
  • [2023-03-05 17:19:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
const int N = 1e6 + 1009;
int n, m, k, q, c[N], C[N];
vector<int> ver[N];
int pre[N], suf[N], Pre[N], Suf[N], d1[N], d2[N];
set<int> s1, s2;
int check(int x) {
    if(x > n || x == k || x == 1) return true;
    return false;
}
int solve1(int x, int y) {
    if(x == y) return 0;
    if(x == k || (x > y && y != k)) swap(x, y);
    int idx = (x == 1 ? 0 : x - n);
    int idy = (y == k ? k : y - n - 1);
    //cout << x <<" " << y << " " << idx << " " << idy << endl;
    if(s2.lower_bound(idx) == s2.end() || *s2.lower_bound(idx) > idy) {
        return d1[y] - d1[x];
    } else return 0x3f3f3f3f;
}
int solve2(int x, int y) {
    if(x == y) return 0;
    if(x > y) swap(x, y);
    int idx = x;
    int idy = y - 1;
    int ans = 0x3f3f3f3f;
    if(s1.lower_bound(idx) == s1.end() || *s1.lower_bound(idx) > idy) {
        ans = min(ans, pre[y] - pre[x]);
    }
    if(s1.lower_bound(1) == s1.end() || *s1.lower_bound(1) > idx - 1) {
        if(s1.lower_bound(idy + 1) == s1.end()) {
            ans = min(ans, pre[x] + suf[y]);
            // cout << pre[x] << " " << suf[y] << " " << x << " " << y << endl;
        }
    }
    return ans;
}
int solve(int x, int y) {
    if(x == y) return 0;
    int ans = 0x3f3f3f3f;
    if(check(x) && check(y)) {
        ans = min(ans, solve1(x, y));
        ans = min(ans, solve1(x, 1) + solve2(1, k) + solve1(k, y));
        ans = min(ans, solve1(x, k) + solve2(k, 1) + solve1(1, y));
    } else if(check(x)) {
        ans = min(ans, solve1(x, 1) + solve2(1, y));
        //  cout<< ans<<" " << solve1(x, 1) <<  endl;
        ans = min(ans, solve1(x, k) + solve2(k, y));
    } else if(check(y)) {
        ans = min(ans, solve1(y, 1) + solve2(1, x));
        ans = min(ans, solve1(y, k) + solve2(k, x));
    } else {
        ans = min(ans, solve2(x, y));
        ans = min(ans, solve2(x, 1) + solve1(1, k) + solve2(k, y));
        ans = min(ans, solve2(x, k) + solve1(k, 1) + solve2(1, y));
    }
    return ans;
}
void work() {
    cin >> n >> k >> m >> q;
    for(int i = 1; i <= n; i ++) {
        cin >> c[i];
    }

    pre[1] = 0;
    for(int i = 2; i <= n; i ++) {
        pre[i] = pre[i - 1] + c[i - 1];
    }
    suf[n] = c[n];
    suf[1] = 0;
    for(int i = n - 1; i > 1; i --) {
        suf[i] = suf[i + 1] + c[i];
    }

    for(int i = 1; i <= m + 1; i ++) cin >> C[i];

    d1[1] = 0; d1[n + 1] = C[1];
    for(int i = n + 2; i <= n + m; i ++) d1[i] = d1[i - 1] + C[i - n];
    d1[k] = d1[n + m] + C[m + 1];

    d2[k] = 0; d2[n + m] = C[m + 1];
    for(int i = n + m - 1; i >= n + 1; i --) d2[i] = d2[i + 1] + C[i - n + 1];
    d2[1] = d2[n + 1] + C[1];

    for(int i = 1; i <= q; i ++) {
        string opt;
        cin >> opt;
        if(opt == "q") {
            int x, y;
            cin >> x >> y;
            int len = solve(x, y);
            if(len == 0x3f3f3f3f) cout << "impossible" << endl;
            else cout << solve(x, y) << endl;
        } else if(opt == "x") {
            int x;
            cin >> x;
            if(s2.count(x)) s2.erase(x);
            else s2.insert(x);
        } else if(opt == "c") {
            int x;
            cin >> x;
            if(s1.count(x)) s1.erase(x);
            else s1.insert(x);
        }
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int Case = 1;
    while(Case --) work();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 36076kb

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

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: 1218ms
memory: 76952kb

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
-54930000
-18106200
1058370967
impossible
impossible
impossible
939783367
1022384167
983773367
991595167
1040691967
-170501600
898300767
-177633600
951712367
1040874367
1012143567
-11218400
968164567
-62376000
861882367
-164457400
impossible
-19953400
935947767
866033567
905978967
impossib...

result:

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