QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142033 | #6733. Moniphant Sleep | OvO_Zuo | WA | 634ms | 50764kb | C++14 | 2.4kb | 2023-08-18 11:27:09 | 2023-09-05 22:11:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n,q;
struct seg{
int z,f,der,tz,tf;
bool cl,mn;
seg(int a=0,int b=0,int c=0,int d=0,int e=0,bool f=0,bool g=0):z(a),f(b),der(c),tz(d),tf(e),cl(f),mn(g){}
void init()
{
z=f=der=tz=tf=0;
cl=mn=0;
}
void add(int x){ der+=x;}
void sub(int x)
{
der+=x;
if(der<0)
{
mn=0;
tz+=x;
der=0;
}
if(tz<0) tf+=tz,tz=0;
}
void upd()
{
if(mn) return;
tz+=der;
der=0;
mn=1;
}
void clear()
{
if(!mn) tz+=der;
mn=0;der=0;
if(cl) return;
if(z+tf<0) f+=z+tf,z=tz;
else z+=tz+tf;
tz=tf=0;
cl=1;
}
seg operator+(seg a)
{
seg res=seg(z,f,der,tz,tf,cl,mn);
res.sub(a.f),res.add(a.z);
if(a.cl) res.clear();
res.sub(a.tf),res.add(a.tz);
if(a.mn) res.upd();
res.add(a.der);
//cout<<res.z<<" "<<res.f<<" "<<res.tz<<" "<<res.tf<<" "<<res.der<<" "<<res.cl<<" "<<res.mn<<endl;
return res;
}
int v(){ return z+f+der+tz+tf;}
}shu[N<<2];
void build(int l,int r,int idx)
{
if(l==r)
{
shu[idx].z=500000;
return;
}
int mid=(l+r)>>1;
build(l,mid,idx<<1),build(mid+1,r,idx<<1|1);
}
void push_down(int idx)
{
shu[idx<<1]=shu[idx<<1]+shu[idx];
shu[idx<<1|1]=shu[idx<<1|1]+shu[idx];
shu[idx].init();
}
void modify(int l,int r,int tl,int tr,seg vv,int idx)
{
if(l>=tl&&r<=tr)
{
shu[idx]=shu[idx]+vv;
return;
}
push_down(idx);
int mid=(l+r)>>1;
if(mid>=tl) modify(l,mid,tl,tr,vv,idx<<1);
if(mid<tr) modify(mid+1,r,tl,tr,vv,idx<<1|1);
}
int query(int l,int r,int tar,int idx)
{
if(l==r) return shu[idx].v();
push_down(idx);
int mid=(l+r)>>1;
if(mid>=tar) return query(l,mid,tar,idx<<1);
else return query(mid+1,r,tar,idx<<1|1);
}
int main()
{
scanf("%d%d",&n,&q);
int i,op,l,r;
build(1,n,1);
for(i=1;i<=q;i++)
{
scanf("%d%d%d",&op,&l,&r);
if(op==1) modify(1,n,l,r,seg(1,0,0,0,0,0,0),1);
else if(op==2) modify(1,n,l,r,seg(0,-1,0,0,0,0,0),1);
else if(op==3) modify(1,n,l,r,seg(0,0,0,0,0,0,1),1);
else if(op==4) modify(1,n,l,r,seg(0,0,0,0,0,1,0),1);
else printf("%d\n",query(1,n,l,1));
//cout<<"query:"<<query(1,n,3,1)<<endl;
}
return 0;
}
/*
一/二操作为区间 +1/-1
四操作为跳转至有效的3操作中最小的后,将所有其余信息清空
不妨每次将清空后的位置视为0点,记录变化量
三操作时,只有更新最小值时需要操作:
将最小值记为当前位置,并将变化量清空
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 50636kb
input:
1 9 1 1 1 1 1 1 1 1 1 3 1 1 2 1 1 1 1 1 1 1 1 4 1 1 5 1 1
output:
500004
result:
ok 1 number(s): "500004"
Test #2:
score: 0
Accepted
time: 7ms
memory: 50692kb
input:
3 7 2 1 3 3 1 3 1 1 3 1 1 3 5 1 1 4 1 3 5 1 1
output:
500001 499999
result:
ok 2 number(s): "500001 499999"
Test #3:
score: -100
Wrong Answer
time: 634ms
memory: 50764kb
input:
500000 500000 2 132991 371170 5 15281 15281 1 278642 397098 2 152103 176573 2 13797 47775 3 139320 370045 3 79054 432340 3 82556 212775 4 270171 469418 5 148000 148000 3 371255 401414 5 71051 71051 2 358945 473071 2 231663 265401 2 20243 58131 1 247710 313373 5 154549 154549 1 17317 233265 5 37602 3...
output:
500000 499999 500000 499998 499999 500000 500000 499997 500000 499997 499997 499999 499997 500000 499997 500000 499999 500001 499999 499999 499997 499997 499996 499998 500000 500001 500001 499996 499998 499999 499996 499999 500001 499998 500000 500002 500002 499997 500001 499997 499995 499998 500004...
result:
wrong answer 13th numbers differ - expected: '499998', found: '499997'