QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#332229 | #7106. Infinite Parenthesis Sequence | yllcm | AC ✓ | 1244ms | 43072kb | C++14 | 1.9kb | 2024-02-19 12:21:06 | 2024-02-19 12:21:08 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
#define int long long
using namespace std;
inline int read() {
int x = 0; bool op = false;
char c = getchar();
while(!isdigit(c))op |= (c == '-'), c = getchar();
while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int N = 2e5 + 10;
int n, Q, m;
char s[N];
int st[N][25], f[N];
void build() {
m = 0;
for(int i = 0; i < n; i++)if(s[i] == '(')f[m++] = i;
for(int i = 0; i < m; i++)f[i + m] = f[i] + n;
// for(int i = 0; i < m * 2; i++)printf("%d ", f[i]); putchar('\n');
for(int i = 0; i < m * 2; i++)f[i] -= i * 2;
for(int i = 0; i < m * 2; i++)st[i][0] = f[i];
for(int j = 1; (1 << j) <= m * 2; j++)
for(int i = 0; i + (1 << j) - 1 < m * 2; i++)
st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
return ;
}
int query(int l, int r) {
int t = __lg(r - l + 1);
return min(st[l][t], st[r - (1 << t) + 1][t]);
}
int kth(int t, int k) {
int val = t + 2 * k;
if(t >= m) {
if(m * 2 <= n)t = m - 1;
else k = k + t - m + 1, t = m - 1;
}
int p = k / m; k %= m;
// cout << "qry:" << t << ' ' << k << ' ' << p << endl;
if(k < 0)p--, k += m;
return query(k, k + t) + (n - m * 2) * p + val;
}
int calc(int t, int r) {
int lef = -3e9, rig = 3e9;
while(lef + 1 < rig) {
int mid = lef + rig >> 1;
if(kth(t, mid) <= r)lef = mid;
else rig = mid;
}
// cout << t << ' ' << r << ' ' << lef << endl;
return lef;
}
void solve() {
scanf("%s", s);
n = strlen(s);
build();
Q = read();
while(Q--) {
int t = read(), l = read(), r = read();
printf("%lld\n", (m == 0 ? 0 : calc(t, r) - calc(t, l - 1)));
}
return ;
}
signed main() {
int test = read();
while(test--)solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5916kb
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: 226ms
memory: 5964kb
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: 1014ms
memory: 43072kb
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: 1244ms
memory: 42452kb
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