QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#775708 | #70. Bitaro, who Leaps through Time | Symbolize | 0 | 162ms | 77388kb | C++17 | 3.6kb | 2024-11-23 16:32:01 | 2024-11-23 16:32:01 |
Judging History
answer
/*
Luogu name: Symbolize
Luogu uid: 672793
*/
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define rep1(i,l,r) for(register int i=l;i<=r;++i)
#define rep2(i,l,r) for(register int i=l;i>=r;--i)
#define rep3(i,x,y,z) for(register int i=x[y];~i;i=z[i])
#define rep4(i,x) for(auto i:x)
#define debug() puts("----------")
const int N=3e5+10;
const int inf=0x3f3f3f3f3f3f3f3f;
using namespace std;
int n,q,ans[N];
pii p[N];
struct Query
{
int opt;
int a,b,c,d;
}Q[N];
struct Segment_tree
{
int pl[N],pr[N];
struct node
{
int l,r;
bool res;
int x,y;
int z;
pii get(int st) const
{
if(!res)
{
if(st<x) return make_pair(x,0);
if(st>y) return make_pair(y,st-y);
return make_pair(st,0);
}
return make_pair(y,max(0ll,st-x)+z);
}
friend node operator+(const node &a,const node &b)
{
node ans;
if(!a.res&&!b.res)
{
if(a.x>b.y) ans={a.l,b.r,1,a.x,b.y,a.x-b.y};
else if(a.y<b.x) ans={a.l,b.r,1,a.y,b.x,0};
else ans={a.l,b.r,0,max(a.x,b.x),min(a.y,b.y),0};
}
else if(!a.res&&b.res)
{
if(b.x<a.x) ans={a.l,b.r,1,a.x,b.y,(a.x-b.x)+b.z};
else if(b.x>a.y) ans={a.l,b.r,1,a.y,b.y,b.z};
else ans={a.l,b.r,1,b.x,b.y,b.z};
}
else
{
pii now=b.get(a.y);
ans={a.l,b.r,1,a.x,now.x,now.y+a.z};
}
return ans;
}
}tr[N<<2];
int ls(int p){return p<<1;}
int rs(int p){return p<<1|1;}
void push_up(int p){tr[p]=tr[ls(p)]+tr[rs(p)];};
void build(int p,int l,int r)
{
tr[p]={l,r,0,0,0,0};
if(l==r)
{
tr[p].res=0;
tr[p].x=pl[l];
tr[p].y=pr[l];
return;
}
int mid=l+r>>1;
build(ls(p),l,mid);
build(rs(p),mid+1,r);
push_up(p);
return;
}
void update(int p,int x)
{
if(tr[p].l==tr[p].r)
{
tr[p].x=pl[x];
tr[p].y=pr[x];
return;
}
int mid=tr[p].l+tr[p].r>>1;
if(x<=mid) update(ls(p),x);
else update(rs(p),x);
push_up(p);
return;
}
node query(int p,int l,int r)
{
if(tr[p].l>=l&&tr[p].r<=r) return tr[p];
int mid=tr[p].l+tr[p].r>>1;
if(r<=mid) return query(ls(p),l,r);
if(l>mid) return query(rs(p),l,r);
return query(ls(p),l,r)+query(rs(p),l,r);
}
}seg;
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<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return f*x;
}
void solve()
{
seg.build(1,1,n-1);
rep1(i,1,q)
{
if(Q[i].opt==1)
{
int x=Q[i].a;
seg.pl[x]=Q[i].b+n-x;
seg.pr[x]=Q[i].c+n-x;
seg.update(1,x);
}
if(Q[i].opt==2)
{
if(Q[i].a>Q[i].c) continue;
if(Q[i].a==Q[i].c)
{
ans[i]=max(0ll,Q[i].b-Q[i].d);
continue;
}
Q[i].b+=n-Q[i].a;
Q[i].d+=n-Q[i].c;
pii now=seg.query(1,Q[i].a,Q[i].c-1).get(Q[i].b);
ans[i]=now.y+max(0ll,now.x-Q[i].d);
}
}
return;
}
signed main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n=read();
q=read();
rep1(i,1,n-1)
{
p[i].x=read();
p[i].y=read()-1;
}
rep1(i,1,q)
{
Q[i].opt=read();
if(Q[i].opt==1) Q[i].a=read(),Q[i].b=read(),Q[i].c=read()-1;
if(Q[i].opt==2) Q[i].a=read(),Q[i].b=read(),Q[i].c=read(),Q[i].d=read();
}
rep1(i,1,n) seg.pl[i]=p[i].x+n-i,seg.pr[i]=p[i].y+n-i;
solve();
// rep1(i,1,q)
// {
// if(Q[i].opt==1) Q[i].a=Q[i].a;
// if(Q[i].opt==2) Q[i].a=n-Q[i].a+1,Q[i].c=n-Q[i].c+1;
// }
// rep1(i,1,n) seg.pl[i]=p[n-i].x+n-i,seg.pr[i]=p[n-i].y+n-i;
// solve();
rep1(i,1,q) if(Q[i].opt==2) cout<<ans[i]<<"\n";
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: 0ms
memory: 13888kb
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:
1155445816 0 517757980 236944355 561949186 106582836 0 0 191096499
result:
wrong answer 2nd lines differ - expected: '286505553', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #42:
score: 0
Wrong Answer
time: 161ms
memory: 77388kb
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:
2849147975708 3843046238428 0 0 0 4429060670616 0 0 588806818956 0 0 8791722334108 0 6704860308139 0 0 46968789226 0 2141002313351 0 446258629063 5203914165259 0 3908068913890 0 0 0 0 0 6046526247358 0 8024476259536 0 0 0 11285197301011 0 0 7128909743041 8230130518537 3651845329578 529350415241 6355...
result:
wrong answer 3rd lines differ - expected: '4095601609850', found: '0'
Subtask #3:
score: 0
Wrong Answer
Test #56:
score: 0
Wrong Answer
time: 162ms
memory: 76192kb
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:
0 0 9771877069345 0 3602711301295 3345329466188 0 0 3001190474356 6022602583263 0 0 5639811302245 0 4905678737163 2895778161036 0 10163872384436 0 5875928707705 7679043988101 0 11052805379820 0 55686209077 0 0 0 0 12401009026028 7203624883162 5768540878730 6070823336877 0 0 0 0 0 0 12522577816879 72...
result:
wrong answer 1st lines differ - expected: '6546523326977', found: '0'