QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549041#5669. Traveling in Jade Cityskrghariapa#WA 807ms67584kbC++207.1kb2024-09-06 00:49:412024-09-06 00:49:41

Judging History

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

  • [2024-09-06 00:49:41]
  • 评测
  • 测评结果:WA
  • 用时:807ms
  • 内存:67584kb
  • [2024-09-06 00:49:41]
  • 提交

answer

#include <bits/stdc++.h>
#include <bit>
#include <bitset>
#include <cstdint>
#include <iostream>

using namespace std;
// t2
#define gc getchar_unlocked
#define pii pair<long long, long long>
using ll = long long;
using cd = complex<double>;

const ll maxN = 1e6 + 10, maxM = 2e5 + 10, MAX = 2e6 + 10;
//const ll maxScore = 4294967295;
const ll mod = 1e9 + 7;
const double pi = acos(-1.0);
const double PI = acos(-1.0);
const double e = exp(1.0);
const ll naught = -100001;
const ll maxT = ceil(sqrt(maxN)) + 1;
const ll root_rec = 15311432;
const ll root_1 = 469870224;
const ll root_pw = (1 << 23);
const int K = 20;
const int g = 3;
const int LOGN = 20;
const int num1 = 16;
const int INF = 1e9;
//const ll is_query = -(1LL<<62)

ll seg[maxN * 4][2];

ll pref[maxN], prefL[maxN], n, m, k;

ll ril[maxN][2];

template <typename T> void fastInt(T& angka) {
    T kali = 1; angka = 0; char input = gc();
    while (!isdigit(input)) { if (input == '-') kali = -1; input = gc(); }
    while (isdigit(input)) angka = (angka << 3) + (angka << 1) + input - 48, input = gc();
    angka *= kali;
}

void fastStr(string& str) {
    str = "";
    char c = '0';
    while ((c = gc()) && (c != -1 && c != '\n' && c != '\t' && c != '\r' && c != ' ')) {
        str += c;
    }
}

ll powMod(ll x, ll y, ll p){
    ll res = 1;
    x %= p;
    if(!x) return 0;
    while (y > 0){
        if (y & 1) res = ((res % p) * (x % p)) % p;
        y = y >> 1;
        x = ((x % p) * (x % p)) % p;
    }
    return res % p;
}

ll inverseMod(ll x, ll p){
    return powMod(x, p - 2, p);
}

void upd(ll ind, ll l, ll r, ll i, ll j){
    if(r < i || i < l) return;
    if(l == r){
        assert(l == i);
        ril[l][j] ^= 1;
        seg[ind][j] = ril[l][j];
        return;
    }
    ll mid = (l + r) >> 1;
    upd(ind << 1, l, mid, i, j);
    upd(ind << 1 | 1, mid + 1, r, i, j);
    seg[ind][j] = seg[ind << 1][j] + seg[ind << 1 | 1][j];
}

ll query(ll ind, ll l, ll r, ll tl, ll tr, ll j){
    if(r < tl || tr < l) return 0;
    if(tl <= l && r <= tr) return seg[ind][j];
    ll mid = (l + r) >> 1;
    return query(ind << 1, l, mid, tl, tr, j) + query(ind << 1 | 1, mid + 1, r, tl, tr, j);
}

ll consider(ll x, ll y){
    if(x == -1) return y;
    if(y == -1) return x;
    return min(x, y);
}

ll clockwise(ll t1, ll t2){
    if(t1 == t2) return 0;
    ll asli = pref[max(t1, t2) - 1] - pref[min(t1, t2) - 1];
    if(t2 < t1){
        ll u = seg[1][0] - query(1, 1, n, t2, t1, 0);
        if(u == 0){
            return pref[n] - asli;
        }else{
            return -1;
        }
    }else{
        ll u = query(1, 1, n, t1, t2, 0);
        if(u == 0){
            return asli;
        }else{
            return -1;
        }
    }
}

ll counterclock(ll t1, ll t2){
    if(t1 == t2) return 0;
    return clockwise(t2, t1);
    //ll asli = pref[max(t1, t2) - 1] - pref[min(t1, t2) - 1];
    /*
    if(t2 < t1){
        ll k = t2 - 1;
        ll u = seg[1][0] - query(1, 1, n, t1, k, 0);
        if(u == 0){
            return pref[n] - pref[t1 - 1] + pref[k];
        }else{
            return -1;
        }
    }else{
        ll k = t1 - 1;
        if(k == 0) k = n;
        ll u = query(1, 1, n, t2, k, 0);
        if(u == 0){
            cout << t1 << "w " << t2 << endl;
            return pref[t2 - 1] - pref[k];
        }else{
            return -1;
        }
    }*/
}

