QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#404220 | #6304. Rectangle | by_chance | WA | 13ms | 25836kb | C++14 | 5.4kb | 2024-05-03 16:16:29 | 2024-05-03 16:16:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline void chkmax(int&a,int b){if(a<b)a=b;}
inline void chkmin(int&a,int b){if(a>b)a=b;}
inline int read(){
int x=0;char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x;
}
typedef long long ll;
const int N=2e5+10,INF=1e9+7,P=998244353;
int C2(int x){return 1ll*x*(x-1)/2%P;}
int C3(int x){return 1ll*x*(x-1)%P*(x-2)%P*166374059%P;}
int T,n,x[N][2],y[N][2],X[N],xc,Y[N],yc,ans;
int mn[N<<2],len[N<<2];ll sum[N<<2],sl[N<<2];
struct node{
priority_queue<int> Q1,Q2;
void clear(){while(Q1.size())Q1.pop();while(Q2.size())Q2.pop();}
void ins(int x){Q1.push(-x);} void del(int x){Q2.push(-x);}
int top(){
while(Q2.size()&&Q1.top()==Q2.top())Q1.pop(),Q2.pop();
if(Q1.size())return -Q1.top();else return INF-7;
}
int size(){return Q1.size()-Q2.size();}
}tr[N];
#define ls p<<1
#define rs p<<1|1
#define mid ((l+r)>>1)
void build(int p,int l,int r){
mn[p]=INF-7;len[p]=Y[r+1]-Y[l];
sum[p]=1ll*len[p]*mn[p];sl[p]=0;
if(l==r){tr[l].clear();return;}
build(ls,l,mid);build(rs,mid+1,r);sl[p]=sum[ls];
}
ll ask(int p,int l,int r,int v){
if(mn[p]>=v)return 1ll*len[p]*v;
if(l==r)return sum[p];
ll res=ask(rs,mid+1,r,v);
if(mn[rs]>v)res+=ask(ls,l,mid,v);
else res+=sl[p];return res;
}
void push_up(int p,int l,int r){
mn[p]=min(mn[ls],mn[rs]);sum[p]=sum[rs];
if(mn[p]==mn[rs])sl[p]=1ll*len[ls]*mn[rs];
else sl[p]=ask(ls,l,mid,mn[rs]);
sum[p]+=sl[p];
}
void modify(int p,int l,int r,int x,int v){
if(l==r){
if(v>0)tr[x].ins(v);else tr[x].del(-v);
mn[p]=tr[x].top();sum[p]=1ll*mn[p]*len[p];return;
}
if(x<=mid)modify(ls,l,mid,x,v);
else modify(rs,mid+1,r,x,v);
push_up(p,l,r);
}
int getmin(int p,int l,int r,int L,int R){
if(l>=L&&r<=R)return mn[p];int res=INF-7;
if(L<=mid)chkmin(res,getmin(ls,l,mid,L,R));
if(R>mid)chkmin(res,getmin(rs,mid+1,r,L,R));
return res;
}
ll query(int p,int l,int r,int L,int R,int&now){
if(l>=L&&r<=R){
if(mn[p]>=now)return 1ll*len[p]*now;
int tmp=now;now=mn[p];return ask(p,l,r,tmp);
}
ll res=0;if(R>mid)res=query(rs,mid+1,r,L,R,now);
now=min(now,mn[rs]);if(L<=mid)res+=query(ls,l,mid,L,R,now);
return res;
}
vector<int> v1[N],v2[N];node pl,pr;
void ins(int p){
pl.ins(-y[p][0]);pr.ins(y[p][1]);
if(y[p][0]==1)return;modify(1,1,yc,y[p][0]-1,Y[y[p][1]+1]-1);
}
void del(int p){
pl.del(-y[p][0]);pr.del(y[p][1]);
if(y[p][0]==1)return;modify(1,1,yc,y[p][0]-1,-(Y[y[p][1]+1]-1));
}
int ask(){
int L=pl.size()?abs(pl.top()):1,
R=pr.size()?abs(pr.top()):yc;
int l=1,r=R;
while(l<=r){
if(getmin(1,1,yc,mid,yc)>=Y[max(mid,L)])r=mid-1;
else l=mid+1;
}
int pos=r+1,now=1e9+1;if(pos>R)return 0;ll suml=0;
if(L>R)suml=1ll*(Y[L]-1)*(Y[R+1]-Y[pos]);
else if(L>pos)suml=1ll*(Y[L]-1)*(Y[L]-Y[pos])+
1ll*(Y[R+1]-Y[L])*(Y[R+1]+Y[L]-1)/2;
else suml=1ll*(Y[R+1]+Y[pos]-1)*(Y[R+1]-Y[pos])/2;
return (query(1,1,yc,pos,R,now)%P-suml%P+P)%P;
}
int calc1(){
for(int i=1;i<=xc;i++)v1[i].clear(),v2[i].clear();
for(int i=1;i<=n;i++)
v1[x[i][0]].push_back(i),v2[x[i][1]].push_back(i);
build(1,1,yc);pl.clear();pr.clear();int res=0;
for(int i=1;i<=n;i++)ins(i);
for(int i=1;i<=xc;i++){
for(int j:v1[i])del(j);
res=(res+1ll*(X[i+1]-X[i])*ask())%P;
for(int j:v2[i])ins(j);
}
return res;
}
int lp[N],rp[N],fl[N],fr[N];
int calc2(){
for(int i=1;i<=xc;i++)lp[i]=0,rp[i]=xc+1;
for(int i=1;i<=n;i++){
chkmax(lp[x[i][1]],x[i][0]);
chkmin(rp[x[i][0]],x[i][1]);
}
int L=0,R=0;
for(int i=1;i<=xc;i++){
fl[i]=R?max(0,X[R+1]-X[L]):-1;
if(lp[i]!=0){if(!R)R=i,L=lp[i];chkmax(L,lp[i]);}
}L=0,R=0;
for(int i=xc;i>=1;i--){
fr[i]=L?max(0,X[R+1]-X[L]):-1;
if(rp[i]!=xc+1){if(!L)L=i,R=rp[i];chkmin(R,rp[i]);}
}
int res=0;
for(int i=1;i<=xc;i++){
int a=X[i]-1,b=X[i+1]-X[i],c=X[xc+1]-X[i+1];
if(fl[i]==-1&&fr[i]==-1)
res=(res+1ll*a*b%P*c%P+1ll*C2(b)*(a+c)%P+C3(b))%P;
else if(fl[i]==-1)res=(res+1ll*(1ll*a*b%P+C2(b))*fr[i]%P)%P;
else if(fr[i]==-1)res=(res+1ll*(1ll*c*b%P+C2(b))*fl[i]%P)%P;
else res=(res+1ll*fl[i]*fr[i]%P*b%P)%P;
}
return res;
}
void solve(){
n=read();xc=yc=ans=0;
for(int i=1;i<=n;i++){
X[++xc]=x[i][0]=read();Y[++yc]=y[i][0]=read();
X[++xc]=(x[i][1]=read())+1;Y[++yc]=(y[i][1]=read())+1;
}
X[++xc]=1;Y[++yc]=1;X[++xc]=1e9+1;Y[++yc]=1e9+1;
sort(X+1,X+xc+1);xc=unique(X+1,X+xc+1)-X-1;--xc;
sort(Y+1,Y+yc+1);yc=unique(Y+1,Y+yc+1)-Y-1;--yc;
for(int i=1;i<=n;i++){
x[i][0]=lower_bound(X+1,X+xc+1,x[i][0])-X;
y[i][0]=lower_bound(Y+1,Y+yc+1,y[i][0])-Y;
x[i][1]=lower_bound(X+1,X+xc+1,x[i][1])-X-1;
y[i][1]=lower_bound(Y+1,Y+yc+1,y[i][1])-Y-1;
}
ans=(ans+calc1())%P;ans=(ans+calc2())%P;
for(int i=1;i<=max(xc,yc)+1;i++)swap(X[i],Y[i]);swap(xc,yc);
for(int i=1;i<=n;i++)for(int c:{0,1})swap(x[i][c],y[i][c]);
ans=(ans+calc1())%P;ans=(ans+calc2())%P;
printf("%d\n",ans);
}
int main(){
T=read();
while(T--)solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 25604kb
input:
3 1 1 1 1000000000 1000000000 3 1 1 2 2 3 3 4 4 5 5 6 6 5 581574116 47617804 999010750 826131769 223840663 366320907 613364068 926991396 267630832 51913575 488301124 223957497 217461197 492085159 999485867 913732845 28144453 603781668 912516656 993160442
output:
230616300 64 977066618
result:
ok 3 number(s): "230616300 64 977066618"
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 25836kb
input:
1000 10 5 7 6 10 4 3 6 9 1 6 3 7 1 1 7 10 1 2 7 7 5 2 8 3 2 1 5 7 1 1 10 6 1 7 2 8 4 7 5 9 10 6 6 8 10 4 4 9 9 2 4 6 5 5 3 10 10 1 3 4 4 2 2 3 6 7 5 8 6 2 7 8 8 5 7 10 10 2 4 7 8 10 3 6 6 10 1 2 7 4 7 5 10 9 4 5 8 9 2 7 5 9 2 2 9 7 3 3 8 4 1 1 8 6 5 4 10 6 3 9 7 10 10 3 1 8 9 1 3 8 10 4 1 7 4 2 4 5 ...
output:
11 7022595 35112934 42135496 18 3511297 17556498 7022622 23 19 7022615 84270914 52669369 28090344 22 104 7 22 19 3511315 7022633 60 7 23 8 17556511 10533971 3511355 14045184 31601636 52 7022659 7022607 7022656 35112974 7022648 15 22 22 17556530 22 38624224 42 3511309 7022601 7022629 38624291 1755646...
result:
wrong answer 1st numbers differ - expected: '28090346', found: '11'