QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#437690#7565. Harumachi KazepandapythonerAC ✓1185ms6120kbC++205.5kb2024-06-09 15:37:232024-06-09 15:37:24

Judging History

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

  • [2024-06-09 15:37:24]
  • 评测
  • 测评结果:AC
  • 用时:1185ms
  • 内存:6120kb
  • [2024-06-09 15:37:23]
  • 提交

answer

#include <bits/stdc++.h>


#define ull unsigned long long
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()


using namespace std;

const ll inf = 1e18;
mt19937 rnd(234);


#ifdef LOCAL
bool local = true;
#else
bool local = false;
#endif

struct biba {
    ull x = 0;
    bool bad = true;

    biba() {}
    biba(ull x) : x(x), bad(false) {}
    biba(ull x, bool bad) : x(x), bad(bad) {}
};


int query_count = 0;


biba operator+(const biba& a, const biba& b) {
    if (a.bad) {
        return a;
    }
    if (b.bad) {
        return b;
    }
    if (a.x == 0) {
        return b;
    }
    if (b.x == 0) {
        return a;
    }
    if (local) {
        return biba{ a.x + b.x, false };
    }
    if (query_count >= 1.5e6) {
        assert(0);
    }
    query_count += 1;
    cout << "A " << a.x << " " << b.x << endl;
    ull x;
    cin >> x;
    return biba{ x, false };
}


biba min(const biba& a, const biba& b) {
    if (a.bad) {
        return b;
    }
    if (b.bad) {
        return a;
    }
    if (a.x == 0) {
        return a;
    }
    if (b.x == 0) {
        return b;
    }
    if (local) {
        return biba{ min(a.x, b.x), false };
    }
    if (query_count >= 1.5e6) {
        assert(0);
    }
    query_count += 1;
    cout << "C " << a.x << " " << b.x << endl;
    ull x;
    cin >> x;
    return biba{ x, false };
}


bool operator==(const biba& a, const biba& b) {
    return a.x == b.x and a.bad == b.bad;
}


bool operator<=(const biba& a, const biba& b) {
    return min(a, b) == a;
}


biba max(const biba& a, const biba& b) {
    if (a <= b) {
        return b;
    } else {
        return a;
    }
}


istream& operator>>(istream& in, biba& a) {
    ull x;
    in >> x;
    a = biba{ x, false };
    return in;
}


ostream& operator<<(ostream& out, const biba& a) {
    return (out << a.x);
}


struct query {
    int type;
    int t, pos;
    biba x;
    int k;
};


istream& operator>>(istream& in, query& a) {
    in >> a.type;
    if (a.type == 1) {
        in >> a.t >> a.pos >> a.x;
        a.pos -= 1;
        assert(a.t == 1 or a.t == 2);
    } else if (a.type == 2) {
        in >> a.k;
    } else {
        assert(0);
    }
    return in;
}

int n, q;
int m;
ll B;

vector<biba> a, b;
vector<biba> ta, tb;
vector<query> f;
vector<biba> rs;


biba get_kth_old(int k) {
    assert(1 <= k and k <= 2 * n);
    int i = 0;
    int j = 0;
    biba last;
    biba sa = a[i], sb = b[j];
    while (k > 0) {
        k -= 1;
        if (sa <= sb) {
            last = sa;
            i += 1;
            sa = sa + a[i];
        } else {
            last = sb;
            j += 1;
            sb = sb + b[j];
        }
    }
    return last;
}


