QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#449930 | #5098. 第一代图灵机 | 2745518585 | 0 | 462ms | 85492kb | C++20 | 2.4kb | 2024-06-21 19:40:54 | 2024-06-21 19:40:55 |
Judging History
answer
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
const int N=1000001;
int n,m,q,b[N],g[N];
ll a[N];
set<int> Set[N];
struct tree
{
int l,r,w;
ll s;
}T[N<<2];
ll find(int x,int l)
{
if(l>=T[x].r) return 0;
if(T[x].l==T[x].r) return a[T[x].l]-a[max(l,g[l])];
int z=T[x].l+T[x].r>>1;
if(l<=T[x<<1].w) return max(find(x<<1,l),T[x<<1|1].s);
else return max(a[z]-a[l],find(x<<1|1,l));
}
void pushup(int x)
{
T[x].w=max(T[x<<1].w,T[x<<1|1].w);
T[x].s=find(x<<1|1,T[x<<1].w);
}
void build(int x,int l,int r)
{
T[x].l=l,T[x].r=r;
if(l==r)
{
T[x].s=a[l]-a[g[l]];
T[x].w=g[l];
return;
}
int z=l+r>>1;
build(x<<1,l,z);
build(x<<1|1,z+1,r);
pushup(x);
}
void add(int x,int q)
{
if(T[x].l==T[x].r)
{
T[x].s=a[T[x].l]-a[g[T[x].l]];
T[x].w=g[T[x].l];
return;
}
int z=T[x].l+T[x].r>>1;
if(q<=z) add(x<<1,q);
else add(x<<1|1,q);
pushup(x);
}
ll sum(int x,int l,int r,int k)
{
if(T[x].l>=l&&T[x].r<=r) return find(x,k);
int z=T[x].l+T[x].r>>1;
ll s=0;
if(l<=z) s=max(s,sum(x<<1,l,r,k));
if(r>z) s=max(s,sum(x<<1|1,l,r,k));
return s;
}
int main()
{
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;++i)
{
scanf("%d",&a[i]);
a[i]+=a[i-1];
}
for(int i=1;i<=m;++i) Set[i].insert(0);
for(int i=1;i<=n;++i)
{
scanf("%d",&b[i]);
g[i]=*Set[b[i]].end();
Set[b[i]].insert(i);
}
build(1,1,n);
for(int i=1;i<=q;++i)
{
int z;
scanf("%d",&z);
if(z==1)
{
int l,r;
scanf("%d%d",&l,&r);
printf("%lld\n",sum(1,l,r,l));
}
else if(z==2)
{
int x,k;
scanf("%d%d",&x,&k);
auto p=Set[b[x]].find(x);
if(next(p)!=Set[b[x]].end())
{
g[*next(p)]=g[x];
add(1,*next(p));
}
Set[b[x]].erase(x);
b[x]=k;
Set[k].insert(x);
p=Set[k].find(x);
g[x]=*prev(p);
add(1,x);
if(next(p)!=Set[k].end())
{
g[*next(p)]=x;
add(1,*next(p));
}
}
}
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: 14ms
memory: 59712kb
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:
6757417 5819544 1573576 9818963 10116860 10013014 3077291 5819544 6555680 6600573 10116860 5819544 9818963 8644765 303271 11776960 818244 309231 273230 11108971 8644765 10116860 8441884 36813 5819544 11108971 434666 6003132 5819544 1155878 4652162 5819544 11364188 8441884 8441884 5819544 11108971 58...
result:
wrong answer 1st lines differ - expected: '118571', found: '6757417'
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 462ms
memory: 80976kb
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:
14794497228 3010127807 3092024942 4121604780 10593259660 18608790329 18691856185 14388247531 2829378780 17898089747 156793393 691777081 13804332566 14388247531 16043685616 14388247531 18867511931 682886683 14388247531 14495639153 14000556888 10786914983 4767326500 18867511931 2601971399 8686415662 1...
result:
wrong answer 1st lines differ - expected: '1232419', found: '14794497228'
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 291ms
memory: 85492kb
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:
6621675747 13369649242 931218999 2620448320 750317409 9534864228 3004960664 9839523563 13389184978 2836654870 125346024 546916664 3319068498 13401800941 12305896651 3918520748 4220403622 4196630492 17911495231 4642609744 12144115606 5386102380 3380303636 1694853309 11951165806 2557854406 14743095279...
result:
wrong answer 1st lines differ - expected: '46702944', found: '6621675747'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%