QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149550 | #4918. 染色 | zhouhuanyi | 0 | 727ms | 165776kb | C++14 | 4.5kb | 2023-08-24 20:45:10 | 2023-08-24 20:45:12 |
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;
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(tree[k].minn,minn)};
return;
}
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,minn);
else if (l>=mid+1) return query(k<<1|1,l,r,minn);
else return query(k<<1,l,mid,minn)+query(k<<1|1,mid+1,r,minn);
}
};
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=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;
}
else l=read(),r=read(),printf("%llu\n",T.query(1,l,r,inf));
}
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: 16ms
memory: 122248kb
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:
0 7725877569435008543 16506359450351356392 10051076577557423233 18210011739713437932 1804746956562951008 10051076577557423233 7280656747796906878 0 16756722185997608405 9251653616692669996 15823100845308279510 2386060303892047161 1524327184340239335 14625002384112509168 16860381148521604811 74210913...
result:
wrong answer 1st words differ - expected: '15128467772367689008', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 727ms
memory: 155396kb
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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2569304860969309636 0 0 5602736502047187558 5479030399340018331 0 0 0 0 5911292200825857028 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2424730988374922983 0 0 0 0 0 0 0 0 0 16361945096320636285 0 0 0 0 8938874443410361664 5733831821835476140 0 0 0 13404741035567043156 0 ...
result:
wrong answer 7th words differ - expected: '12272376591028786218', found: '0'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 614ms
memory: 165776kb
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 0 0 0 0 0 12484822223837439917 0 17801167625750041447 0 0 0 4162920189091467717 0 0 0 0 0 0 0 0 4277779908844306652 13368567004097850084 0 0 0 9081461581121774729 0 0 0 0 0 0 0 0 0 0 0 0 6710086566175205237 4311191105472858124 0 0 761863118402533936 5199587061790191501 15429198409555669176 12009...
result:
wrong answer 3rd words differ - expected: '16968625150574630951', found: '0'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%