QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84122#5669. Traveling in Jade CityHOLIC#WA 1213ms77432kbC++203.4kb2023-03-05 17:10:362023-03-05 17:10:39

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:10:39]
  • 评测
  • 测评结果:WA
  • 用时:1213ms
  • 内存:77432kb
  • [2023-03-05 17:10:36]
  • 提交

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 == n || (x > y && y != n)) 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: 0ms
memory: 36204kb

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

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: 1213ms
memory: 77432kb

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
-55133800
-18309200
1058167567
impossible
impossible
impossible
939579967
1022180767
983569967
991391767
1040488567
-170704600
898097367
-177836600
951508967
1040670967
1011940167
-286914800
967961167
-257026400
861678967
-212527400
impossible
-137578200
935744367
865830167
905775567
impos...

result:

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