QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67364 | #5098. 第一代图灵机 | aoui | 10 | 132ms | 10700kb | C++14 | 3.5kb | 2022-12-10 12:12:32 | 2022-12-10 12:12:33 |
Judging History
answer
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e5+5;
int n,m,Q,a[N],c[N],cnt,tm[N<<2],tl[N<<5],ls[N<<5],rs[N<<5],rt[N],tc[N<<2],tag,tt[N];
struct node{int bz,cl,cr,sl,sr,sum,ans;}t[N<<2];
node comb(node l,node r)
{
node res;
res.sum=l.sum+r.sum;
res.ans=max(l.ans,r.ans);
if(l.cr!=r.cl)
{
res.ans=max(res.ans,l.sr+r.sl);
if(l.bz&&r.bz)res.bz=1;
}
res.cl=l.cl;
res.cr=r.cr;
res.sl=l.sl;
res.sr=r.sr;
if(l.bz&&l.cr!=r.cl)res.sl=max(res.sl,l.sl+r.sl);
if(r.bz&&l.cr!=r.cl)res.sr=max(res.sr,r.sr+l.sr);
return res;
}
void build(int v,int l,int r)
{
if(l==r)
{
t[v]=(node){1,c[l],c[l],a[l],a[l],a[l],a[l]};
return;
}
int mid=l+r>>1;
build(v<<1,l,mid);
build(v<<1|1,mid+1,r);
t[v]=comb(t[v<<1],t[v<<1|1]);
}
void upt(int v,int l,int r,int x,int y)
{
if(l==r)
{
t[v].cl=t[v].cr=y;
return;
}
int mid=l+r>>1;
if(x<=mid)upt(v<<1,l,mid,x,y);
else upt(v<<1|1,mid+1,r,x,y);
t[v]=comb(t[v<<1],t[v<<1|1]);
}
node que(int v,int l,int r,int x,int y)
{
if(l>=x&&r<=y)return t[v];
int mid=l+r>>1;
if(y<=mid)return que(v<<1,l,mid,x,y);
if(x>mid)return que(v<<1|1,mid+1,r,x,y);
node resl=que(v<<1,l,mid,x,y),resr=que(v<<1|1,mid+1,r,x,y);
return comb(resl,resr);
}
void chg(int v,int l,int r,int x,int y)
{
if(l==r)
{
tm[v]=y;
return;
}
int mid=l+r>>1;
if(x<=mid)chg(v<<1,l,mid,x,y);
else chg(v<<1|1,mid+1,r,x,y);
tm[v]=max(tm[v<<1],tm[v<<1|1]);
}
int ask(int v,int l,int r,int x,int y)
{
if(l>=x&&r<=y)return tm[v];
int mid=l+r>>1,res=0;
if(x<=mid)res=max(res,ask(v<<1,l,mid,x,y));
if(mid<y)res=max(res,ask(v<<1|1,mid+1,r,x,y));
return res;
}
void ins(int &v,int l,int r,int x,int y)
{
if(!v)v=++cnt;
if(l==r)
{
if(y)tl[v]=x;
else tl[v]=n+1;
return;
}
int mid=l+r>>1;
if(x<=mid)ins(ls[v],l,mid,x,y);
else ins(rs[v],mid+1,r,x,y);
tl[v]=min(tl[ls[v]],tl[rs[v]]);
}
int find(int v,int l,int r,int x)
{
if(!v)return 0;
if(tl[v]>n)return 0;
int mid=l+r>>1;
if(x<=mid)return find(ls[v],l,mid,x);
if(tl[rs[v]]<=x)return find(rs[v],mid+1,r,x);
return find(ls[v],l,mid,x);
}
void cao(int v,int l,int r,int x,int y)
{
if(l==r)
{
tc[v]=y;
return;
}
int mid=l+r>>1;
if(x<=mid)cao(v<<1,l,mid,x,y);
else cao(v<<1|1,mid+1,r,x,y);
tc[v]=max(tc[v<<1],tc[v<<1|1]);
}
int gun(int v,int l,int r,int x,int y)
{
if(l>=x&&r<=y)return tc[v];
int mid=l+r>>1,res=0;
if(x<=mid)res=max(res,gun(v<<1,l,mid,x,y));
if(mid<y)res=max(res,gun(v<<1|1,mid+1,r,x,y));
return res;
}
int main()
{
scanf("%d%d%d",&n,&m,&Q);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=n;i++)scanf("%d",&c[i]);
build(1,1,n);
tl[0]=n+1;
for(int i=1;i<=n;i++)
{
ins(rt[c[i]],1,n,i,1);
int x=find(rt[c[i]],1,n,i-1);
cao(1,1,n,i,x);
x=gun(1,1,n,x+1,i);
node y=que(1,1,n,x+1,i);
chg(1,1,n,i,y.sum);
}
for(;Q;Q--)
{
int op,x,y;
scanf("%d%d%d",&op,&x,&y);
if(op==1)
{
node s=que(1,1,n,x,y);
int mi=ask(1,1,n,x,y);
int ans=0;
for(int i=x;i<=y;i++)
{
tag++;
int v=0;
for(int j=i;j<=y;j++)
{
if(tt[c[j]]==tag)break;
v+=a[j];
tt[c[j]]=tag;
}
ans=max(ans,v);
}
printf("%d\n",ans);
// printf("%d\n",min(s.ans,mi));
}
else
{
upt(1,1,n,x,y);
ins(rt[c[x]],1,n,x,0);
c[x]=y;
ins(rt[c[x]],1,n,x,1);
int l=find(rt[c[x]],1,n,x-1);
cao(1,1,n,x,l);
l=gun(1,1,n,l+1,x);
node r=que(1,1,n,l+1,x);
chg(1,1,n,x,r.sum);
}
}
return 0;
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 84ms
memory: 10272kb
input:
5000 200 5000 2315 3433 1793 4621 4627 4561 289 4399 3822 2392 392 4581 2643 2441 4572 4649 2981 3094 4206 2057 761 2516 2849 3509 3033 658 4965 3316 3269 4284 4961 753 1187 2515 1377 1725 4743 4761 3823 3464 4859 989 2401 953 875 1481 2181 103 2067 2625 3296 4721 61 3843 1607 997 4385 1284 4299 441...
output:
118571 90725 79596 95154 95154 94493 72411 100567 100567 100567 100567 90725 100567 100567 90725 118571 94493 95154 58191 118571 100567 100567 100567 39374 89208 118571 99923 100567 100567 95724 87252 100567 118571 100567 100567 100567 100567 100567 100567 26617 100567 99923 100567 118571 100567 100...
result:
ok 3799 lines
Test #2:
score: 0
Accepted
time: 132ms
memory: 10700kb
input:
5000 1000 5000 451 521 3465 4281 3422 1186 2547 3341 2060 1467 717 2115 2513 2471 1399 1812 3070 2173 521 1621 2801 4020 4493 138 4162 97 1179 171 4011 3340 2393 689 1830 3981 2352 3352 3561 2969 1037 1205 2390 3916 1578 2313 2433 885 1097 1820 739 4483 3241 3861 1547 665 1449 4133 4877 1005 3510 18...
output:
188595 209663 209663 209663 209663 209663 209282 209663 209663 176195 156041 141623 176195 209663 209663 209282 175706 209663 209663 209663 209663 209663 209282 209663 209663 209663 188595 209282 209663 183686 209663 163197 209663 183686 209663 183686 209663 175706 209663 209663 209663 209663 209663...
result:
ok 3724 lines
Subtask #2:
score: 0
Time Limit Exceeded
Test #3:
score: 0
Time Limit Exceeded
input:
200000 10 200000 55651 97298 108697 86619 60721 199951 10610 162267 154301 138848 39191 18605 101369 57073 34977 101576 71252 143401 89587 160521 166491 38442 150761 35579 25571 121311 38033 38483 144639 41401 179161 54872 157905 137601 46863 187656 171901 43715 41036 150741 69057 102031 130561 4772...
output:
1232419 1222519 1232419 1232419 1232419 1232419 1232419 1232419 1232419 1232419 1040511 1148070 1232419 1232419 1232419 1232419 1206368 1206368 1232419 1232419 1232419 1222519 1167757 1206368 1214212 1222519 1232419 1222519 1222519 1160928 1011843 1232419 1232419 1189403 1222519 1232419 1222519 1148...
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #5:
score: 0
Time Limit Exceeded
input:
200000 20000 200000 30681 32496 35471 48191 159123 69792 120915 150673 187226 158493 36275 26856 107976 124777 145229 69745 183961 14497 144808 153612 185893 137681 66417 46802 19345 113322 168046 128149 191001 135433 13201 139214 59489 81178 42343 163158 110121 119201 97501 53079 158755 192241 1132...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Test #9:
score: 0
Time Limit Exceeded
input:
50000 1000 50000 22098 40691 15626 6766 15467 15377 43375 7991 25841 6053 2031 38833 19761 42385 9421 28399 42001 15985 31206 30047 14001 7441 8377 5217 4402 37695 41393 25926 38137 32913 23203 31265 31401 32772 32905 24167 5233 24058 41685 26999 41 18461 15721 49365 49676 3151 29237 22894 37323 272...
output:
2734990 2469610 2734990 2734990 2734990 1967019 2734990 2469610 2469610 2388133 1799671 2469610 2734990 2734990 2734990 1957691 2273183 1952934 2734990 2168141 2273183 2436566 2734990 2469610 2469610 2273183 1986640 2734990 2152587 2152587 2436566 1957691 2734990 1952934 2469610 1927323 2734990 2734...
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%