QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#654485 | #5516. Modern Machine | liuziao | 37 | 748ms | 57312kb | C++23 | 3.1kb | 2024-10-18 21:39:34 | 2024-10-18 21:39:39 |
Judging History
answer
#include <bits/stdc++.h>
// #define int int64_t
const int kMaxN = 1.2e5 + 5, kLog = 18;
int n, m, q;
int a[kMaxN], nxt[kLog][kLog][kMaxN];
int64_t sumr[kLog][kLog][kMaxN], sumb[kLog][kLog][kMaxN];
std::string s;
struct SGT {
std::vector<std::pair<int, int>> v[kMaxN * 4];
int func(int x, int val) {
auto it = std::upper_bound(v[x].begin(), v[x].end(), std::pair<int, int>(val, 1e9)) - 1;
return val + it->second;
}
void pushup(int x) {
int ls = (x << 1), rs = (x << 1 | 1);
for (int i = 0; i < (int)v[ls].size(); ++i) {
auto [L, val] = v[ls][i];
int R = (i + 1 == (int)v[ls].size() ? n + 1 : v[ls][i + 1].first);
auto itl = std::lower_bound(v[rs].begin(), v[rs].end(), std::pair<int, int>(L + val, -1e9));
auto itr = std::lower_bound(v[rs].begin(), v[rs].end(), std::pair<int, int>(R + val, -1e9));
v[x].emplace_back(L, 0);
for (auto it = itl; it != itr; ++it) {
v[x].emplace_back(it->first - val, 0);
}
}
std::sort(v[x].begin(), v[x].end());
v[x].erase(std::unique(v[x].begin(), v[x].end()), v[x].end());
for (auto &[xx, val] : v[x]) {
val = func(rs, func(ls, xx)) - xx;
}
}
void build(int x, int l, int r) {
if (l == r) {
if (n - a[l] > 0) {
v[x].emplace_back(0, a[l] + 1);
if (n - a[l] <= a[l] - 1) v[x].emplace_back(n - a[l], a[l] - n);
} else {
v[x].emplace_back(0, a[l] - n);
}
if (a[l] < n + 1 - a[l]) {
v[x].emplace_back(a[l], a[l]);
v[x].emplace_back(n - a[l] + 1, a[l] - (n + 1));
} else {
v[x].emplace_back(a[l], a[l] - (n + 1));
}
std::sort(v[x].begin(), v[x].end());
return;
}
int mid = (l + r) >> 1;
build(x << 1, l, mid), build(x << 1 | 1, mid + 1, r);
pushup(x);
}
int query(int x, int l, int r, int ql, int qr, int val) {
if (l > qr || r < ql) {
return val;
} else if (l >= ql && r <= qr) {
return func(x, val);
}
int mid = (l + r) >> 1;
return query(x << 1 | 1, mid + 1, r, ql, qr, query(x << 1, l, mid, ql, qr, val));
}
} sgt;
void prework() {
sgt.build(1, 1, m);
}
void dickdreamer() {
std::cin >> n >> m >> s;
s = " " + s;
for (int i = 1; i <= m; ++i) std::cin >> a[i];
prework();
int fir = 0;
for (int i = 1; i <= n; ++i)
if (s[i] == 'R')
fir = i;
std::cin >> q;
for (int i = 1; i <= q; ++i) {
int l, r;
std::cin >> l >> r;
std::cout << sgt.query(1, 1, m, l, r, fir) << '\n';
// int now = fir;
// for (int j = l; j <= r; ++j) now = sgt.query(1, 1, m, j, j, now);
// for (int j = l; j <= r; ++j) {
// if (now >= a[j]) now = (now + a[j]) % (n + 1);
// else now = (now + a[j] + 1) % (n + 1);
// }
// std::cout << now << '\n';
}
}
int32_t main() {
#ifdef ORZXKR
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
int T = 1;
// std::cin >> T;
while (T--) dickdreamer();
// std::cerr << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3588kb
input:
3 1 BBR 3 1 1 1
output:
2
result:
wrong answer 1st lines differ - expected: '0', found: '2'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 11
Accepted
Test #21:
score: 11
Accepted
time: 173ms
memory: 31396kb
input:
10 120000 RRRRRRRRRR 9 1 9 6 1 9 6 10 3 2 6 4 2 5 7 10 8 9 2 6 7 10 2 9 7 5 9 9 2 7 4 1 8 3 3 6 9 4 7 9 6 8 8 2 5 6 8 3 9 2 5 2 5 9 8 4 8 3 2 2 5 1 9 1 7 9 9 4 9 5 2 10 7 4 3 8 1 10 7 6 6 2 3 8 7 8 5 9 2 2 1 10 2 2 5 4 2 5 9 1 8 4 5 1 2 8 3 10 10 6 7 2 1 5 10 1 9 10 1 7 3 10 8 10 6 8 3 1 10 9 10 5 5...
output:
10 6 1 8 1 9 8 1 3 0 3 4 4 2 2 2 10 8 10 7 0 7 0 1 10 3 10 7 3 2 10 8 10 0 0 10 1 2 5 4 0 7 1 0 6 7 6 8 3 2 4 7 0 6 7 5 2 8 4 8 1 4 4 10 3 7 7 7 3 1 3 10 3 4 0 2 1 3 9 8 4 6 10 9 3 7 9 2 5 7 2 7 2 1 0 6 0 6 3 6 2 8 1 10 9 4 5 2 5 10 9 4 1 8 5 3 6 3 8 9 10 6 4 10 7 2 8 7 9 7 7 0 9 5 5 6 3 7 4 7 9 6 7...
result:
ok 120000 lines
Test #22:
score: 11
Accepted
time: 187ms
memory: 31468kb
input:
10 120000 RRRRRRRRRR 5 3 4 3 3 4 3 7 7 7 6 9 4 10 10 9 9 7 8 8 9 4 8 9 5 8 4 8 8 6 4 10 9 4 8 6 3 1 7 8 1 7 5 5 1 6 4 5 1 1 9 1 5 6 9 7 4 5 8 10 3 2 3 10 2 9 8 3 3 5 5 9 5 7 10 6 2 6 9 10 5 3 1 6 2 8 1 1 3 9 3 6 9 7 6 8 8 4 7 9 8 8 6 6 7 7 8 4 9 5 9 9 3 4 8 1 6 6 10 7 2 10 8 10 5 4 5 8 7 5 5 7 2 9 8...
output:
3 0 7 8 10 10 8 2 7 10 4 8 7 10 8 5 1 0 3 7 4 10 7 5 7 1 0 7 7 7 5 7 5 8 0 3 8 3 6 6 3 6 6 0 2 8 5 5 4 9 10 6 6 3 7 10 3 1 4 2 2 9 2 5 4 7 1 7 7 0 10 3 2 0 0 1 0 10 1 5 8 6 8 1 4 0 10 9 5 3 7 5 7 3 5 7 4 0 4 1 8 4 4 8 0 10 0 5 1 3 2 9 2 7 6 0 8 4 6 3 2 6 3 4 10 1 3 8 3 9 6 5 3 2 0 3 0 5 5 10 1 3 2 6...
result:
ok 120000 lines
Test #23:
score: 11
Accepted
time: 80ms
memory: 19528kb
input:
10 120000 RRRRRRRRRR 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...
output:
9 5 9 2 9 8 9 9 7 6 9 9 9 6 7 9 9 7 5 9 9 9 9 9 3 9 9 7 7 2 9 9 9 9 7 3 7 7 7 5 9 9 9 6 9 9 7 9 7 9 9 9 9 9 9 9 9 6 9 9 9 9 9 9 2 9 5 6 7 7 7 9 2 9 9 2 9 9 9 2 9 2 9 9 5 7 7 6 2 9 9 7 9 8 2 9 9 2 9 9 9 9 7 9 9 9 9 6 9 8 7 8 7 7 2 7 7 6 9 9 6 9 9 9 2 3 2 9 9 9 9 9 9 9 7 7 9 9 9 6 9 9 7 7 7 9 7 2 9 7 ...
result:
ok 120000 lines
Test #24:
score: 11
Accepted
time: 111ms
memory: 29752kb
input:
10 120000 RRRRRRRRRR 9 1 5 3 5 6 4 7 4 3 2 2 5 3 1 8 6 6 2 4 7 5 5 4 8 4 7 10 1 4 7 6 8 4 9 2 9 9 6 6 2 1 8 6 3 8 6 7 9 10 7 10 5 10 10 1 4 10 9 8 7 1 6 5 2 8 3 6 9 5 7 4 4 9 9 9 1 5 4 3 6 1 4 1 8 10 7 2 10 1 5 3 2 3 2 6 2 9 5 1 5 6 3 1 9 8 1 4 5 8 8 10 6 2 8 4 2 7 5 9 2 10 2 8 10 7 3 5 3 9 5 9 3 9 ...
output:
8 9 3 6 0 7 0 8 1 5 7 9 3 6 7 5 1 8 10 3 0 6 0 5 3 8 4 4 5 9 5 1 10 3 2 4 3 2 9 4 6 7 5 1 5 3 10 6 5 5 2 2 8 8 8 9 2 2 1 10 6 7 2 8 10 7 10 5 4 10 6 10 3 2 1 0 2 8 1 5 1 2 7 8 5 5 2 4 4 5 10 2 4 7 9 4 6 5 10 0 6 1 5 6 5 3 4 8 2 0 9 9 4 6 4 8 10 6 0 10 1 1 4 2 2 10 2 8 0 10 4 3 6 5 8 4 7 1 8 0 0 5 5 ...
result:
ok 120000 lines
Test #25:
score: 11
Accepted
time: 108ms
memory: 30040kb
input:
10 120000 RRRRRRRRRR 3 7 3 1 1 4 4 5 6 8 9 7 1 3 6 5 9 9 7 2 1 10 1 7 2 5 10 7 10 2 8 3 2 8 6 5 7 10 1 1 9 10 3 1 8 7 4 6 3 7 8 5 8 8 10 5 9 1 2 8 7 1 6 6 8 9 9 3 5 7 6 8 10 9 1 7 10 1 10 8 7 4 2 7 3 7 9 5 3 3 3 5 1 4 1 5 8 1 2 5 2 7 8 3 4 3 3 8 8 8 6 1 5 2 2 6 2 1 5 6 8 1 8 10 4 3 4 8 5 5 5 1 4 6 1...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 120000 lines
Subtask #5:
score: 26
Accepted
Test #26:
score: 26
Accepted
time: 748ms
memory: 55064kb
input:
120000 120000 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
output:
23441 85217 55120 85435 90828 27927 63967 41321 97520 63588 53976 9028 23460 86914 85688 112911 68792 102907 14973 38475 71931 17922 62077 53185 57121 43774 12583 21332 82917 28259 92209 28023 51606 65188 44768 34904 96969 18999 3653 3865 42795 86270 55638 108702 7871 68493 109086 40077 60406 38299 ...
result:
ok 120000 lines
Test #27:
score: 26
Accepted
time: 748ms
memory: 57312kb
input:
120000 120000 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
output:
2018 77981 92021 56481 116102 56745 67069 27266 30240 27284 13740 91171 108960 56234 109524 112538 55657 42972 50147 67079 7111 117407 39871 76936 45716 91668 95720 77368 97105 85437 79208 67078 48361 96495 85567 55381 19702 20133 30919 44934 86141 2061 51472 119392 58595 83081 98072 70266 44208 836...
result:
ok 119999 lines
Test #28:
score: 26
Accepted
time: 478ms
memory: 57080kb
input:
120000 120000 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
output:
74259 100417 22098 39799 56013 106728 100176 691 115099 118024 24216 53415 50787 78009 93371 114696 10114 113629 42308 99501 31925 2977 101690 15659 8409 87275 8847 117293 75701 3539 100844 31941 32198 3892 91695 29078 71179 92631 112213 43774 2220 17510 30742 69729 41857 84581 82608 73397 77072 935...
result:
ok 120000 lines
Test #29:
score: 26
Accepted
time: 537ms
memory: 56936kb
input:
120000 120000 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
output:
93180 85506 102645 62667 72263 51220 85142 81308 76933 106402 99293 27616 94064 104319 9479 119556 70424 76433 61917 110968 48994 108260 66210 40756 64358 89287 104790 100481 108187 20280 118127 29501 61041 59815 17775 87287 77037 95623 78604 90259 65811 33371 14467 12846 35149 18246 32718 84622 903...
result:
ok 120000 lines
Subtask #6:
score: 0
Wrong Answer
Test #30:
score: 0
Wrong Answer
time: 259ms
memory: 35492kb
input:
120000 120000 RRBBRBRBBBRBRRBRBRRRBRBRRBRRRBBRBBBBBBRBBRBRBRBRRBRBRBRRRBRBBBBRRBBRRBBRRRBRRBRBBRRRBBBRRBBBBRBBBRBBBRBBBRBBRBBBBRBBBBRRBRRRRRRRBRRRBRBBBRBBBBRBBRBRBRRBBRRBRBBBBRBBBRBBRRBBBBRBBBBRBRRBRBBRBBBBRRBBBBBBRBBRBBBBBBRBBRRRRRBBBRBBBRBRRBBRBRBRBBRRBRRBBBRBRBRRRBBRRBBRRRRBRRBBRRBBBBBBBRBBBRBBBR...
output:
23047 41041 26815 30547 27321 48693 25505 35216 45060 26815 24715 29403 26941 24596 25880 38342 41601 55024 26311 28112 28079 41952 29966 22280 28851 38095 47995 50394 25003 37533 40007 27609 43590 37446 49038 34296 27101 28733 36426 27224 36303 21835 48977 25926 33620 46897 43070 22744 27403 35055 ...
result:
wrong answer 1st lines differ - expected: '83101', found: '23047'
Subtask #7:
score: 0
Skipped
Dependency #1:
0%