QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#163966 | #7106. Infinite Parenthesis Sequence | TsReaper | WA | 1ms | 8340kb | C++17 | 1.7kb | 2023-09-04 17:25:58 | 2023-09-04 17:25:59 |
Judging History
answer
#include <bits/stdc++.h>
#define MAXN ((int) 1e5)
#define MAXP 20
using namespace std;
int n, m, q;
char s[MAXN + 10];
int lg[MAXN + 10], rmq[MAXP][MAXN * 2 + 10];
void preRmq() {
m = 0;
for (int i = 0; i < n; i++) if (s[i] == '(') rmq[0][m++] = i;
for (int i = m; i < m * 2; i++) rmq[0][i] = rmq[0][i - m] + n;
for (int i = 0; i < m * 2; i++) rmq[0][i] -= i * 2;
for (int p = 1; p < MAXP; p++) for (int i = 0, ii = (1 << p) - 1; ii < m * 2; i++, ii++) {
int j = i + (1 << (p - 1));
rmq[p][i] = min(rmq[p - 1][i], rmq[p - 1][j]);
}
}
long long calc(long long K, long long i) {
long long L, R;
if (m * 2 <= n) {
L = i;
R = min(i + K, L + m - 1);
} else {
R = i + K;
L = max(i, R - m + 1);
}
long long delta = n * (L / m) - 2 * (L / m) * m;
int len = R - L + 1, p = lg[len];
return min(rmq[p][L % m], rmq[p][L % m + len - (1 << p)]) + delta + K + 2 * i;
}
long long query(long long K, long long lim) {
long long head = -1e18, tail = 1e18;
while (head < tail) {
long long mid = (head + tail + 1) >> 1;
if (calc(K, mid) <= lim) head = mid;
else tail = mid - 1;
}
return head;
}
void solve() {
scanf("%s", s); n = strlen(s);
preRmq();
scanf("%d", &q);
while (q--) {
long long K, l, r; scanf("%lld%lld%lld", &K, &l, &r);
long long len = r - l;
l = (l % n + n) % n + n;
r = l + len;
printf("%lld\n", query(K, r) - query(K, l - 1));
}
}
int main() {
lg[1] = 0;
for (int i = 2; i <= MAXN; i++) lg[i] = lg[i >> 1] + 1;
int tcase; scanf("%d", &tcase);
while (tcase--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 8340kb
input:
3 (()) 3 0 -3 2 1 -2 3 2 0 0 ))()( 3 0 -3 4 2 1 3 3 -4 -1 ))()(()( 4 1234 -5678 9012 123 -456 789 12 -34 56 1 -2 3
output:
3 3 0 4 1 1 7345 622 45 3
result:
wrong answer 8th lines differ - expected: '623', found: '622'