QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84125#5669. Traveling in Jade CityHOLIC#WA 1227ms101968kbC++203.5kb2023-03-05 17:24:522023-03-05 17:24:53

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:24:53]
  • 评测
  • 测评结果:WA
  • 用时:1227ms
  • 内存:101968kb
  • [2023-03-05 17:24:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
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(0) == 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: 2ms
memory: 36072kb

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

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: 1227ms
memory: 101968kb

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
-54930800
-18107000
1058370167
impossible
impossible
impossible
939782567
1022383367
983772567
991594367
1040691167
-170502400
898299967
-177634400
951711567
1040873567
1012142767
-11219200
968163767
-62376800
861881567
-164458200
impossible
-19954200
935946967
866032767
905978167
impossib...

result:

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