ll case1(ll t1, ll t2){
    ll ans = -1;
    // clockwise
    ans = consider(ans, clockwise(t1, t2));
    //cout << "ans1: " << ans << endl;
    ans = consider(ans, counterclock(t1, t2));
    //cout << "ans2: " << ans << endl;

    if(seg[1][1] == 0){


    ll c1 = clockwise(t1, 1);
    ll cc1 = counterclock(t1, 1);

    ll k1 = consider(c1, cc1);

    ll c2 = clockwise(t1, k);
    ll cc2 = counterclock(t1, k);

    ll k2 = consider(c2, cc2);

    ll c3 = clockwise(1, t2);
    ll cc3 = counterclock(1, t2);

    ll k3 = consider(c3, cc3);

    ll c4 = clockwise(k, t2);
    ll cc4 = counterclock(k, t2);

    ll k4 = consider(c4, cc4);

    //cout << k1 << " " << k2 << " " << k3 << " " << k4 << " " << c3 << " " << cc3 <<  endl;

    if(k1 != -1 && k4 != -1) ans = consider(ans, k1 + k4 + prefL[m + 1]);
    if(k2 != -1 && k3 != -1) ans = consider(ans, k2 + k3 + prefL[m + 1]);
    }
    return ans;
}

ll case2(ll t1, ll t2){
    if(t1 == t2) return 0;
    ll u1 = clockwise(t1, k);
    ll u2 = counterclock(t1, k);
    ll ans = -1;
    ll k1 = consider(u1, u2);
    if(k1 != -1 && query(1, 1, m + 1, t2 - n + 1, m + 1, 1) == 0){
        ans = consider(k1 + prefL[m + 1] - prefL[t2 - n], ans);
    }

    ll u3 = clockwise(t1, 1);
    ll u4 = counterclock(t1, 1);

    ll k2 = consider(u3, u4);
    if(k2 != -1 && query(1, 1, m + 1, 1, t2 - n, 1) == 0){
        ans = consider(k2 + prefL[t2 - n], ans);
    }
    return ans;
}

ll case3(ll t1, ll t2){
    return case2(t2, t1);
}

ll case4(ll t1, ll t2){
    if(t1 == t2) return 0;
    if(t2 < t1) swap(t1, t2);
    ll u1 = clockwise(1, k);
    ll u2 = counterclock(1, k);

    ll k1 = consider(u1, u2);
    ll ans = -1;
    if(k1 != -1 && query(1, 1, m + 1, 1, t1 - n, 1) == 0 && query(1, 1, m + 1, t2 - n + 1, m + 1, 1) == 0){
        ans = consider(ans, k1 + prefL[t1 - n] + prefL[m + 1] - prefL[t2 - n]);
        //cout << "1: " << ans << endl;
    }
    if(query(1, 1, m + 1, t1 - n + 1, t2 - n, 1) == 0){
        ans = consider(ans, prefL[t2 - n] - prefL[t1 - n]);
        //cout << "2: " << ans << endl;
    }
    return ans;
}

void solve(){
    ll q;
    fastInt(n); fastInt(k); fastInt(m); fastInt(q);
    for(int i = 1; i <= n; i++){
        ll x; fastInt(x);
        pref[i] = pref[i - 1] + x;
    }
    for(int i = 1; i <= m + 1; i++){
        ll x; fastInt(x);
        prefL[i] = prefL[i - 1] + x;
    }
    for(int i = 1; i <= q; i++){
        string s1; fastStr(s1);
        if(s1 == "c"){
            ll t; fastInt(t);
            upd(1, 1, n, t, 0);
        }else if(s1 == "x"){
            ll t; fastInt(t);
            t++;
            upd(1, 1, m + 1, t, 1);
        }else{
            ll t1, t2;
            fastInt(t1); fastInt(t2);
            ll u = -1;
            if(1 <= t1 && t1 <= n && 1 <= t2 && t2 <= n){
                u = case1(t1, t2);
            }else if(1 <= t1 && t1 <= n && n < t2 && t2 <= n + m){
                u = case2(t1, t2);
            }else if(n < t1 && t1 <= n + m && 1 <= t2 && t2 <= n){
                cout << "h" << endl;
                u = case3(t1, t2);
            }else{
                u = case4(t1, t2);
            }
            if(u == -1) cout << "impossible" << '\n';
            else cout << u << '\n';
        }
    }
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.precision(10);
    //auto beg = high_resolution_clock::now();
    //cout << req(1e7 + 8) << '\n';
    //precalc();
    int t; t = 1;
    while(t--) solve();
    //auto en = high_resolution_clock::now();
    //auto dur = duration_cast<microseconds>(en - beg);
    //cout << dur.count() << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5684kb

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

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: 807ms
memory: 67584kb

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
h
impossible
impossible
impossible
impossible
h
impossible
h
impossible
h
impossible
h
impossible
impossible
h
29295200
impossible
22163200
impossible
impossible
impossible
11422200
h
impossible
62579800
impossible
35339400
impossible
20157200
impossible
h
impossible
imp...

result:

wrong answer 4th lines differ - expected: 'impossible', found: 'h'