QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#95650 | #70. Bitaro, who Leaps through Time | tricyzhkx | 0 | 381ms | 39772kb | C++14 | 2.2kb | 2023-04-11 08:57:33 | 2023-04-11 08:57:35 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,q,L[300010],R[300010];
ll ans[300010];
struct Query{int op,a,b,c,d;}que[300010];
struct node
{
int L,R,typ,x;
ll y;
node(int _L=0,int _R=0):L(_L),R(_R),typ(0),y(0){}
int pos(int t)const{return max(min(t,R),L);}
ll calc(int t)const{return typ?max(t-x,0)+y:max(t-R,0);}
node operator+(const node &a)const
{
node ans;
if(typ || a.typ || max(L,a.L)>min(R,a.R))
{
ans.typ=1;
ans.L=a.pos(L);ans.R=a.pos(R);
assert(pos(a.L)==pos(a.R));
ans.x=pos(a.L);ans.y=a.calc(ans.x)+y;
}
else
{
ans.typ=0;
ans.L=max(L,a.L);ans.R=min(R,a.R);
}
return ans;
}
}val[1100000];
void build(int rt,int l,int r)
{
if(l==r) return val[rt]=node(L[l]-l,R[l]-1-l),void();
int mid=(l+r)/2;
build(rt*2,l,mid);build(rt*2+1,mid+1,r);
val[rt]=val[rt*2]+val[rt*2+1];
}
void update(int rt,int l,int r,int x,int y,int z)
{
if(l==r) return val[rt]=node(y-x,z-1-x),void();
int mid=(l+r)/2;
if(x<=mid) update(rt*2,l,mid,x,y,z);
else update(rt*2+1,mid+1,r,x,y,z);
val[rt]=val[rt*2]+val[rt*2+1];
}
node query(int rt,int l,int r,int x,int y)
{
if(x<=l && r<=y) return val[rt];
int mid=(l+r)/2;
if(y<=mid) return query(rt*2,l,mid,x,y);
else if(x>mid) return query(rt*2+1,mid+1,r,x,y);
else return query(rt*2,l,mid,x,y)+query(rt*2+1,mid+1,r,x,y);
}
void solve()
{
build(1,1,n-1);
for(int i=1;i<=q;i++)
if(que[i].op==1) update(1,1,n-1,que[i].a,que[i].b,que[i].c);
else if(que[i].a<que[i].c)
{
int x=que[i].a,y=que[i].c,t1=que[i].b-x,t2=que[i].d-y;
node v=query(1,1,n-1,x,y-1);
ans[i]=v.calc(t1)+max(v.pos(t1)-t2,0);
}
}
int main()
{
cin>>n>>q;
for(int i=1;i<n;i++) scanf("%d%d",&L[i],&R[i]);
for(int i=1;i<=q;i++)
{
scanf("%d%d%d%d",&que[i].op,&que[i].a,&que[i].b,&que[i].c);
if(que[i].op==2) scanf("%d",&que[i].d);
}
for(int i=1;i<=q;i++)
if(que[i].a==que[i].c) ans[i]=max(que[i].b-que[i].d,0);
solve();
reverse(L+1,L+n);reverse(R+1,R+n);
for(int i=1;i<=n;i++)
if(que[i].op==1) que[i].a=n-que[i].a;
else que[i].a=n-que[i].a+1,que[i].c=n-que[i].c+1;
solve();
for(int i=1;i<=q;i++)
if(que[i].op==2) printf("%lld\n",ans[i]);
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: 1ms
memory: 34328kb
input:
20 18 115497790 671208773 326245299 528973482 100582193 437996818 89058008 771100620 768935396 842907844 187943946 997369106 455078418 542835554 536691525 970171971 564540350 570234421 657178750 753833933 386375484 979995375 389681484 772601117 634873482 897954663 87193815 139420775 259946990 394597...
output:
1311190384 286505553 1007027668 236944355 946740303 106582836 0 418804603 191096499
result:
wrong answer 1st lines differ - expected: '1155445816', found: '1311190384'
Subtask #2:
score: 0
Wrong Answer
Test #42:
score: 0
Wrong Answer
time: 332ms
memory: 39696kb
input:
274318 300000 489215489 676617321 780126019 788585486 556851007 580284394 233372413 595198772 519202713 898223077 502895565 696411826 206200999 769856900 270143414 346344669 729812429 901771242 663771137 938786194 472985796 990513077 846601694 992055636 178982840 919444964 27052680 316046043 8183731...
output:
2928104365280 3942684622343 4194273013361 9378918255752 458505757843 4580243562243 6928191757281 11052600633976 604995205546 4637611238128 3967924897287 9001197324647 6258208236763 6872930293443 7134891198831 8012438368884 46708804573 1137815364128 2186146345684 5315730629643 466181515456 5346778261...
result:
wrong answer 1st lines differ - expected: '2849147975708', found: '2928104365280'
Subtask #3:
score: 0
Wrong Answer
Test #56:
score: 0
Wrong Answer
time: 381ms
memory: 39772kb
input:
270695 300000 513123795 772355425 210106247 394028231 276162603 911454418 105669187 977348162 173662950 272706156 152814457 669922258 344843731 523572913 316675910 752220119 109044474 322732409 555169512 652867118 622530606 779759913 153668285 339269709 150911093 937002300 186921016 855255616 118867...
output:
6747383375577 1190867573133 10050886821251 1168265819479 3703198635392 3447044857174 8980606836028 1250367724279 3102820253483 6195971800097 11270262406839 3518672874769 5809114558335 4397723949216 5051696861355 2988258256205 6075117715239 10451355715689 2462354802674 6034860229720 7901756979133 467...
result:
wrong answer 1st lines differ - expected: '6546523326977', found: '6747383375577'