QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#390288 | #5098. 第一代图灵机 | onlycre | 0 | 268ms | 41424kb | C++14 | 2.4kb | 2024-04-15 11:17:38 | 2024-04-15 11:17:43 |
Judging History
answer
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rpe(i,x) for(int i=_he[x];i;i=_ne[i])
using namespace std;
typedef long long LL;
typedef pair<int,LL>pil;
const int N=2e5+10;
int pre[N],c[N],n,m,Q;
LL s[N];
namespace T{
int pmx[N<<2];
LL dat[N<<2],F[N<<2];
LL solve(int p,int l,int r,int x)
{
if(l==r)return s[l]-s[max(x,pre[l])];
int mid=(l+r)>>1;
if(x>=pmx[p<<1])return max(s[mid]-s[x],solve(p<<1|1,mid+1,r,x));
return max(solve(p<<1,l,mid,x),F[p<<1|1]);
}
void pup(int p,int mid,int r)
{
pmx[p]=max(pmx[p<<1],pmx[p<<1|1]);
F[p<<1|1]=solve(p<<1|1,mid+1,r,pmx[p<<1]);
dat[p]=max(dat[p<<1],F[p<<1|1]);
}
void build(int p,int l,int r)
{
if(l==r)return dat[p]=s[l]-s[pmx[p]=pre[l]],void();
int mid=(l+r)>>1;
build(p<<1,l,mid),build(p<<1|1,mid+1,r);
pup(p,mid,r);
//printf("%d %d %lld qwq\n",l,r,dat[p<<1]);
}
void mdf(int p,int l,int r,int pos,int v)
{
if(l==r)return pre[p]=v,void();
int mid=(l+r)>>1;
pos<=mid?mdf(p<<1,l,mid,pos,v):mdf(p<<1|1,mid+1,r,pos,v);
pup(p,mid,r);
}
pil ask(int p,int l,int r,int tl,int tr,int x)
{
if(l>=tl&&r<=tr)return {max(x,pmx[p]),solve(p,l,r,x)};
int mid=(l+r)>>1;
if(tl<=mid&&tr>mid)
{
pil L=ask(p<<1,l,mid,tl,tr,x),R=ask(p<<1|1,mid+1,r,tl,tr,max(x,L.first));
return {max(L.first,R.first),max(L.second,R.second)};
}
return tl<=mid?ask(p<<1,l,mid,tl,tr,x):ask(p<<1|1,mid+1,r,tl,tr,x);
}
}
set<int>S[N];
int main()
{
scanf("%d%d%d",&n,&m,&Q);
rep(i,1,n)scanf("%lld",&s[i]),s[i]+=s[i-1];
rep(i,1,n)
{
scanf("%d",&c[i]);
if(!S[c[i]].empty())pre[i]=*prev(S[c[i]].end());
S[c[i]].insert(i);
}
T::build(1,1,n);
//printf("%lld qwq\n",T::ask(1,1,n,1,3,0).second);
while(Q--)
{
int opt,x,y;scanf("%d%d%d",&opt,&x,&y);
if(opt==1)printf("%lld\n",T::ask(1,1,n,x,y,0).second);
else
{
if(c[x]==y)continue;
S[c[x]].erase(x);
auto it=S[c[x]].lower_bound(x);
if(it!=S[c[x]].end())
{
if(it==S[c[x]].begin())pre[*it]=0;
else pre[*it]=*prev(it);
T::mdf(1,1,n,*it,pre[*it]);
}
it=S[y].lower_bound(x);
if(it!=S[y].end())
{
pre[*it]=x;
T::mdf(1,1,n,*it,x);
}
if(it==S[y].begin())pre[x]=0;
else pre[x]=*prev(it);
T::mdf(1,1,n,x,pre[x]);
}
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 23896kb
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:
283134 90725 680075 95154 155748 94493 94522 443501 100567 431685 100567 279261 246448 100567 1709794 157406 124573 95154 214405 118571 100567 108214 420936 1991991 2193495 399299 99923 338920 3745298 95724 191740 459412 313242 194515 100567 402444 772755 300462 1221140 361155 1796450 214295 100567 ...
result:
wrong answer 1st lines differ - expected: '118571', found: '283134'
Subtask #2:
score: 0
Runtime Error
Test #3:
score: 0
Runtime Error
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:
result:
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 268ms
memory: 41424kb
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:
678300053 4120106917 1985154291 38615532 4979839860 3375561726 634623297 183815644 103097727 321101134 187524024 38402892 376985610 1745407459 1752852767 42323113 922081412 283766703 564533736 248372570 174658480 529134255 459202302 301251545 259219442 239604241 2239700365 421397411 508736493 951072...
result:
wrong answer 1st lines differ - expected: '46702944', found: '678300053'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%