QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#379214 | #8576. Symphony in c++ major | ucup-team1516# | TL | 0ms | 3556kb | C++20 | 6.7kb | 2024-04-06 16:38:04 | 2024-04-06 16:38:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
if(x > y) {
x = y;
return true;
} else return false;
}
template<class T> bool chmax(T& x, T y){
if(x < y) {
x = y;
return true;
} else return false;
}
// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )
#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )
#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)
// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)
// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)
// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c)
// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = b - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = b - 1; i >= (ll)(a); i -= c)
// for_earh
#define fore(e, v) for (auto&& e : v)
// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
template<class T, T(* op)(T, T), T(* e)()>
struct segment_tree {
private:
int n, tn;
vector<T> node;
public:
segment_tree(int _n, vector<T> a = {}) : tn(_n) {
n = 1;
while (n < _n) n *= 2;
node.resize(2 * n, e());
if (!a.empty()) {
for (int i = 0; i < (int)a.size(); i++) {
update(i, a[i]);
}
}
}
void update(int i, T val) {
i += n;
node[i] = val;
while (i / 2) {
i /= 2;
node[i] = op(node[i * 2], node[i * 2 + 1]);
}
}
T get_val(int l, int r) {
l += n;
r += n;
T lval = e(), rval = e();
while (l < r) {
if (l & 1) lval = op(lval, node[l++]);
if (r & 1) rval = op(node[--r], rval);
l /= 2, r /= 2;
}
return op(lval, rval);
}
template<class F>
int right_search(int i, F f) {
int ret = i, len = 1;
i += n;
T val = e();
while (ret < n) {
if (i & 1) {
if (!f(op(val, node[i]))) break;
val = op(val, node[i]);
ret += len;
i++;
}
len *= 2, i /= 2;
}
if (ret == n) return tn;
while (len > 1) {
len /= 2, i *= 2;
if (f(op(val, node[i]))) {
val = op(val, node[i]);
ret += len;
i++;
}
}
return min(ret, tn);
}
template<class F>
int left_search(int i, F f) {
int ret = i, len = 1;
i += n;
T val = e();
while (ret > 0) {
if (i & 1) {
i--;
if (!f(op(node[i], val))) break;
val = op(node[i], val);
ret -= len;
}
len *= 2, i /= 2;
}
if (ret == 0) return 0;
while (len > 1) {
len /= 2, i = i * 2 + 1;
if (f(op(node[i], val))) {
val = op(node[i], val);
ret -= len;
i--;
}
}
return ret;
}
};
// 表
int idx[26];
int nxt[26];
struct node {
int dp[6][8];
node() {
rep (i, 6) rep (j, 8) dp[i][j] = -inf;
}
};
node op(node a, node b) {
node ret;
rep (i, 6) rep (j, 8) {
chmax(ret.dp[i][j], max(a.dp[i][j], b.dp[i][j]));
}
// くっつける
rep (i, 6) rep (j, 7) rep (k, 8) {
if (a.dp[i][j] == -inf || b.dp[nxt[j]][k] == -inf) continue;
chmax(ret.dp[i][k], a.dp[i][j] + b.dp[nxt[j]][k] + 2);
}
vector<int> mxa(6, -inf), mxb(8, -inf);
rep (i, 6) rep (j, 8) {
chmax(mxa[i], a.dp[i][j]);
chmax(mxb[j], b.dp[i][j]);
}
rep (i, 6) rep (j, 8) {
chmax(ret.dp[i][j], mxa[i] + mxb[j]);
}
return ret;
}
node e() {
return node();
}
int n, q;
string s;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
cin >> n >> q >> s;
segment_tree<node, op, e> st(n);
string con = "drmfslt";
string to = "oeiaoai";
string vow = "aiueo";
set<int> cons, vows;
rep (i, vow.size()) {
vows.insert(vow[i] - 'a');
idx[vow[i] - 'a'] = i;
}
rep (i, con.size()) {
cons.insert(con[i] - 'a');
idx[con[i] - 'a'] = i;
nxt[i] = idx[to[i] - 'a'];
}
rep (i, n) {
int ci = s[i] - 'a';
node nd;
if (cons.find(ci) != cons.end()) {
nd.dp[5][idx[ci]] = 0;
}
if (vows.find(ci) != vows.end()) {
nd.dp[idx[ci]][7] = 0;
}
st.update(i, nd);
}
rep (_, q) {
char c;
int l, r;
cin >> c >> l >> r;
l--;
if (c == '?') {
node val = st.get_val(l, r);
int mx = 0;
rep (i, 6) rep (j, 8) chmax(mx, val.dp[i][j]);
cout << r - l - mx << '\n';
} else {
string t;
cin >> t;
rep (i, t.size()) {
int ci = t[i] - 'a';
node nd;
if (cons.find(ci) != cons.end()) {
nd.dp[5][idx[ci]] = 0;
}
if (vows.find(ci) != vows.end()) {
nd.dp[idx[ci]][7] = 0;
}
st.update(l + i, nd);
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
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
Time 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...