QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#553848#5669. Traveling in Jade CityBongoCatEnjoyer#WA 237ms29068kbC++204.3kb2024-09-08 21:13:442024-09-08 21:13:44

Judging History

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

  • [2024-09-08 21:13:44]
  • 评测
  • 测评结果:WA
  • 用时:237ms
  • 内存:29068kb
  • [2024-09-08 21:13:44]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define forn(i,n) for(int i = 0; i <(int)n; ++i)
#define vi vector<int>
#define debug(x)    cout << #x << " : " << x << endl;

const int MOD = 1000000007;
//const int MOD = 998244353;

int fen[3][1000005]; // clow, chigh, x
int n, k, m, q;

void add(int x, int v, int f) {
    for (int i = x; i <= 1000000; i += i & -i) {
        fen[f][i] += v;
    }
}

int sum(int x, int f) {
    int ans = 0;
    for (int i = x; i > 0; i -= i & -i) {
        ans += fen[f][i];
    }
    return ans;
}


bool X[1000005], C[1000005];

void init() {
    for (int i = 0; i <= 1000003; ++i) {
        X[i] = C[i]  =1;
    }
    memset(fen, 0, sizeof(fen));
}
void togglex(int x) {
    if (X[x]) {
        add(x+1, 1e12, 2);
    }
    else {
        add(x+1, -1e12, 2);
    }

    X[x] = !X[x];
}

void togglec(int c) {
    int p = c >= k;
    int cc = c - (k - 1) * p;

    if (C[c]) {
        add(cc, 1e12, p);
    }
    else {
        add(cc, -1e12, p);
    }

    C[c] = !C[c];
}

int query(int l, int r) {
    int ans = LLONG_MAX;
    // direct
    if (l != 1 && l != k && r != 1 && r != k) {
        if (1 <= l && l < k && 1 < r && r < k) {
            int ll = min(l, r) - 1;
            int rr = max(l, r) - 1;

            ans = min(ans, sum(rr, 0) - sum(ll, 0));
        }
        else if (k < l && l <= n && k < r && r <= n) {
            int ll = min(l, r) - k;
            int rr = max(l, r) - k;

            ans = min(ans, sum(rr, 1) - sum(ll, 1));
        }
        else if (n < l && l <= n+m && n < r && r <= n+m) {
            int ll = min(l, r) - n;
            int rr = max(l, r) - n;

            ans = min(ans, sum(rr, 2) - sum(ll, 2));
        }
    }

    int lto1;
    if (1 <= l && l <= k) {
        lto1 = sum(l-1, 0);
    }
    else if (k < l && l <= n) {
        lto1 = sum(n-k+1, 1) - sum(l-k, 1);
    }
    else if (n < l && l <= n+m) {
        lto1 = sum(l-n, 2);
    }

    int rto1;
    if (1 <= r && r <= k) {
        rto1 = sum(r-1, 0);
    }
    else if (k < r && r <= n) {
        rto1 = sum(n-k+1, 1) - sum(r-k, 1);
    }
    else if (n < r && r <= n+m) {
        rto1 = sum(r-n, 2);
    }

    int ltok;
    if (1 <= l && l <= k) {
        ltok = sum(k, 0) - sum(l-1, 0);
    }
    else if (k < l && l <= n) {
        ltok = sum(l-k, 1);
    }
    else if (n < l && l <= n+m) {
        ltok = sum(m+1, 2) - sum(l-n, 2);
    }

    int rtok;
    if (1 <= r && r <= k) {
        rtok = sum(k, 0) - sum(r-1, 0);
    }
    else if (k < r && r <= n) {
        rtok = sum(r-k, 1);
    }
    else if (n < r && r <= n+m) {
        rtok = sum(m+1, 2) - sum(r-n, 2);
    }

    int kto1;
    kto1 = min(sum(k, 0), min(sum(n-k+1, 1), sum(m+1, 2)));

    // cout << m << "  " << sum(m+1, 2) << endl;

    // cout << lto1 << ' ' << ltok << ' ' << rto1 << ' ' << rtok << ' ' << kto1 << '\n';


    // via 1
    ans = min(ans, lto1 + rto1);
    // via k
    ans = min(ans, ltok + rtok);
    // via 1 - k
    ans = min(ans, lto1 + kto1 + rtok);
    // via k - 1
    ans = min(ans, ltok + kto1 + rto1);

    if (ans >= 1e12) {
        return -1;
    }
    return ans;
}

void solve() {
    cin >> n >> k >> m >> q;
    init();
    forn(i, n) {
        int x;
        cin >> x;
        if (i < k- 1) {
            add(i+1, x, 0);
        }
        else {
            add(i+2-k, x, 1);
        }
    }
    forn(i, m+1) {
        int x;
        cin >> x;
        add(i+1, x, 2);
    }

    forn(i, q) {
        char c;
        cin >> c;
        if (c == 'q') {
            int l, r;
            cin >> l >> r;
            int ans = query(l, r);
            if (ans == -1) {
                cout << "impossible\n";
            }
            else {
                cout << ans << '\n';
            }
        }
        else if (c == 'c') {
            int x;
            cin >> x;
            togglec(x);
        }
        else if (c == 'x') {
            int x;
            cin >> x;
            togglex(x);
        }
    }
}


int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    int tc = 1;
    // cin >> tc;
    while(tc--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 29028kb

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: 2ms
memory: 29064kb

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: 237ms
memory: 29068kb

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
122264400
70328200
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
29295200
impossible
22163200
impossible
impossible
impossible
11422200
impossible
62579800
impossible
35339200
impossible
20157200
impossible
impossible
impossible
impossib...

result:

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