QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#163983 | #7106. Infinite Parenthesis Sequence | TsReaper | WA | 477ms | 12440kb | C++17 | 1.8kb | 2023-09-04 17:40:53 | 2023-09-04 17:40:54 |
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 div = (L >= 0 ? L / m : (L + 1) / m - 1);
int mod = (L % m + m) % m;
long long delta = n * div - 2 * div * m;
int len = R - L + 1, p = lg[len];
return min(rmq[p][mod], rmq[p][mod + 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);
if (m == 0) printf("0\n");
else 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: 100
Accepted
time: 2ms
memory: 8264kb
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 623 45 3
result:
ok 10 lines
Test #2:
score: -100
Wrong Answer
time: 477ms
memory: 12440kb
input:
5564 ()()(((() 16 0 -825489608 537105171 0 481386502 824237183 0 -32590250 515314371 0 -634830457 908018223 3 -494274112 299679416 125527658 81646800 208166552 632660143 -774899605 -551752339 4 -874787302 127206822 4 -102348267 122390255 2 -881139944 898929361 0 -656262874 -233671414 111787130 -5925...
output:
908396520 228567121 365269747 1028565788 529302353 84346502 148764845 667996084 149825682 1186712870 281727640 995600518 63752581 740373707 867951696 27044667 530591272 345487789 415550920 701803793 413364407 187916462 386485772 125057026 296666743 470522533 367131179 635722815 58970215 379425066 18...
result:
wrong answer 32759th lines differ - expected: '33483986', found: '33483987'