QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#149554 | #4918. 染色 | zhouhuanyi | 0 | 655ms | 168972kb | C++14 | 4.7kb | 2023-08-24 20:52:21 | 2023-08-24 20:52:22 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<set>
#define N 300000
using namespace std;
unsigned long long read()
{
char c=0;
unsigned long long sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
const int inf=(int)(1e9);
int n,m,length,st[N+1],leng;
struct reads
{
int num,minn,data;
};
reads tong[N+1];
struct rds
{
int l,r,type;
bool operator < (const rds &t)const
{
return r<t.r;
}
};
set<rds>sw[N+1];
struct seg
{
struct node
{
int l,r,data,minn,cnt;
set<int>s;
unsigned long long lazy,ans;
};
node tree[(N<<2)+1];
void push_up(int k)
{
if (tree[k].l!=tree[k].r)
{
tree[k].minn=min(min(tree[k<<1].minn,tree[k<<1|1].minn),tree[k].data),tree[k].cnt=0;
if (min(tree[k<<1].minn,tree[k].data)==tree[k].minn) tree[k].cnt+=(tree[k<<1].minn<tree[k].data?tree[k<<1].cnt:tree[k<<1].r-tree[k<<1].l+1);
if (min(tree[k<<1|1].minn,tree[k].data)==tree[k].minn) tree[k].cnt+=(tree[k<<1|1].minn<tree[k].data?tree[k<<1|1].cnt:tree[k<<1|1].r-tree[k<<1|1].l+1);
tree[k].ans=tree[k<<1].ans+tree[k<<1|1].ans;
}
else tree[k].minn=tree[k].data,tree[k].cnt=1;
return;
}
void spread(int k,int minn)
{
if (tree[k].lazy)
{
if (min(tree[k<<1].minn,minn)==min(tree[k].minn,minn)) tree[k<<1].ans+=tree[k].lazy*(tree[k<<1].minn<minn?tree[k<<1].cnt:tree[k<<1].r-tree[k<<1].l+1),tree[k<<1].lazy+=tree[k].lazy;
if (min(tree[k<<1|1].minn,minn)==min(tree[k].minn,minn)) tree[k<<1|1].ans+=tree[k].lazy*(tree[k<<1|1].minn<minn?tree[k<<1|1].cnt:tree[k<<1|1].r-tree[k<<1|1].l+1),tree[k<<1|1].lazy+=tree[k].lazy;
tree[k].lazy=0;
}
return;
}
void build(int k,int l,int r)
{
tree[k].l=l,tree[k].r=r,tree[k].data=tree[k].minn=inf,tree[k].cnt=tree[k].r-tree[k].l+1;
if (l==r) return;
int mid=(l+r)>>1;
build(k<<1,l,mid),build(k<<1|1,mid+1,r);
return;
}
void add(int k,int l,int r,int x,int d,int minn)
{
if (tree[k].l==l&&tree[k].r==r)
{
if (tree[k].l!=tree[k].r) spread(k,minn);
if (d==1) tree[k].s.insert(x);
else tree[k].s.erase(x);
tree[k].data=(!tree[k].s.empty()?*tree[k].s.begin():inf),push_up(k);
return;
}
spread(k,minn);
int mid=(tree[k].l+tree[k].r)>>1;
if (r<=mid) add(k<<1,l,r,x,d,min(minn,tree[k].data));
else if (l>=mid+1) add(k<<1|1,l,r,x,d,min(minn,tree[k].data));
else add(k<<1,l,mid,x,d,min(minn,tree[k].data)),add(k<<1|1,mid+1,r,x,d,min(minn,tree[k].data));
push_up(k);
return;
}
void find(int k,int l,int r,int minn)
{
if (tree[k].l==l&&tree[k].r==r)
{
tong[++length]=(reads){k,minn,min(minn,tree[k].minn)};
return;
}
st[++leng]=k,spread(k,minn);
int mid=(tree[k].l+tree[k].r)>>1;
if (r<=mid) find(k<<1,l,r,min(minn,tree[k].data));
else if (l>=mid+1) find(k<<1|1,l,r,min(minn,tree[k].data));
else find(k<<1,l,mid,min(minn,tree[k].data)),find(k<<1|1,mid+1,r,min(minn,tree[k].data));
return;
}
unsigned long long query(int k,int l,int r,int minn)
{
if (tree[k].l==l&&tree[k].r==r) return tree[k].ans;
spread(k,minn);
int mid=(tree[k].l+tree[k].r)>>1;
if (r<=mid) return query(k<<1,l,r,min(minn,tree[k].data));
else if (l>=mid+1) return query(k<<1|1,l,r,min(minn,tree[k].data));
else return query(k<<1,l,mid,min(minn,tree[k].data))+query(k<<1|1,mid+1,r,min(minn,tree[k].data));
}
};
seg T;
void adder(int l,int r,int x,int type)
{
rds top;
for (auto it=sw[x].lower_bound((rds){0,l,type});it!=sw[x].end()&&(*it).l<=r;it=sw[x].lower_bound((rds){0,l,type}))
{
top=*it,sw[x].erase(it);
if (!top.type) T.add(1,top.l,top.r,x,-1,inf);
if (top.l<=l-1)
{
sw[x].insert((rds){top.l,l-1,top.type});
if (!top.type) T.add(1,top.l,l-1,x,1,inf);
}
if (r+1<=top.r)
{
sw[x].insert((rds){r+1,top.r,top.type});
if (!top.type) T.add(1,r+1,top.r,x,1,inf);
}
}
sw[x].insert((rds){l,r,type});
if (!type) T.add(1,l,r,x,1,inf);
return;
}
int main()
{
int op,l,r,x,minn;
unsigned long long d;
n=read(),m=read(),T.build(1,1,n);
for (int i=1;i<=m;++i) adder(1,n,i,0);
for (int i=1;i<=m;++i)
{
op=read();
if (op==1) l=read(),r=read(),x=read(),adder(l,r,x,1);
else if (op==2) l=read(),r=read(),x=read(),adder(l,r,x,0);
else if (op==3)
{
l=read(),r=read(),d=read(),length=leng=0,T.find(1,l,r,inf),minn=inf;
for (int j=1;j<=length;++j) minn=min(minn,tong[j].data);
for (int j=1;j<=length;++j)
if (tong[j].data==minn)
T.tree[tong[j].num].ans+=d*(T.tree[tong[j].num].minn<tong[j].minn?T.tree[tong[j].num].cnt:T.tree[tong[j].num].r-T.tree[tong[j].num].l+1),T.tree[tong[j].num].lazy+=d;
for (int j=leng;j>=1;--j) T.push_up(st[j]);
}
else l=read(),r=read(),printf("%llu\n",T.query(1,l,r,inf));
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 14ms
memory: 122696kb
input:
1000 1000 3 722 914 2141556875752121755 3 323 347 6433743606947304931 2 142 206 439 2 117 840 195 2 127 502 56 3 168 707 15142638115094015116 4 190 257 2 88 976 475 1 319 867 351 1 682 889 409 2 406 446 196 3 28 35 4899387534800369959 2 291 546 150 1 528 617 128 1 58 122 251 2 381 400 276 4 510 958 ...
output:
15128467772367689008 17361914246216994339 5483226026482017320 3033562207293358603 2081407883485577238 7431958406282818646 4664359672511637691 8517692808398202534 17884251128335023776 3389445997760709607 15161173652136060523 17246899135664170339 16659472119973467421 5618344994614112283 92650283427734...
result:
wrong answer 101st words differ - expected: '14524402874407691970', found: '11204799760876574983'
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 655ms
memory: 154636kb
input:
300000 300000 1 237576 237663 1 3 16150 16208 9270412155482010138 2 175648 175692 1 4 190836 190849 4 199010 199097 1 73976 298801 1 3 89902 89939 6418828085116455990 3 55415 55461 12238963685511262676 3 119825 119875 8146944792877919309 3 135103 135158 218634681842812119 3 127261 127352 13291431184...
output:
0 0 0 0 0 0 12272376591028786218 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11461925751858974091 0 0 9151384944171872543 1026552556127344833 0 0 0 0 5911292200825857028 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5274906196339107896 0 0 0 0 0 0 0 0 0 16624900364521184536 0 0 0 0 8938874443410361664 5733831821835476140 0 0 0 134...
result:
wrong answer 22nd words differ - expected: '954290611784159519', found: '11461925751858974091'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 560ms
memory: 168972kb
input:
300000 300000 1 85444 86076 59 1 41150 41411 71 1 278698 279414 45 1 238445 239202 56 1 29965 29984 49 1 282953 283272 37 1 34668 35653 86 2 198587 198744 28 1 270855 271611 58 1 2130 2965 773 1 161601 162298 937 1 50299 50435 36 1 100759 101198 64 1 120208 120543 84 1 295293 295732 34 1 112185 1129...
output:
0 0 16968625150574630951 16605993861994422737 14436884090003254733 0 3880767775473082445 6112413713545582398 0 2784546786634233715 0 0 0 2704742022656382160 0 0 995880312728861482 0 0 0 0 0 10433996744029883784 13368567004097850084 0 3861451384001627672 0 2134685396643390371 7057146825293478647 0 13...
result:
wrong answer 10th words differ - expected: '17289176072916758003', found: '2784546786634233715'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%