結果
| 問題 | No.2992 Range ABCD String Query |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-30 18:22:58 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 808 ms / 6,000 ms |
| + 408µs | |
| コード長 | 5,640 bytes |
| 記録 | |
| コンパイル時間 | 5,643 ms |
| コンパイル使用メモリ | 407,752 KB |
| 実行使用メモリ | 94,292 KB |
| 最終ジャッジ日時 | 2026-11-30 18:23:35 |
| 合計ジャッジ時間 | 35,633 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge6_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 41 |
ソースコード
// Library Codes are in: https://github.com/reinsirk/sirkit-cpp-library
// GCC バグ対策 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128217
#pragma GCC optimize("no-tree-loop-vectorize")
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define SKIP_RUNTIME_CHECKS
constexpr int64_t INF = static_cast<int64_t>(1) << 60;
namespace sirkit
{
#ifndef SIRKIT_INF_DEFINED
#define SIRKIT_INF_DEFINED
inline constexpr std::int64_t kInf = std::int64_t{1} << 60;
#endif
#ifndef SIRKIT_UNWEIGHTED_GRAPH_DEFINED
#define SIRKIT_UNWEIGHTED_GRAPH_DEFINED
using Graph = std::vector<std::vector<int>>;
#endif
#ifndef SIRKIT_GRAPH_TYPES_DEFINED
#define SIRKIT_GRAPH_TYPES_DEFINED
struct Edge
{
int to;
std::int64_t w;
Edge(int destination, std::int64_t weight) : to(destination), w(weight)
{
}
};
using WGraph = std::vector<std::vector<Edge>>;
#endif
#ifndef SIRKIT_CHMIN_DEFINED
#define SIRKIT_CHMIN_DEFINED
#define SIRKIT_TEMP_DEFINE_CHMIN
template <class T>
constexpr bool chmin(T &a, T b);
#endif
#ifndef SIRKIT_CHMAX_DEFINED
#define SIRKIT_CHMAX_DEFINED
#define SIRKIT_TEMP_DEFINE_CHMAX
template <class T>
constexpr bool chmax(T &a, T b);
#endif
#ifndef SIRKIT_POW64I_DEFINED
#define SIRKIT_POW64I_DEFINED
#define SIRKIT_TEMP_DEFINE_POW64I
constexpr std::uint64_t pow64i(std::uint64_t x, std::uint64_t n);
#endif
#ifndef SIRKIT_IS_MUL_OVERFLOW_DEFINED
#define SIRKIT_IS_MUL_OVERFLOW_DEFINED
#define SIRKIT_TEMP_DEFINE_IS_MUL_OVERFLOW
constexpr bool is_mul_overflow(std::int64_t a, std::int64_t b);
#endif
} // namespace sirkit
using namespace sirkit;
struct S
{
array<array<int64_t, 4>, 4> v;
};
S e()
{
S e;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
e.v.at(i).at(j) = 0;
}
}
return e;
}
S op(S a, S b)
{
S ret = e();
for (int i = 0; i < 4; i++)
{
for (int j = i; j < 4; j++)
{
for (int u = j; u < 4; u++)
{
for (int k = u; k < 4; k++)
{
chmax(ret.v.at(i).at(k), a.v.at(i).at(j) + b.v.at(u).at(k));
}
}
}
}
return ret;
}
int main()
{
std::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++)
{
v.at(i) = e();
for (int j = 0; j < 4; j++)
{
for (int k = 0; k <= j; k++)
{
if (s.at(i) == 'A' + j)
{
v.at(i).v.at(k).at(j) = 1;
}
else
{
v.at(i).v.at(k).at(j) = 0;
}
}
}
}
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--;
v.at(x) = e();
s.at(x) = c;
for (int j = 0; j < 4; j++)
{
for (int k = 0; k <= j; k++)
{
if (s.at(x) == 'A' + j)
{
v.at(x).v.at(k).at(j) = 1;
}
else
{
v.at(x).v.at(k).at(j) = 0;
}
}
}
sg.set(x, v.at(x));
}
else
{
int l, r;
cin >> l >> r;
l--;
auto x = sg.prod(l, r);
int64_t ans = 0;
for (auto &y : x.v)
{
for (auto z : y)
{
chmax(ans, z);
}
}
cout << r - l - ans << endl;
}
}
return 0;
}
namespace sirkit
{
#ifdef SIRKIT_TEMP_DEFINE_CHMIN
#undef SIRKIT_TEMP_DEFINE_CHMIN
template <class T>
constexpr bool chmin(T &a, T b)
{
if (b < a)
{
a = b;
return true;
}
return false;
}
#endif
#ifdef SIRKIT_TEMP_DEFINE_CHMAX
#undef SIRKIT_TEMP_DEFINE_CHMAX
template <class T>
constexpr bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
#endif
#ifdef SIRKIT_TEMP_DEFINE_POW64I
#undef SIRKIT_TEMP_DEFINE_POW64I
constexpr std::uint64_t pow64i(std::uint64_t x, std::uint64_t n)
{
std::uint64_t result = 1;
while (n != 0)
{
if ((n & 1) != 0)
{
result *= x;
}
n >>= 1;
if (n != 0)
{
x *= x;
}
}
return result;
}
#endif
#ifdef SIRKIT_TEMP_DEFINE_IS_MUL_OVERFLOW
#undef SIRKIT_TEMP_DEFINE_IS_MUL_OVERFLOW
constexpr bool is_mul_overflow(std::int64_t a, std::int64_t b)
{
#if (defined(__GNUC__) || defined(__clang__)) && !defined(SIRKIT_FORCE_STANDARD_MUL_OVERFLOW)
std::int64_t product;
return __builtin_mul_overflow(a, b, &product);
#else
// 最小負数の絶対値も符号なし演算で安全に求める。
const std::uint64_t ua = a < 0 ? std::uint64_t{0} - static_cast<std::uint64_t>(a) : static_cast<std::uint64_t>(a);
const std::uint64_t ub = b < 0 ? std::uint64_t{0} - static_cast<std::uint64_t>(b) : static_cast<std::uint64_t>(b);
const std::uint64_t limit = (a < 0) != (b < 0)
? std::uint64_t{1} << 63
: static_cast<std::uint64_t>(std::numeric_limits<std::int64_t>::max());
return ub != 0 && ua > limit / ub;
#endif
}
#endif
} // namespace sirkit