QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67130 | #5098. 第一代图灵机 | Graphcity | 0 | 668ms | 56728kb | C++20 | 3.4kb | 2022-12-10 09:46:08 | 2022-12-10 09:46:37 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=2e5;
const ll inf=1e18;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0' || ch>'9')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
int n,m,q,val[Maxn+5],col[Maxn+5],pre[Maxn+5];
ll sum[Maxn+5]; set<int> st[Maxn+5];
struct Node
{
int id,l,r,pos,mx; ll val,rval,ans,hzh;
inline void Print()
{
printf("%d %d %d: %d %d %lld %lld %lld %lld\n",id,l,r,pos,mx,val,rval,ans,hzh);
}
} t[Maxn*4+5];
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
inline ll GetHzh(int p,int k)
{
int l=t[p].l,r=t[p].r,mid=(l+r)>>1;
if(l==r) return sum[l]-sum[max(k,pre[l])];
if(k<=t[ls(p)].mx) return max(t[p].rval,GetHzh(ls(p),k));
else return max(sum[mid]-sum[k],GetHzh(rs(p),k));
}
inline ll GetAns(int p,int k)
{
int l=t[p].l,r=t[p].r,mid=(l+r)>>1;
if(l==r) return sum[l]-sum[max(pre[l],k-1)];
if(t[ls(p)].mx<k) return max(sum[mid]-sum[k-1],GetAns(rs(p),k));
else return max(GetAns(ls(p),k),t[p].rval);
}
inline Node operator+(Node a,Node b)
{
if(!a.l) return b;
Node c;
c.mx=max(a.mx,b.mx);
c.val=a.val+b.val;
c.l=a.l,c.r=b.r;
c.rval=GetHzh(b.id,a.mx);
c.hzh=max(a.hzh,c.rval);
c.pos=b.pos;
if(b.pos==b.l) c.pos=max(a.pos,b.mx+1);
c.ans=max(a.ans,b.ans);
c.ans=max(c.ans,GetAns(b.id,a.pos));
return c;
}
inline void push_up(int p) {t[p]=t[ls(p)]+t[rs(p)],t[p].id=p;}
inline void Build(int l,int r,int p)
{
t[p].l=l,t[p].r=r;
if(l==r) {t[p]=(Node){p,l,r,l,pre[l],val[l],-inf,val[l],sum[l]-sum[pre[l]]}; return;}
int mid=(l+r)>>1;
Build(l,mid,ls(p)),Build(mid+1,r,rs(p)),push_up(p);
}
inline void Modify(int l,int r,int p,int pos,int k)
{
// if(l==r) printf("opt %d: %d\n",pos,k);
if(l==r) {t[p].mx=k,t[p].hzh=sum[l]-sum[k]; return;}
int mid=(l+r)>>1;
if(pos<=mid) Modify(l,mid,ls(p),pos,k);
else Modify(mid+1,r,rs(p),pos,k);
push_up(p);
}
inline Node Count(int nl,int nr,int l,int r,int p)
{
if(l<=nl && nr<=r) return t[p];
int mid=(nl+nr)>>1; Node res; res.l=0;
if(l<=mid) res=res+Count(nl,mid,l,r,ls(p));
if(r>mid) res=res+Count(mid+1,nr,l,r,rs(p));
return res;
}
int main()
{
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
n=read(),m=read(),q=read();
For(i,1,m) st[i].insert(0);
For(i,1,n) val[i]=read();
For(i,1,n) col[i]=read();
For(i,1,n)
{
sum[i]=sum[i-1]+val[i];
pre[i]=*--st[col[i]].end(),st[col[i]].insert(i);
}
For(i,1,m) st[i].insert(n+1);
Build(1,n,1);
while(q--)
{
int opt=read(),a=read(),b=read();
if(opt==1) printf("%d\n",Count(1,n,a,b,1).ans);
if(opt==2)
{
if(col[a]==b) continue;
int x=*st[col[a]].upper_bound(a);
int y=*--st[col[a]].lower_bound(a);
int z=*--st[b].lower_bound(a);
int s=*st[b].upper_bound(a);
if(x<=n) pre[x]=y,Modify(1,n,1,x,y);
col[a]=b,pre[a]=z,Modify(1,n,1,a,z);
if(s<=n) pre[s]=a,Modify(1,n,1,s,a);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 14336kb
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:
428064 136303 79596 381002 667560 628229 126242 398077 226461 210951 170534 136303 258987 228052 73382 163511 127706 304232 58191 144071 1253911 587282 100567 39374 648685 467419 433061 102096 244579 79596 87252 100567 118571 100567 459079 100567 701570 466602 100567 26617 1770070 963740 170534 1802...
result:
wrong answer 1st lines differ - expected: '118571', found: '428064'
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 668ms
memory: 54924kb
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 1627157 4612047 1232419 2615196 1503001 1040511 1148070 1576307 1232419 1232419 1232419 1206368 1206368 1232419 1232419 1232419 1222519 1167757 1206368 1214212 1313667 1232419 1222519 1222519 1160928 5370489 1467955 1232419 1189403 2124159 1232419 1222519 1148...
result:
wrong answer 6th lines differ - expected: '1232419', found: '1627157'
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 597ms
memory: 56728kb
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:
-51895125 46702944 272235530 2082574765 184738573 215130322 1503039070 77507158 511066957 947390860 121808514 156002865 922532359 1655645026 1497576554 1880621346 1499148856 2120088056 -1150253170 121834492 407987493 135097633 594088434 768229884 801823540 939754008 117859830 48866360 842200135 -159...
result:
wrong answer 1st lines differ - expected: '46702944', found: '-51895125'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%