QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#378755 | #8576. Symphony in c++ major | ucup-team3396# | ML | 1ms | 8016kb | C++14 | 2.3kb | 2024-04-06 14:30:29 | 2024-04-06 14:30:30 |
Judging History
answer
#include<bits/stdc++.h>
typedef int ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
inline void write(ll x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
}
const ll N=5e5+9;
ll n,q,rev[N],a[N];
struct M{
ll a[12][12];
void clear(){
rep(i,0,11){
rep(j,0,11)a[i][j]=1e7;
}
}
}tr[N<<2],trans[12];
M operator*(const M&a,const M&b){
M c;c.clear();
rep(k,0,11){
rep(i,0,11){
rep(j,0,11)c.a[i][j]=min(c.a[i][j],a.a[i][k]+b.a[k][j]);
}
}
return c;
}
void Pushup(ll x){
tr[x]=tr[x<<1]*tr[x<<1|1];
}
void Build(ll x,ll l,ll r){
if(l==r){
tr[x]=trans[a[l]];
return ;
}
ll mid=(l+r)>>1;
Build(x<<1,l,mid);
Build(x<<1|1,mid+1,r);
Pushup(x);
}
void Upd(ll x,ll l,ll r,ll ql,ll qr){
if(l>qr||r<ql)return ;
if(l==r){
tr[x]=trans[a[l]];
return ;
}
ll mid=(l+r)>>1;
Upd(x<<1,l,mid,ql,qr);
Upd(x<<1|1,mid+1,r,ql,qr);
Pushup(x);
}
M Query(ll x,ll l,ll r,ll ql,ll qr){
if(ql<=l&&r<=qr)return tr[x];
ll mid=(l+r)>>1;
if(qr<=mid)return Query(x<<1,l,mid,ql,qr);
if(ql>mid)return Query(x<<1|1,mid+1,r,ql,qr);
return Query(x<<1,l,mid,ql,qr)*Query(x<<1|1,mid+1,r,ql,qr);
}
char s[N];
bool Med;
int main(){
cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
n=read(),q=read();
scanf("%s",s+1);
rev['d']=1,rev['o']=2;
rev['r']=3,rev['e']=4;
rev['m']=5,rev['i']=6;
rev['f']=7,rev['a']=8;
rev['s']=9;
rev['l']=10;
rev['t']=11;
rep(i,0,11)trans[i].clear();
rep(j,0,11){
rep(i,0,11)trans[j].a[i][i]=1;
}
rep(j,1,11){
trans[j].a[0][j]=0;
}
trans[2].a[1][0]=0;
trans[4].a[3][0]=0;
trans[6].a[5][0]=0;
trans[8].a[7][0]=0;
trans[2].a[9][0]=0;
trans[8].a[10][0]=0;
trans[6].a[11][0]=0;
rep(i,1,n)a[i]=rev[s[i]];
Build(1,1,n);
while(q--){
char op[3];
scanf("%s",op);
if(op[0]=='?'){
ll l=read(),r=read();
M o=Query(1,1,n,l,r);
write(o.a[0][0]),putchar('\n');
}
else {
ll l=read(),r=read();
scanf("%s",s+1);
rep(i,l,r)a[i]=rev[s[i-l+1]];
Upd(1,1,n,l,r);
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 8016kb
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...