QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#571666 | #9351. Game Store | real_sigma_team# | TL | 0ms | 3520kb | C++20 | 1.4kb | 2024-09-18 03:11:52 | 2024-09-18 03:11:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve();
int32_t main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#endif
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
__int128_t xor3(__int128_t a, __int128_t b) {
__int128_t res = 0, i3 = 1;
while (a || b) {
res += (((a % 3) + (b % 3)) % 3) * i3;
i3 *= 3;
a /= 3;
b /= 3;
}
return res;
}
__int128_t mndeg3(__int128_t x) {
__int128_t i3 = 1;
while (i3 * 3 <= x) {
i3 *= 3;
}
return i3;
}
void solve() {
int n;
cin >> n;
ll last = 0;
vector<pair<__int128_t, int>> base;
for (int i = 0; i < n; i++) {
ll x, y;
cin >> x >> y;
x ^= last;
y ^= last;
__int128_t i3 = 1;
__int128_t a = 0;
for (int j = 0; j < 60; j++) {
if ((1ll << j) & x) {
a += i3;
}
i3 *= 3;
}
int b = y;
int ind = 0;
pair<int, int> mx = {0, 0};
pair<__int128_t, int> oink;
for (auto [v, c] : base) {
if (mndeg3(a) == mndeg3(v)) {
if (make_pair(b - c, ind) > mx) {
mx = make_pair(b - c, ind);
oink = {a, b};
}
while (a >= mndeg3(v)) {
a = xor3(a, v);
}
} else {
break;
}
ind++;
}
if (a) {
base.emplace(base.begin() + ind, a, b);
last += b;
} else if (mx.first > 0) {
last += mx.first;
base[mx.second] = oink;
}
cout << last << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
input:
3 1 4 6 7 4 13
output:
4 7 14
result:
ok 3 lines
Test #2:
score: -100
Time Limit Exceeded
input:
500000 395134631858718935 964539556 125290790696511447 743741881 68785955678986648 1867726875 774218610629433714 1107843806 251011758189826329 3218789432 712376502291877860 3368474950 237512969552427655 3307057592 26026853208103063 3366794857 904189246433646740 3824475130 105677592268903953 50111856...
output:
964539556 1319559617 1889305499 2737921248 3223119288 3371639478 3605116356 4113447281 4496890876 5146597364 5443005741 5560684788 6532334449 7521134451 8336539770 8705245338 9014268525 9265374719 9381614536 9559254162 10004316290 10462314640 10662416153 10955313276 11748683855 12256749782 129943566...