QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#588940 | #6820. Youth Finale | Sunlight9# | WA | 2ms | 6008kb | C++20 | 2.2kb | 2024-09-25 15:21:23 | 2024-09-25 15:21:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using LL = long long;
#define int LL
struct Bit {
int n;
vector<ll> s;
Bit (int _n) {
n = _n;
s.assign(n + 1, {});
}
int lowbit(int x) {
return x & -x;
}
void add(int x, int k) {
while (x <= n) {
s[x] += k;
x += lowbit(x);
}
};
LL qy(int x) {
LL res = 0;
while (x >= 1) {
res += s[x];
x -= lowbit(x);
}
return res;
}
LL qy(int l, int r) {
return qy(r) - qy(l - 1);
}
};
constexpr int M = 3E5 + 20;
signed main() {
cin.tie(nullptr) -> sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
a[i] = b[n - i + 1] = x;
}
a.insert(a.end(), a.begin() + 1, a.end());
b.insert(b.end(), b.begin() + 1, b.end());
int n2 = n + n;
auto work = [&](vector<int> &p) {
Bit bit(M);
vector<LL> sum(n2 + 1);
for (int i = 1; i <= n2; i++) {
int j = i - n;
if (j > 0) bit.add(p[j], -1);
sum[i] = sum[i - 1] + bit.qy(p[i] + 1, M);
if (j > 0) sum[i] -= bit.qy(p[j] - 1);
bit.add(p[i], 1);
}
return sum;
};
// cerr << "??? \n";
auto sa = work(a);
auto sr = work(b);
auto show = [&](auto &x) {
for (int i = 1; i <= n2; i++) {
cout << x[i] << " \n"[i == n2];
}
};
// show(a);
// show(sa);
// show(b);
// show(sr);
int inr = 1, r = n;
auto reg = [&](int x) {
if (x >= n2) x -= n;
if (x < n) x += n;
return x;
};
string ans = "", s;
cin >> s;
cout << sa[n] << "\n";
for (char c : s) {
if (c == 'R') {
inr = -inr;
} else {
r = reg(r + inr);
}
int res = (inr == 1 ? sa[r] : sr[r]) % 10;
// cout << inr << " " << r << " " << res << "\n";
ans += char(res + '0');
}
cout << ans << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 6008kb
input:
5 10 5 4 3 2 1 SSSSRSSSSR
output:
10 6446466400
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 5904kb
input:
1 1 1 R
output:
0 0
result:
ok 2 tokens
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 5968kb
input:
1000 2000 313 691 343 806 897 516 38 769 391 353 43 55 246 7 65 790 185 362 60 203 642 66 731 64 760 780 266 920 805 48 724 788 730 560 766 491 748 986 439 904 619 749 652 571 617 785 202 588 234 5 717 113 84 823 399 282 269 894 703 745 886 364 258 177 622 621 573 322 487 422 413 58 39 436 543 756 9...
output:
251209 43874381050107890783098123234927898721470309674923058363694547296507416143876969292321676989034983038541030987896725616943010543872367252169438969430743696107694147678721892527816985092189692785010789030107898907692961674507816763438529678381214145296929276765098723496107898943450929092765672...
result:
wrong answer 2nd words differ - expected: '438743810501078907830981232349...6787892107230123090509276327619', found: '438743810501078907830981232349...8903850981470741276343218723619'