biba get_kth(int k) {
    assert(1 <= k and k <= 2 * n);
    biba sa = 0;
    biba sb = 0;
    int i = 0;
    int j = 0;
    while (k > 0) {
        int bits = __lg((k + 1) / 2);
        int u = i + m;
        int v = j + m;
        for (int x = 0; x < bits; x += 1) {
            u /= 2;
            v /= 2;
        }
        if (i == m) {
            sb = sb + tb[v];
            j += (1 << bits);
            k -= (1 << bits);
            continue;
        }
        if (j == m) {
            sa = sa + ta[u];
            i += (1 << bits);
            k -= (1 << bits);
            continue;
        }
        auto dsa = ta[u];
        auto dsb = tb[v];
        auto nsa = sa + dsa;
        auto nsb = sb + dsb;
        if (nsa <= nsb) {
            sa = nsa;
            i += (1 << bits);
            k -= (1 << bits);
        } else {
            sb = nsb;
            j += (1 << bits);
            k -= (1 << bits);
        }
    }
    return max(sa, sb);
}


void solve() {
    m = 1;
    while (m < n) {
        m *= 2;
    }
    ta.assign(2 * m, biba());
    tb.assign(2 * m, biba());
    for (int i = 0; i < n; i += 1) {
        ta[m + i] = a[i];
        tb[m + i] = b[i];
    }
    for (int i = m - 1; i >= 1; i -= 1) {
        ta[i] = ta[i + i] + ta[i + i + 1];
        tb[i] = tb[i + i] + tb[i + i + 1];
    }
    rs.clear();
    for (auto d : f) {
        if (d.type == 1) {
            if (d.t == 1) {
                a[d.pos] = d.x;
                int v = m + d.pos;
                ta[v] = d.x;
                for (v /= 2; v >= 1; v /= 2) {
                    ta[v] = ta[v + v] + ta[v + v + 1];
                }
            } else {
                b[d.pos] = d.x;
                int v = m + d.pos;
                tb[v] = d.x;
                for (v /= 2; v >= 1; v /= 2) {
                    tb[v] = tb[v + v] + tb[v + v + 1];
                }
            }
        } else {
            auto val = get_kth(d.k);
            rs.push_back(val);
        }
    }
}


int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    cin >> n >> q >> B;
    a.assign(n + 1, biba());
    b.assign(n + 1, biba());
    for (int i = 0; i < n; i += 1) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i += 1) {
        cin >> b[i];
    }
    f.resize(q);
    for (int i = 0; i < q; i += 1) {
        cin >> f[i];
    }
    solve();
    cout << "! " << (int)rs.size() << endl;
    for (auto x : rs) {
        cout << x << " ";
    }
    cout << endl;
    return 0;
}


