YamadaRyou @ 2023-10-04 19:34:47
本地没问题但是交上去就 RE,检查了下好像不是返回值的问题
#include<stdio.h>
struct{
int id,x1,y1,x2,y2,k;
}q[60001],q1[60001],q2[60001];
struct{
int x,y,k;
}a[250001],a1[250001],a2[250001];
int n,res[60001],c[501][501];
void add(int x,int y,int k){
for(int i=x;i<=n;i+=(i&-i))
for(int j=y;j<=n;j+=(j&-j))
c[i][j]+=k;
}
int sum(int x,int y){
int s=0;
for(int i=x;i;i-=(i&-i))
for(int j=y;j;j-=(j&-j))
s+=c[i][j];
return s;
}
int sum(int x1,int y1,int x2,int y2){
return sum(x2,y2)-sum(x1-1,y2)-sum(x2,y1-1)+sum(x1-1,y1-1);
}
void solve(int l,int r,int al,int ar,int ql,int qr){
if(ql>qr)return;
if(l==r){
for(int i=ql;i<=qr;++i)res[q[i].id]=l;
return;
}
int mid=l+r>>1,p1=0,p2=0,p3=0,p4=0;
for(int i=al;i<=ar;++i)
if(a[i].k<=mid)
add(a[i].x,a[i].y,1),a1[++p1]=a[i];
else a2[++p2]=a[i];
for(int i=ql,k;i<=qr;++i)
if(q[i].k<=(k=sum(q[i].x1,q[i].y1,q[i].x2,q[i].y2)))q1[++p3]=q[i];
else q[i].k-=k,q2[++p4]=q[i];
for(int i=1;i<=p1;++i)add(a1[i].x,a1[i].y,-1),a[al-1+i]=a1[i];
for(int i=1;i<=p2;++i)a[al-1+p1+i]=a2[i];
for(int i=1;i<=p3;++i)q[ql-1+i]=q1[i];
for(int i=1;i<=p4;++i)q[ql-1+p3+i]=q2[i];
solve(l,mid,al,al-1+p1,ql,ql-1+p3),solve(mid+1,r,al+p1,ar,ql+p3,qr);
}
int main(){
int m,tot;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)scanf("%d",&a[++tot].k),a[tot].x=i,a[tot].y=j;
for(int i=1;i<=m;++i)scanf("%d%d%d%d%d",&q[i].x1,&q[i].y1,&q[i].x2,&q[i].y2,&q[i].k),q[i].id=i;
solve(0,1000000000,1,n*n,1,m);
for(int i=1;i<=m;++i)printf("%d\n",res[i]);
return 0;
}
by Tibrella @ 2023-10-04 19:38:03
@toaru
int m,tot;
里面 tot 没有初始化,改了就过了
by Tibrella @ 2023-10-04 19:39:06
另外这个错开 -Wall
就能查出来(
by YamadaRyou @ 2023-10-04 19:43:50
@Tibrella 啊这,谢谢/dk
by BeBanned @ 2023-10-05 08:11:43
@toaru 大佬怎么还卷呢