QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#207132 | #6863. Or | jrjyy | AC ✓ | 4398ms | 14084kb | C++20 | 1.6kb | 2023-10-08 09:57:36 | 2023-10-08 09:57:37 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n, q;
std::cin >> n >> q;
std::vector<int> a(n);
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
}
std::vector<int> b(n);
for (int i = 0; i < n; ++i) {
std::cin >> b[i];
}
std::vector<std::vector<std::pair<int, int>>> qry(n);
for (int i = 0; i < q; ++i) {
int l, r;
std::cin >> l >> r;
--l;
qry[l].emplace_back(r, i);
}
std::vector<int> s(n);
for (int i = n - 2; i >= 0; --i) {
s[i] = s[i + 1] + b[i + 1];
}
std::vector<int> ans(q);
for (int bit = 0; bit < 30; ++bit) {
int fst = n;
for (int l = n - 1; l >= 0; --l) {
for (int r = l; r < n; ++r) {
if ((a[l] + s[l] - s[r]) >> bit & 1) {
fst = std::min(fst, r);
break;
}
}
for (auto [r, id] : qry[l]) {
if (fst < r) {
ans[id] += 1 << bit;
}
}
}
}
constexpr int P = 998244353, B = 233;
int res = 0, coef = 1;
for (int i = 0; i < q; ++i) {
coef = 1ll * coef * B % P;
res = (res + 1ll * ans[i] * coef) % P;
}
std::cout << res << "\n";
// for (int i = 0; i < q; ++i) {
// std::cout << ans[i] << "\n";
// }
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4398ms
memory: 14084kb
input:
4 40000 400000 548 4 34696904 0 7256657 310 0 253420460 0 89450757 759109 77 0 505042 382936044 1481860 986 6785 6683 477367350 88280508 0 78412 0 22978423 266 47 7409042 8 98452 437468733 0 909816 426136882 38 851 22645 387376803 0 32419 45 884 35 477851795 68713 6242 89402749 0 0 292244 605599 471...
output:
447795610 14292334 96619037 930487124
result:
ok 4 lines