QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133233#5669. Traveling in Jade Citytselmegkh#WA 1859ms42708kbC++203.1kb2023-08-01 19:09:272023-08-01 19:09:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-01 19:09:30]
  • 评测
  • 测评结果:WA
  • 用时:1859ms
  • 内存:42708kb
  • [2023-08-01 19:09:27]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;

const int N = 1e6 + 5, inf = 1e9;
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define sz(x) (int)x.size()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
int n, k, m, q;
int a[N], b[N];

ll t[4 * N];

void update(int v, int l, int r, int x, int k){
    if(l > x || r < x)return;
    if(l == x && r == x){
        t[v] = k;
        return;
    }
    int mid = (l + r) / 2;
    update(v * 2, l, mid, x, k);
    update(v * 2 + 1, mid + 1, r, x, k);
    t[v] = t[v * 2] + t[v * 2 + 1];
}
ll get(int v, int l, int r, int ql, int qr){
    if(ql > qr)return 0ll;
    if(l > qr || r < ql)return 0ll;
    if(ql <= l && r <= qr)return t[v];
    int mid = (l + r) / 2;
    return get(v * 2, l, mid, ql, qr) + get(v * 2 + 1, mid + 1, r, ql, qr);
}
ll f(int u, int v){
    return get(1, 1, n + m + 1, u, v);
}
void solve(){
    cin >> n >> k >> m >> q;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        update(1, 1, n + m + 1, i, a[i]);
    }
    for(int i = 0; i <= m; i++){
        cin >> b[i];
        update(1, 1, n + m + 1, n + i + 1, b[i]);
    }
    while(q--){
        char type;
        cin >> type;
        if(type == 'q'){
            int u, v; cin >> u >> v;
            if(u > v)swap(u, v);
            ll res = inf;
            //u->v
            res = min(res, min(f(u, v - 1), f(1, u - 1) + f(v, n)));
            //u->k->1->v
            ll cur = min({f(min(u, k), max(u, k) - 1), f(1, u - 1) + f(n + 1, n + m + 1), f(u, n) + f(1, k - 1), f(1, u - 1) + f(k, n)}); // u->k
            cur += min({f(n + 1, n + m + 1), f(k, n), f(1, k - 1)});
            cur += min(f(1, v - 1), f(v, n));
            res = min(res, cur);
            //u->1->k->v
            cur = min(f(1, u - 1), f(u, n));
            cur += min({f(n + 1, n + m + 1), f(k, n), f(1, k - 1)});
            cur += min({f(min(v, k), max(v, k) - 1), f(1, v - 1) + f(n + 1, n + m + 1), f(k, n) + f(1, v - 1), f(1, k - 1) + f(v, n)});
            if(res == inf){
                cout << "impossible\n";
            } else {
                cout << res << '\n';
            }
        } else if(type == 'c'){
            int i; cin >> i;
            if(f(i, i) == inf){
                update(1, 1, n + m + 1, i, a[i]);
            } else {
                update(1, 1, n + m + 1, i, inf);
            }
        } else if(type == 'x'){
            int j; cin >> j;
            if(f(n + 1 + j, n + 1 + j) == inf){
                update(1, 1, n + m + 1, n + 1 + j, b[j]);
            } else {
                update(1, 1, n + m + 1, n + 1 + j, inf);
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7568kb

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

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: 1859ms
memory: 42708kb

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
33565800
26009200
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
10227000
impossible
10484800
impossible
impossible
impossible
11422200
impossible
40095800
impossible
11304600
impossible
20157200
impossible
impossible
impossible
impossibl...

result:

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