QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#883706 | #8576. Symphony in c++ major | tassei903# | ML | 0ms | 3712kb | C++23 | 4.3kb | 2025-02-05 18:19:09 | 2025-02-05 18:19:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define ov4(a, b, c, d, name, ...) name
#define rep3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep2(i, a, b) rep3(i, a, b, 1)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(aaaaa, n)
#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define per(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define fore(e, v) for(auto&& e : v)
#define all(a) begin(a), end(a)
#define sz(a) (int)(size(a))
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define eb emplace_back
template<typename T, typename S> bool chmin(T& a, const S& b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S> bool chmax(T& a, const S& b) { return a < b ? a = b, 1 : 0; }
const int INF = 1e9 + 100;
const ll INFL = 3e18 + 100;
#define i128 __int128_t
struct _ {
_() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;
template<class S, S (*op)(S, S), S (*e)()> struct segtree {
segtree(int n) : segtree(vector<S>(n, e())) {}
segtree(const vector<S>& v) : n(sz(v)) {
s = bit_ceil(unsigned(n));
log = countr_zero(unsigned(s));
d = vector<S>(2 * s, e());
rep(i, n) d[s + i] = v[i];
per(i, s, 1) update(i);
}
void set(int p, S x) {
d[p += s] = x;
rep(i, 1, log + 1) update(p >> i);
}
S prod(int l, int r) const {
S sml = e(), smr = e();
l += s, r += s;
while(l < r) {
if(l & 1) sml = op(sml, d[l++]);
if(r & 1) smr = op(d[--r], smr);
l >>= 1, r >>= 1;
}
return op(sml, smr);
}
S all_prod() const { return d[1]; }
template<typename F> int max_right(int l, F f) const {
if(l == n) return n;
l += s;
S sm = e();
do {
while(~l & 1) l >>= 1;
if(!f(op(sm, d[l]))) {
while(l < s) {
l <<= 1;
if(f(op(sm, d[l]))) sm = op(sm, d[l++]);
}
return l - s;
}
sm = op(sm, d[l++]);
} while((l & -l) != l);
return n;
}
template<typename F> int min_left(int r, F f) const {
if(!r) return 0;
r += s;
S sm = e();
do {
r--;
while(r > 1 and r & 1) r >>= 1;
if(!f(op(d[r], sm))) {
while(r < s) {
r = (2 * r + 1);
if(f(op(d[r], sm))) sm = op(d[r--], sm);
}
return r + 1 - s;
}
sm = op(d[r], sm);
} while((r & -r) != r);
return 0;
}
private:
int n, s, log;
vector<S> d;
void update(int k) { d[k] = op(d[k * 2], d[k * 2 + 1]); }
};
const int M = 4;
struct S {
vector<int> to, cnt;
};
// a ... fl
// e ... r?
// i ... mt
// o ... ds
const vector<string> LL = {"fl", "r?", "mt", "ds"};
const string RR = "aeio";
S e() {
S z;
z.cnt.resize(1<<M);
z.to.resize(1<<M);
rep(i, 1<<M)z.cnt[i] = 0, z.to[i] = i;
return z;
}
S op(S x, S y) {
S z = e();
rep(i, 1 << M) {
z.to[i] = y.to[x.to[i]];
z.cnt[i] = x.cnt[i] + y.cnt[x.to[i]];
}
return z;
}
S get(char x) {
S z = e();
rep(i, 1 << M) {
int to = i, cnt = 0;
rep(j, M) {
if (LL[j][0] == x || LL[j][1] == x) to |= (1 << j);
if (i >> j & 1 && RR[j] == x) {
to = 0;
cnt = 1;
break;
}
}
z.to[i] = to;
z.cnt[i] = cnt;
}
return z;
}
void solve() {
int n, q;cin >> n >> q;
string s;cin >> s;
vector<S> a(n);
rep(i, n) a[i] = get(s[i]);
segtree<S, op, e> st(a);
rep(q) {
string t;cin >> t;
if (t == "?") {
int l, r;cin >> l >> r;
l--;
cout << r - l - 2 * st.prod(l, r).cnt[0] << endl;
}
else {
int l, r;cin >> l >> r;
l--;
string news;cin >> news;
rep(i, l, r) {
st.set(i, get(news[i-l]));
}
}
}
}
int main() {
// int T;cin >> T;
int T = 1;
while (T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
8 10 eldorado ? 1 3 ? 1 8 # 6 7 it ? 1 8 # 3 3 t ? 1 8 # 1 8 streamer ? 1 8 # 1 8 symphony ? 1 8
output:
3 4 6 6 6 6
result:
ok 6 numbers
Test #2:
score: -100
Memory Limit Exceeded
input:
500000 300000 rfsraltzititrofomloldlaefikdemaddaafmimiioiuaueiaedifacmxamttiiitaaltiiireexeafsaaraedosotlaioootaiosizlifiioadhnxiofsasaflleaiisstaotdlliulilxatrpdaraaraaoiaeoooiumwuumarlifesroloistedoaaieolisaoatamsredorrfiifaaidfeassfioaiasmstomasallsftsrfaiiirteomaeiirefldmlaoaofrxlaeuilioirafotoa...
output:
122151 133262 96922 55212 91547 148150 73505 4097 300798 54037 56741 265921 127608 170707 79236 209443 84732 83219 184042 77169 94062 172946 202750 97798 92449 67243 171524 145772 53856 165837 104913 179165 35068 55893 17287 74510 319355 244761 118810 162815 175172 136079 43107 237581 112894 48610 1...