QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205635 | #7565. Harumachi Kaze | ucup-team087# | AC ✓ | 1914ms | 43948kb | C++14 | 5.8kb | 2023-10-07 16:51:25 | 2023-10-07 16:51:25 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
// #define DEB
using U = unsigned long long;
int cntAdd, cntCmp;
U add(U x, U y) {
#ifdef DEB
++cntAdd;
return x + y;
#else
if (!x) return y;
if (!y) return x;
if (x > y) swap(x, y);
static map<pair<U, U>, U> cache;
auto it = cache.find(make_pair(x, y));
if (it != cache.end()) return it->second;
printf("A %llu %llu\n", x, y); fflush(stdout);
U z; scanf("%llu", &z);
return cache[make_pair(x, y)] = z;
#endif
}
U cmp(U x, U y) {
#ifdef DEB
++cntCmp;
return min(x, y);
#else
if (!x) return 0;
if (!y) return 0;
if (x > y) swap(x, y);
static map<pair<U, U>, U> cache;
auto it = cache.find(make_pair(x, y));
if (it != cache.end()) return it->second;
printf("C %llu %llu\n", x, y); fflush(stdout);
U z; scanf("%llu", &z);
return cache[make_pair(x, y)] = z;
#endif
}
int N, Q, B;
vector<U> A[2];
vector<int> O, H, I, K;
vector<U> X;
int segN;
vector<int> L, R;
vector<U> seg[2];
U get(int h, int l, int e) {
const int r = l + (1 << e);
const int u = (segN >> e) + (l >> e);
assert(L[u] == l);
assert(R[u] == r);
return seg[h][u];
}
int main() {
scanf("%d%d%d", &N, &Q, &B);
for (int h = 0; h < 2; ++h) {
A[h].resize(N);
for (int i = 0; i < N; ++i) {
scanf("%llu", &A[h][i]);
}
}
O.assign(Q, -1);
H.assign(Q, -1);
I.assign(Q, -1);
X.assign(Q, -1);
K.assign(Q, -1);
for (int q = 0; q < Q; ++q) {
scanf("%d", &O[q]);
if (O[q] == 1) {
scanf("%d%d%llu", &H[q], &I[q], &X[q]);
--H[q];
--I[q];
} else {
scanf("%d", &K[q]);
}
}
for (segN = 1; segN < N; segN <<= 1) {}
L.assign(segN << 1, -1);
R.assign(segN << 1, -1);
for (int i = 0; i < segN; ++i) {
L[segN + i] = i;
R[segN + i] = i + 1;
}
for (int u = segN; --u; ) {
L[u] = L[u << 1];
R[u] = R[u << 1 | 1];
}
for (int h = 0; h < 2; ++h) {
seg[h].assign(segN << 1, 0);
for (int i = 0; i < N; ++i) {
seg[h][segN + i] = A[h][i];
}
for (int u = segN; --u; ) {
seg[h][u] = add(seg[h][u << 1], seg[h][u << 1 | 1]);
}
// cerr<<"seg["<<h<<"] = "<<seg[h]<<endl;
}
vector<U> anss;
for (int q = 0; q < Q; ++q) {
if (O[q] == 1) {
const int h = H[q];
const int i = I[q];
A[h][i] = X[q];
int u = segN + i;
seg[h][u] = X[q];
for (; u >>= 1; ) {
seg[h][u] = add(seg[h][u << 1], seg[h][u << 1 | 1]);
}
} else {
// cerr<<COLOR("33")<<"query "<<K[q]<<COLOR()<<endl;
U ans = -1;
int k = K[q];
int xs[2] = {};
U ss[2] = {};
for (; ; ) {
// cerr<<"k = "<<k<<", xs = "<<xs[0]<<" "<<xs[1]<<", ss = "<<ss[0]<<" "<<ss[1]<<endl;
assert(k >= 1);
int e = 31 - __builtin_clz(k);
if (e) --e;
// A[h][0, xs[h] + 2^e)
auto calc = [&](int h) -> U {
const U res = get(h, xs[h], e);
return add(ss[h], res);
};
auto adv = [&](int h) -> void {
ss[h] = calc(h);
xs[h] += (1 << e);
k -= (1 << e);
};
if (xs[0] + (1 << e) <= N) {
if (xs[1] + (1 << e) <= N) {
U ts[2];
for (int h = 0; h < 2; ++h) ts[h] = calc(h);
if (ts[0] == ts[1]) {
if ((1 << e) + (1 << e) >= k) {
ans = ts[0];
break;
} else {
adv(0);
adv(1);
}
} else {
const U mn = cmp(ts[0], ts[1]);
if (k == 1) {
ans = mn;
break;
} else {
if (mn == ts[0]) {
adv(0);
} else {
adv(1);
}
}
}
} else {
if (k == 1) {
ans = calc(0);
break;
} else {
adv(0);
}
}
} else {
if (xs[1] + (1 << e) <= N) {
if (k == 1) {
ans = calc(1);
break;
} else {
adv(1);
}
} else {
assert(false);
}
}
}
anss.push_back(ans);
}
}
#ifdef DEB
cerr<<"cntAdd = "<<cntAdd<<endl;
cerr<<"cntCmp = "<<cntCmp<<endl;
#endif
printf("! %d\n", (int)anss.size());
for (int i = 0; i < (int)anss.size(); ++i) {
if (i) printf(" ");
printf("%llu", anss[i]);
}
puts("");
fflush(stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3780kb
input:
2 3 2 288230376151711744 864691128455135232 1441151880758558720 2017612633061982208 2 3 1 2 2 2594073385365405696 2 3 1152921504606846976 3458764513820540928 288230376151711744 1152921504606846976 4035225266123964416
output:
A 288230376151711744 864691128455135232 A 1441151880758558720 2017612633061982208 C 288230376151711744 1441151880758558720 C 1152921504606846976 1441151880758558720 A 1441151880758558720 2594073385365405696 ! 2 1441151880758558720 1441151880758558720
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3660kb
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 5188146770730811392 3458764513820540928 3746994889972252672 2882303761517117440 144115188075...
output:
A 864691128455135232 2017612633061982208 A 2305843009213693952 2882303761517117440 A 1441151880758558720 2017612633061982208 A 288230376151711744 3458764513820540928 C 2882303761517117440 3458764513820540928 C 1441151880758558720 5188146770730811392 C 3458764513820540928 5188146770730811392 C 374699...
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 1547ms
memory: 37568kb
input:
16000 20000 14 12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...
output:
A 11048728814583818664 15677818123922243563 A 6866204288908749798 7524845485598995388 A 1068718252472774662 11980183590060892778 A 1651242460292755263 16451093994246303075 A 8054628330105193642 9284689372282485912 A 12924005644596021778 15686791472762219703 A 9015834026689566877 15540348601681561929...
result:
ok 2 lines
Test #4:
score: 0
Accepted
time: 1535ms
memory: 37816kb
input:
16000 20000 14 14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...
output:
A 1530312906755215691 6699580840817043648 A 3277995304381861937 3778754331816613065 A 5796810004253202499 17900425965763201922 A 10962991741131899674 16087894862382483319 A 9399062956659245650 10341669336510826685 A 3678974906259452354 13155214090337463029 A 12299727804406423735 13258416512718908913...
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 1579ms
memory: 37400kb
input:
16000 20000 14 12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...
output:
A 16384065041536563074 16646737163382162232 A 622375621264508444 4861463594572177469 A 16325934726602483649 17351712012742734872 A 1787658897265471541 16680849464824298188 A 8107465154877872066 8204363257667144067 A 4471449900873850680 6704679822520899332 A 17803294680465360433 18000352387766962329 ...
result:
ok 2 lines
Test #6:
score: 0
Accepted
time: 1455ms
memory: 36804kb
input:
16000 20000 14 12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...
output:
A 11048728814583818664 15677818123922243563 A 6866204288908749798 7524845485598995388 A 1068718252472774662 11980183590060892778 A 1651242460292755263 16451093994246303075 A 8054628330105193642 9284689372282485912 A 12924005644596021778 15686791472762219703 A 9015834026689566877 15540348601681561929...
result:
ok 2 lines
Test #7:
score: 0
Accepted
time: 1385ms
memory: 37840kb
input:
16000 20000 14 14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...
output:
A 1530312906755215691 6699580840817043648 A 3277995304381861937 3778754331816613065 A 5796810004253202499 17900425965763201922 A 10962991741131899674 16087894862382483319 A 9399062956659245650 10341669336510826685 A 3678974906259452354 13155214090337463029 A 12299727804406423735 13258416512718908913...
result:
ok 2 lines
Test #8:
score: 0
Accepted
time: 1419ms
memory: 36500kb
input:
16000 20000 14 12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...
output:
A 16384065041536563074 16646737163382162232 A 622375621264508444 4861463594572177469 A 16325934726602483649 17351712012742734872 A 1787658897265471541 16680849464824298188 A 8107465154877872066 8204363257667144067 A 4471449900873850680 6704679822520899332 A 17803294680465360433 18000352387766962329 ...
result:
ok 2 lines
Test #9:
score: 0
Accepted
time: 1914ms
memory: 43948kb
input:
16000 20000 14 12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...
output:
A 11048728814583818664 15677818123922243563 A 6866204288908749798 7524845485598995388 A 1068718252472774662 11980183590060892778 A 1651242460292755263 16451093994246303075 A 8054628330105193642 9284689372282485912 A 12924005644596021778 15686791472762219703 A 9015834026689566877 15540348601681561929...
result:
ok 2 lines
Test #10:
score: 0
Accepted
time: 1851ms
memory: 43480kb
input:
16000 20000 14 14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...
output:
A 1530312906755215691 6699580840817043648 A 3277995304381861937 3778754331816613065 A 5796810004253202499 17900425965763201922 A 10962991741131899674 16087894862382483319 A 9399062956659245650 10341669336510826685 A 3678974906259452354 13155214090337463029 A 12299727804406423735 13258416512718908913...
result:
ok 2 lines
Test #11:
score: 0
Accepted
time: 1738ms
memory: 43900kb
input:
16000 20000 14 12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...
output:
A 16384065041536563074 16646737163382162232 A 622375621264508444 4861463594572177469 A 16325934726602483649 17351712012742734872 A 1787658897265471541 16680849464824298188 A 8107465154877872066 8204363257667144067 A 4471449900873850680 6704679822520899332 A 17803294680465360433 18000352387766962329 ...
result:
ok 2 lines