QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549881#5669. Traveling in Jade CityTiga_Pilot_2#WA 1544ms42284kbC++204.0kb2024-09-06 22:51:122024-09-06 22:51:13

Judging History

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

  • [2024-09-06 22:51:13]
  • 评测
  • 测评结果:WA
  • 用时:1544ms
  • 内存:42284kb
  • [2024-09-06 22:51:12]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(a, b) for (int i = (int) a; i < (int) b; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int mxn = 2e6;
const int inf = 1e9;
vector<int> t(mxn*4);
vector<int> a(mxn);
int n, k, m, q, sz;
int combine(int x, int y) {
    if(x >= inf || y >= inf) {
        return inf;
    } else {
        if(x >= inf-y) {
            return inf;
        } else {
            return x+y;
        }
    }
}

void build(int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(v*2, tl, tm);
        build(v*2+1, tm+1, tr);
        t[v] = combine(t[v*2], t[v*2+1]);
    }
}

void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = combine(t[v*2], t[v*2+1]);
    }
}

int query(int v, int tl, int tr, int l, int r) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) 
        return t[v];
    int tm = (tl + tr) / 2;
    return combine(query(v*2, tl, tm, l, min(r, tm)), 
                   query(v*2+1, tm+1, tr, max(l, tm+1), r));
}

array<int, 3> sol(int u) {
    array<int, 3> res = {inf, inf, inf};
    if(u <= k) {
        if(u == 1) {
            res[0] = 0;
        } else {
            res[0] = query(1, 0, sz-1, 0, max(u-2, 0));
        }
        res[1] = query(1, 0, sz-1, u-1, n-1);
        res[2] = query(1, 0, sz-1, u-1, k-2) + query(1, 0, sz-1, n, sz-1);
    } else if(u <= n) {
        res[0] = query(1, 0, sz-1, 0, max(u-2, 0));
        res[1] = query(1, 0, sz-1, u-1, n-1);
        res[2] = query(1, 0, sz-1, k-1, u-2) + query(1, 0, sz-1, n, sz-1);
    } else {
        res[0] = query(1, 0, sz-1, n, u-1);
        res[1] = query(1, 0, sz-1, n, sz-1) + query(1, 0, sz-1, 0, k-2);
        res[2] = query(1, 0, sz-1, n, sz-1) + query(1, 0, sz-1, k-1, n-1);
    }
    return res;
}


int main() { 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k >> m >> q;
    sz = n+m+1;
    for(int i=0; i<n; i++) {
        cin >> a[i]; 
    }
    for(int i=n; i<=n+m; i++) {
        cin >> a[i];
    }
    // for(int i=0; )
    build(1, 0, sz-1);
    while(q--) {
        char ct;
        cin >> ct;
        if(ct == 'q') {
            // for(int i=0; i<sz; i++){
            //     cout << query(1, 0, sz-1, i, i) << " \n"[i==sz-1];
            // }
            int u, v;
            cin >> u >> v;
            if(u == v) {
                cout << 0 << "\n";
            } else {
                if(u > v) {
                    swap(u, v);
                }
                int ans = query(1, 0, sz-1, u-1, v-2);
                array<int, 3> ax1 = sol(u);
                array<int, 3> ax2 = sol(v);
                for(int i=0; i<3; i++) {
                    for(int j=0; j<3; j++) {
                        int as = combine(ax1[i], ax2[j]);
                        ans = min(ans, as);
                    }
                }
                if(ans >= inf) {
                    cout << "impossible\n";
                } else {
                    cout << ans << "\n";
                }
            }
        } else {
            int x;
            cin >> x;
            if(ct == 'x') {
                x = x+n+1;
            }
            int qry = query(1, 0, sz-1, x-1, x-1);
            if(qry >= inf) {
                update(1, 0, sz-1, x-1, a[x-1]);
            } else {
                update(1, 0, sz-1, x-1, inf);
            }
        }
        
        // for(int i=0; i<sz; i++){
        //     cout << query(1, 0, sz-1, i, i) << " \n"[i==sz-1];
        // }
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 9ms
memory: 42284kb

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: 1544ms
memory: 42208kb

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
144866600
181690600
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
29295200
impossible
22163200
impossible
impossible
impossible
11422200
impossible
62579800
impossible
164661200
impossible
20157200
impossible
impossible
impossible
imposs...

result:

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