/*
2 3 2
1 3
5 7
2 3
1 2 2 9
2 3

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 3 2
288230376151711744 864691128455135232
1441151880758558720 2017612633061982208
2 3
1 2 2 2594073385365405696
2 3
1152921504606846976
3458764513820540928
1152921504606846976
1152921504606846976
4035225266123964416
1152921504606846976
1152921504606846976

output:

A 288230376151711744 864691128455135232
A 1441151880758558720 2017612633061982208
C 1152921504606846976 3458764513820540928
C 1152921504606846976 1441151880758558720
A 1441151880758558720 2594073385365405696
C 1152921504606846976 4035225266123964416
C 1152921504606846976 1441151880758558720
! 2
1441...

result:

ok 2 lines

Test #2:

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

input:

3 5 3
2017612633061982208 864691128455135232 2305843009213693952
1441151880758558720 2017612633061982208 288230376151711744
2 5
2 2
1 1 3 1729382256910270464
1 2 1 2017612633061982208
2 5
2882303761517117440
3458764513820540928
2882303761517117440
5188146770730811392
3746994889972252672
374699488997...

output:

A 2017612633061982208 864691128455135232
A 1441151880758558720 2017612633061982208
C 2882303761517117440 3458764513820540928
A 2882303761517117440 2305843009213693952
A 3458764513820540928 288230376151711744
C 5188146770730811392 3746994889972252672
C 2882303761517117440 3746994889972252672
C 201761...

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 861ms
memory: 5916kb

input:

16000 20000 14
12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...

output:

A 11048728814583818664 15677818123922243563
A 2565851401584575835 6437826446793249029
A 6866204288908749798 7524845485598995388
A 7541202894948887905 17999698327915010774
A 1068718252472774662 11980183590060892778
A 8586449783218478804 14434754479864353936
A 16451093994246303075 1651242460292755263
...

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 1160ms
memory: 5928kb

input:

16000 20000 14
14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...

output:

A 6699580840817043648 1530312906755215691
A 11622006755605925985 6066307777916066633
A 3778754331816613065 3277995304381861937
A 11811774561651298468 5475264425524514453
A 5796810004253202499 17900425965763201922
A 11861448038057634268 16955721253727089685
A 16087894862382483319 10962991741131899674...

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 1086ms
memory: 5960kb

input:

16000 20000 14
12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...

output:

A 16646737163382162232 16384065041536563074
A 2939679445067668328 11455813752167935374
A 622375621264508444 4861463594572177469
A 9295874022640625423 13814305402487251484
A 17351712012742734872 16325934726602483649
A 5933243281540024388 33452168578618265
A 16680849464824298188 1787658897265471541
A ...

result:

ok 2 lines

Test #6:

score: 0
Accepted
time: 1173ms
memory: 5928kb

input:

16000 20000 14
12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...

output:

A 11048728814583818664 15677818123922243563
A 2565851401584575835 6437826446793249029
A 6866204288908749798 7524845485598995388
A 7541202894948887905 17999698327915010774
A 1068718252472774662 11980183590060892778
A 8586449783218478804 14434754479864353936
A 16451093994246303075 1651242460292755263
...

result:

ok 2 lines

Test #7:

score: 0
Accepted
time: 1018ms
memory: 5964kb

input:

16000 20000 14
14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...

output:

A 6699580840817043648 1530312906755215691
A 11622006755605925985 6066307777916066633
A 3778754331816613065 3277995304381861937
A 11811774561651298468 5475264425524514453
A 5796810004253202499 17900425965763201922
A 11861448038057634268 16955721253727089685
A 16087894862382483319 10962991741131899674...

result:

ok 2 lines

Test #8:

score: 0
Accepted
time: 1066ms
memory: 6120kb

input:

16000 20000 14
12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...

output:

A 16646737163382162232 16384065041536563074
A 2939679445067668328 11455813752167935374
A 622375621264508444 4861463594572177469
A 9295874022640625423 13814305402487251484
A 17351712012742734872 16325934726602483649
A 5933243281540024388 33452168578618265
A 16680849464824298188 1787658897265471541
A ...

result:

ok 2 lines

Test #9:

score: 0
Accepted
time: 1056ms
memory: 5928kb

input:

16000 20000 14
12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...

output:

A 11048728814583818664 15677818123922243563
A 2565851401584575835 6437826446793249029
A 6866204288908749798 7524845485598995388
A 7541202894948887905 17999698327915010774
A 1068718252472774662 11980183590060892778
A 8586449783218478804 14434754479864353936
A 16451093994246303075 1651242460292755263
...

result:

ok 2 lines

Test #10:

score: 0
Accepted
time: 1185ms
memory: 5924kb

input:

16000 20000 14
14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...

output:

A 6699580840817043648 1530312906755215691
A 11622006755605925985 6066307777916066633
A 3778754331816613065 3277995304381861937
A 11811774561651298468 5475264425524514453
A 5796810004253202499 17900425965763201922
A 11861448038057634268 16955721253727089685
A 16087894862382483319 10962991741131899674...

result:

ok 2 lines

Test #11:

score: 0
Accepted
time: 1093ms
memory: 6048kb

input:

16000 20000 14
12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...

output:

A 16646737163382162232 16384065041536563074
A 2939679445067668328 11455813752167935374
A 622375621264508444 4861463594572177469
A 9295874022640625423 13814305402487251484
A 17351712012742734872 16325934726602483649
A 5933243281540024388 33452168578618265
A 16680849464824298188 1787658897265471541
A ...

result:

ok 2 lines