QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#421804 | #7106. Infinite Parenthesis Sequence | pandapythoner | TL | 0ms | 3672kb | C++14 | 1.4kb | 2024-05-26 05:42:07 | 2024-05-26 05:42:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const ll inf = 1e18;
mt19937 rnd(234);
int n;
string s;
int q;
vector<ll> p;
ll get_val(ll i) {
ll x = ((i % n) + n) % n;
return p[x] + ((i - x) / n) * (p[n] - p[0]);
}
ll get_val_at_time(ll i, ll t) {
ll rs = -inf;
for (ll j = i - t; j <= i + t; j += 2) {
rs = max(rs, get_val(j) - t);
}
return rs;
}
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int t;
cin >> t;
for (int itr = 0; itr < t; itr += 1) {
cin >> s;
n = (int)s.size();
p.resize(n + 1);
p[0] = 0;
for (int i = 0; i < n; i += 1) {
p[i + 1] = p[i] + (s[i] == '(' ? 1 : -1);
}
cin >> q;
for (int i = 0; i < q; i += 1) {
ll t, l, r;
cin >> t >> l >> r;
++r;
ll balance = get_val_at_time(r, t) - get_val_at_time(l, t);
ll rs = (balance + r - l) / 2;
cout << rs << "\n";
}
}
return 0;
}
/*
1
))()(
3
0 -3 4
2 1 3
3 -4 -1
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
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3672kb
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...