QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245351 | #7106. Infinite Parenthesis Sequence | FISHER_ | AC ✓ | 715ms | 19872kb | C++20 | 1.5kb | 2023-11-09 20:55:47 | 2023-11-09 20:55:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int maxn = 100000;
int n, c;
char str[maxn + 5];
int f0[2 * maxn + 5][20];
int lg2[2 * maxn + 5];
inline int qMin(int l, int r) {
int t = lg2[r - l + 1];
return min(f0[l][t], f0[r - (1 << t) + 1][t]);
}
inline int f(int i, int t) {
int l, r;
if (n - 2 * c > 0) l = i, r = i + min(t, c - 1);
else r = i + t, l = max(i, r - c + 1);
int id = (l - 1) / c;
l -= id * c, r -= id * c;
return qMin(l, r) + id * (n - 2 * c) + t + 2 * i;
}
inline i64 q(i64 x, int k) {
int fir = f(1, k);
i64 rs = (x - fir) / n * c;
x = (x - fir) % n + fir;
int l = 0, r = c;
while (l < r) {
int mid = (l + r + 1) / 2;
if (f(mid, k) <= x) l = mid;
else r = mid - 1;
}
return rs + l;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%s", str);
n = strlen(str), c = 0;
for (int i = 0; i < n; i++)
if (str[i] == '(') f0[++c][0] = i;
for (int i = 1; i <= c; i++) f0[i][0] -= 2 * i;
for (int i = 1; i <= c; i++) f0[i + c][0] = f0[i][0] + n - 2 * c;
for (int i = 2 * c; i; i--)
for (int j = 1; i + (1 << j) - 1 <= 2 * c; j++) f0[i][j] = min(f0[i][j - 1], f0[i + (1 << (j - 1))][j - 1]);
for (int i = 2; i <= 2 * c; i++) lg2[i] = lg2[i >> 1] + 1;
int Q;
scanf("%d", &Q);
for (int i = 1; i <= Q; i++) {
i64 l, r; int k;
scanf("%d%lld%lld", &k, &l, &r);
l += 2000000000LL * n, r += 2000000000LL * n;
printf("%lld\n", q(r, k) - q(l - 1, k));
}
}
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5640kb
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: 0
Accepted
time: 120ms
memory: 3920kb
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:
ok 271661 lines
Test #3:
score: 0
Accepted
time: 601ms
memory: 19872kb
input:
7 ((()(((()(((()((()((()((()(((()(((()((()(((()(((()((()(((()(((()(((()(((()((()(((()((()((()(((()(((()(((()((()((()(((()((()((()(((()(((()(((()((()(((()((()(((()((()((()(((()(((()(((()(((()((()(((()(((()((()((()((()(((()(((()((()(((()(((()(((()((()(((()(((()((()((()(((()(((()(((()((()((()(((()((()(...
output:
185704843 446800089 255099554 1156402 212636323 416191407 12472890 247228052 489620931 107469522 16222287 341270888 29184920 107393597 163613521 175919552 118376824 76183214 805506070 206363476 326077675 54361969 121810843 684646392 716061472 697723268 23956954 588434738 4870237 305505833 489380166 ...
result:
ok 700000 lines
Test #4:
score: 0
Accepted
time: 715ms
memory: 19804kb
input:
5571 ()()(((() 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:
ok 971661 lines
Extra Test:
score: 0
Extra Test Passed