QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133243#5669. Traveling in Jade Citytselmegkh#WA 1627ms42664kbC++204.0kb2023-08-01 19:57:282023-08-01 19:57:28

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:57:28]
  • 评测
  • 测评结果:WA
  • 用时:1627ms
  • 内存:42664kb
  • [2023-08-01 19:57:28]
  • 提交

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;
            
            if(u <= n && v <= n){
                //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(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), f(n + 1, n + m + 1) + f(v, n)});
                res = min(res, cur);
            }
            else if(u <= n && v > n){
                //u->k->v
                ll cur = min(f(min(u, k), max(u, k) - 1), f(1, u - 1) + f(k, n));
                cur += f(v + 1, n + m + 1);
                res = min(res, cur);
                //u->1->v
                cur = min(f(1, u - 1), f(u, n));
                cur += f(n + 1, v);
                res = min(res, cur);
            } else {
                //u->v
                res = min(res, f(u + 1, v));
                //u->1->k->v
                ll cur = f(n + 1, u);
                cur += min({f(k, n), f(1, k - 1)});
                cur += f(v + 1, n + m + 1);
                res = min(res, cur);
            }

            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: 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 #2:

score: 0
Accepted
time: 1ms
memory: 7684kb

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: 0
Accepted
time: 1320ms
memory: 42532kb

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
122264600
70328400
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
29295200
impossible
22163200
impossible
impossible
impossible
11422200
impossible
62579800
impossible
35339400
impossible
20157200
impossible
impossible
impossible
impossib...

result:

ok 500003 lines

Test #4:

score: 0
Accepted
time: 766ms
memory: 26272kb

input:

100000 25123 500000 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 200 ...

output:

4243800
37968200
35427000
52078200
5074200
70821200
13901400
13614600
8774800
68958800
49822200
31077400
impossible
45392400
48946000
76885400
37532600
34416200
impossible
20744200
71652000
21288000
7501600
70315400
14721800
impossible
12981800
81039600
9506800
impossible
33487200
53520200
impossibl...

result:

ok 500004 lines

Test #5:

score: 0
Accepted
time: 1321ms
memory: 42536kb

input:

1000000 543210 999999 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 20...

output:

43962400
803800
153423600
impossible
impossible
impossible
impossible
impossible
191566200
impossible
impossible
impossible
impossible
84524200
impossible
8790000
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
86439200
20798400
impossibl...

result:

ok 666666 lines

Test #6:

score: -100
Wrong Answer
time: 1627ms
memory: 42664kb

input:

999999 2 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 200 200...

output:

103577000
40419800
44334400
117613400
27695600
219757800
174773200
impossible
impossible
41683400
58145400
impossible
impossible
38841000
impossible
impossible
60723200
impossible
impossible
impossible
35102200
360200
impossible
64912000
48484000
impossible
impossible
impossible
impossible
impossibl...

result:

wrong answer 6th lines differ - expected: '101675800', found: '219757800'