結果
| 問題 |
No.3208 Parse AND OR Affection
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2025-07-19 15:21:54 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 66 ms / 5,000 ms |
| コード長 | 1,834 bytes |
| コンパイル時間 | 3,224 ms |
| コンパイル使用メモリ | 303,164 KB |
| 実行使用メモリ | 15,672 KB |
| 最終ジャッジ日時 | 2025-07-19 15:22:00 |
| 合計ジャッジ時間 | 5,381 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
struct S {
bool to[2];
int into[2], outfrom[2];
ll res;
};
S op(S x, S y) {
S z{};
rep(i, 2) {
z.to[i] = y.to[x.to[i]];
z.into[y.to[i]] += x.into[i];
z.into[i] += y.into[i];
z.outfrom[i] += x.outfrom[i];
z.outfrom[i] += y.outfrom[x.to[i]];
z.res += (ll)x.into[i] * y.outfrom[i];
}
z.res += x.res + y.res;
return z;
}
S e() {
S s{};
rep(i, 2) s.to[i] = i;
return s;
}
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
string x;
cin >> x;
segtree<S, op, e> seg([&]() {
vector<S> init((n + 1) / 2);
for (int i = -1; i < n; i += 2) {
S s{};
char op = i == -1 ? '+' : x[i];
bool val = x[i+1] == 'T';
rep(i, 2) {
int j = op == '+' ? i | val : op == '*' ? i & val : i ^ val;
s.to[i] = j;
s.outfrom[i] = j;
}
s.into[val] = 1;
s.res = val;
init[(i + 1) / 2] = s;
}
return init;
}());
rep(_, q) {
int l, r;
cin >> l >> r;
l--;
l = (l + 1) / 2;
r = (r + 1) / 2;
cout << seg.prod(l, r).res << '\n';
}
}
Kude