QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#403763 | #70. Bitaro, who Leaps through Time | Rafi22 | 0 | 388ms | 94080kb | C++14 | 4.1kb | 2024-05-02 18:37:21 | 2024-05-02 18:37:22 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000000000000007;
int mod=1000000007;
int mod1=998244353;
const int N=300007,pot=1<<19;
struct S
{
int l=-inf,r=inf,x=-1,y=-1,sum=0;
};
int l1[N],r1[N];
int l2[N],r2[N];
S Merge(S L,S R)
{
if(L.x!=-1)
{
if(R.x!=-1) return {0,0,L.x,R.y,L.sum+R.sum+max(0LL,L.y-R.x)};
else
{
if(L.y<R.l) return {0,0,L.x,R.l,L.sum+R.sum};
else if(L.y>R.r) return {0,0,L.x,R.r,L.sum+R.sum+L.y-R.r};
else return {0,0,L.x,L.y,L.sum+R.sum};
}
}
else
{
if(R.x!=-1)
{
if(R.x<L.l) return {0,0,L.l,R.y,L.sum+R.sum+L.l-R.x};
else if(R.x>L.r) return {0,0,L.r,R.y,L.sum+R.sum};
else return {0,0,R.x,R.y,L.sum+R.sum};
}
else
{
if(L.r<R.l) return {0,0,L.r,R.l,0};
else if(L.l>R.r) return {0,0,L.l,R.r,L.l-R.r};
else return {max(L.l,R.l),min(L.r,R.r),-1,-1,0};
}
}
}
struct T
{
S seg[2*pot+7];
T()
{
for(int j=1;j<2*pot;j++) seg[j]={-inf,inf,-1,-1,0};
}
void upd(int v)
{
seg[v+pot-1]= {l1[v],r1[v],-1,-1,0};
v+=pot-1;
while(v>1)
{
v/=2;
seg[v]=Merge(seg[2*v],seg[2*v+1]);
}
}
S que(int v,int a,int b,int l,int r)
{
if(a<=l&&b>=r) return seg[v];
if(r<a||l>b) return {-inf,inf,-1,-1,0};
return Merge(que(2*v,a,b,l,(l+r)/2),que(2*v+1,a,b,(l+r)/2+1,r));
}
};
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,q,l,r;
cin>>n>>q;
T T1,T2;
for(int i=1;i<n;i++)
{
cin>>l>>r;
r--;
l1[i]=l+n-i;
r1[i]=r+n-i;
T1.seg[i+pot-1]={l1[i],r1[i],-1,-1,0};
l2[n-i]=l+i+1;
r2[n-i]=r+i+1;
T2.seg[n-i+pot-1]={l2[i],r2[i],-1,-1,0};
}
for(int i=pot-1;i>0;i--)
{
T1.seg[i]=Merge(T1.seg[2*i],T1.seg[2*i+1]);
T2.seg[i]=Merge(T2.seg[2*i],T2.seg[2*i+1]);
}
while(q--)
{
int t;
cin>>t;
if(t==1)
{
int i;
cin>>i;
cin>>l>>r;
r--;
l1[i]=l+n-i;
r1[i]=r+n-i;
T1.upd(i);
l2[n-i]=l+i+1;
r2[n-i]=r+i+1;
T2.upd(n-i);
}
else
{
int a,b,c,d,ans=0;
cin>>a>>b>>c>>d;
if(a<=c)
{
b+=n-a;
d+=n-c;
S p=T1.que(1,a,c-1,1,pot);
ans+=p.sum;
if(p.x!=-1)
{
ans+=max(0LL,b-p.x);
ans+=max(0LL,p.y-d);
}
else
{
if(b>p.r)
{
ans+=b-p.r;
b=p.r;
}
else if(b<p.l) b=p.l;
ans+=max(0LL,b-d);
}
}
else
{
b+=a;
d+=c;
a=n-a+1;
c=n-c+1;
S p=T2.que(1,a,c-1,1,pot);
ans+=p.sum;
if(p.x!=-1)
{
ans+=max(0LL,b-p.x);
ans+=max(0LL,p.y-d);
}
else
{
if(b>p.r)
{
ans+=b-p.r;
b=p.r;
}
else if(b<p.l) b=p.l;
ans+=max(0LL,b-d);
}
}
cout<<ans<<endl;
}
}
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: 37ms
memory: 85548kb
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 757633746 517757980 236944355 561949186 106582836 27085947 917125756 191096499
result:
wrong answer 2nd lines differ - expected: '286505553', found: '757633746'
Subtask #2:
score: 0
Wrong Answer
Test #42:
score: 0
Wrong Answer
time: 388ms
memory: 94080kb
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 37323036706 7258963059462 444228727672 4429060670616 6687125880555 6935309426619 588806818956 3467307714818 585814640 8791722334108 684412311 6704860308139 4323459010754 4925459727267 46968789226 1106052488458 2141002313351 2974203582273 446258629063 5203914165259 7801658...
result:
wrong answer 3rd lines differ - expected: '4095601609850', found: '37323036706'
Subtask #3:
score: 0
Wrong Answer
Test #56:
score: 0
Wrong Answer
time: 379ms
memory: 93912kb
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:
6568284719225 1148673779623 9771877069345 402700745 3602711301295 3345329466188 7449449722417 1580029590 3001190474356 6022602583263 4121761714752 1109525880104 5639811302245 1739244418 4905678737163 2895778161036 5469274205063 10163872384436 1235784443 5875928707705 7679043988101 437423872113 11052...
result:
wrong answer 1st lines differ - expected: '6546523326977', found: '6568284719225'