QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#246396 | #7106. Infinite Parenthesis Sequence | dieselhuang | TL | 1ms | 6004kb | C++14 | 1.6kb | 2023-11-10 19:46:56 | 2023-11-10 19:46:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int inf = 1e9;
int n, m, d, f[200010][20], lg[200010];
char a[100010];
int qmd(int x, int m){ x = x % m + m; return x >= m ? x - m : x; }
int qry(int l, int r){ int i = lg[r - l + 1]; return min(f[l][i], f[r - (1 << i) + 1][i]); }
ll calc(int k, int x){
int i;
if(k < m || d >= 0){
i = qmd(x, m);
return qry(i, i + min(k, m - 1)) + ((ll)x - i) / m * d + x + x + k;
}else{
int y = x + k - m + 1; i = qmd(y, m);
return qry(i, i + m - 1) + ((ll)y - i) / m * d + x + x + k;
}
}
int g(int k, int x){
int l = -inf, r = max(inf, x + k), md;
while(l < r){
md = l + r; md = (md >= 0 ? md + 1 >> 1 : -(-md >> 1));
if(calc(k, md) <= x) l = md;
else r = md - 1;
}
return l;
}
void solve(){
int q, i, j, k, l, r;
for(i = 0; a[i] != '\0'; i++) a[i] = '\0';
scanf(" %s", a);
for(i = 0; a[i] != '\0'; i++) ;
n = i;
for(i = 0, m = 0; i < n; i++){
if(a[i] == '('){ f[m][0] = i - (m << 1); m++; }
}
if(m == 0){
scanf("%d", &q);
while(q--){ scanf("%d%d%d", &k, &l, &r); printf("0\n"); }
return;
}
d = n - (m << 1);
lg[0] = -1;
for(i = 1; i <= m << 1; i++) lg[i] = lg[i >> 1] + 1;
for(i = 0; i < m; i++) f[i + m][0] = f[i][0] + d;
for(i = (m << 1) - 1; i >= 0; i--){
for(j = 1; i + (1 << j) <= m << 1; j++) f[i][j] = min(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
}
scanf("%d", &q);
while(q--){
scanf("%d%d%d", &k, &l, &r);
printf("%d\n", g(k, r) - g(k, l - 1));
}
}
int main()
{
memset(a, '\0', sizeof(a));
int t;
scanf("%d", &t);
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6004kb
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
Time Limit Exceeded
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...