結果
| 問題 | No.3652 Range Bracket Sequence |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-29 23:36:09 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,173 bytes |
| 記録 | |
| コンパイル時間 | 4,482 ms |
| コンパイル使用メモリ | 357,136 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2026-08-29 23:36:24 |
| 合計ジャッジ時間 | 11,181 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 44 |
ソースコード
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
constexpr int64_t INF = static_cast<int64_t>(1) << 60;
template <class T>
bool chmin(T &a, T b);
template <class T>
bool chmax(T &a, T b);
// x^nを高速で計算する
uint64_t pow64i(uint64_t x, uint64_t n);
// cout << std::fixed << std::setprecision(15);
using Graph = vector<vector<int>>;
#include <atcoder/segtree>
struct S
{
int l = 0, r = 0;
int ans = 0;
};
S op(S a, S b)
{
return {a.l + b.l - min(a.l, b.r), a.r + b.r - min(a.l, b.r), a.ans + b.ans + min(a.l, b.r) * 2};
}
S e()
{
return {0, 0, 0};
}
int main()
{
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, q;
cin >> n >> q;
string s;
cin >> s;
vector<S> v(n);
for (int i = 0; i < n; i++)
{
if (s.at(i) == '(')
{
v.at(i).l++;
}
else
{
v.at(i).r++;
}
}
atcoder::segtree<S, op, e> sg(v);
for (; q > 0; q--)
{
int t;
cin >> t;
if (t == 1)
{
int x;
char c;
cin >> x >> c;
x--;
if (s.at(x) != c)
{
s.at(x) = c;
if (c == '(')
{
sg.set(x, {1, 0, 0});
}
else
{
sg.set(x, {0, 1, 0});
}
}
}
else
{
int l, r;
cin >> l >> r;
l--;
cout << sg.prod(l, r).ans << endl;
}
}
return 0;
}
template <class T>
bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <class T>
bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
uint64_t pow64i(uint64_t x, uint64_t n)
{
uint64_t ret = 1;
while (n > 0)
{
if (n & 1)
ret *= x; // n の最下位bitが 1 ならば x^(2^i) をかける
x *= x;
n >>= 1; // n を1bit 左にずらす
}
return ret;
}