QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378246 | #8576. Symphony in c++ major | ucup-team2894# | ML | 0ms | 3564kb | C++20 | 2.8kb | 2024-04-06 10:17:07 | 2024-04-06 10:17:08 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;
using pii = pair<int,int>;
using ll = long long;
using pll = pair<ll,ll>;
using vi = vector<int>;
using ld = long double;
#define all(x) (x).begin(), (x).end()
const int maxn = 1e6+10, inf = 1e9+100;
const ll linf = 1e18+100;
const int mod = 998244353;
const ld eps = 1e-9;
const ld PI = acos(-1.L);
using Matrix = array<array<int,8>,8>;
using Vector = array<int,8>;
string tar[8] = {"", "do", "re", "mi", "fa", "so", "la", "ti"};
Matrix mval[26];
Matrix getmat(char c) {
Matrix m;
for(int i=0;i<8;i++)for(int j=0;j<8;j++)m[i][j] = -inf;
for(int i=0;i<8;i++)m[i][i] = 0;
for(int i=1;i<8;i++){
if(tar[i][0] == c) m[i][0] = 1;
if(tar[i][1] == c) m[0][i] = 1;
}
return m;
}
Matrix mult(const Matrix& a, const Matrix& b) {
Matrix c;
for(int i=0;i<8;i++)for(int j=0;j<8;j++)c[i][j] = -inf;
for(int i=0;i<8;i++)for(int j=0;j<8;j++)for(int k=0;k<8;k++){
c[i][k]=max(c[i][k],a[i][j]+b[j][k]);
}
return c;
}
Vector mult(const Matrix& a, const Vector& b) {
Vector c;
for(int i=0;i<8;i++)c[i] = -inf;
for(int i=0;i<8;i++)for(int j=0;j<8;j++){
c[i]=max(c[i],a[i][j]+b[j]);
}
return c;
}
Matrix seg[maxn*4];
string s;
void init(int x,int l,int r) {
if(l==r) seg[x] = mval[s[l]-'a'];
else {
int mid = (l+r)/2;
init(x*2,l,mid);
init(x*2+1,mid+1,r);
seg[x] = mult(seg[x*2+1],seg[x*2]);
}
}
void upd(int x,int l,int r,int a, char c) {
if(l == r ) {
seg[x] = mval[c - 'a'];
}
else {
int mid = (l+r)/2;
if(a<=mid)upd(x*2,l,mid,a,c);
else upd(x*2+1,mid+1,r,a,c);
seg[x] = mult(seg[x*2+1],seg[x*2]);
}
}
Vector ans;
void qu(int x,int l,int r,int a,int b) {
if(l==a&&r==b) {
ans = mult(seg[x], ans);
}
else {
int mid = (l+r)/2;
if(b<=mid)qu(x*2,l,mid,a,b);
else if(a>mid)qu(x*2+1,mid+1,r,a,b);
else {
qu(x*2,l,mid,a,mid);
qu(x*2+1,mid+1,r,mid+1,b);
}
}
}
void solve(){
int n,q;
cin >> n >> q;
cin >> s;
for(int i=0;i<26;i++){
mval[i] = getmat('a'+i);
}
init(1,0,n-1);
for(int i=0;i<q;i++){
string ty;
cin >> ty;
if(ty == "?") {
int a,b;
cin >> a >> b;
a--,b--;
ans[0] = 0;
for(int i=1;i<8;i++)ans[i] = -inf;
qu(1,0,n-1,a,b);
cout << (b-a+1) - ans[0] << "\n";
}
else {
int a,b;
string t;
cin >> a >> b >> t;
// cerr << a << " " << b << " " << t << endl;
a--,b--;
for(int i=0;i<t.size();i++){
// cerr << a << " " << t[a+i] << endl;
upd(1,0,n-1,a+i,t[i]);
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout<<fixed;
cout.precision(20);
cerr << fixed;
cerr.precision(5);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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...