QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#393386 | #7436. Optimal Ordered Problem Solver | lcs080206 | 0 | 2830ms | 240620kb | C++14 | 5.9kb | 2024-04-18 15:56:04 | 2024-04-18 15:56:04 |
Judging History
answer
#include<bits/stdc++.h>
#define N 1000005
#define ls x<<1
#define rs x<<1|1
using namespace std;
int n,m;
struct node{
int x,y;
}a[N];
bool cmp1(node x,node y){return x.x==y.x?x.y<y.y:x.x<y.x;}
struct Qr{
int o,x,y,X,Y;
int ans1;
}q[N];
struct Qr2{int x,y,id;};
struct tree1{
int tr[N];
int lb(int x){return (x&-x);}
void upd(int x,int y){
for(int i=x;i<=n;i+=lb(i)){
tr[i]+=y;
}
}
int qr(int x){
int res=0;
for(int i=x;i;i-=lb(i))res+=tr[i];
return res;
}
}tr1;//二维数点
vector<Qr2>qr[N];
struct SG1{
int minn[N<<2];
void pup(int x){minn[x]=min(minn[ls],minn[rs]);}
void upd(int x,int l,int r,int t,int v){
if(l>t||r<t)return;
if(l==r){minn[x]=v;return;}
int mid=l+r>>1;
upd(ls,l,mid,t,v);upd(rs,mid+1,r,t,v);pup(x);
}
int query1(int x,int l,int r,int tl,int tr){
if(l>tr||r<tl)return n+1;
if(l>=tl&&r<=tr)return minn[x];
int mid=l+r>>1;
return min(query1(ls,l,mid,tl,tr),query1(rs,mid+1,r,tl,tr));
}
int query2(int x,int l,int r,int tl,int tr,int v){
if(l>tr||r<tl)return 0;
if(l>=tl&&r<=tr){
if(minn[x]!=v)return 0;
if(l==r)return l;
int mid=l+r>>1,X=query2(ls,l,mid,tl,tr,v);
if(!X)return query2(rs,mid+1,r,tl,tr,v);
return X;
}
int mid=l+r>>1,X=query2(ls,l,mid,tl,tr,v);
if(!X)return query2(rs,mid+1,r,tl,tr,v);
return X;
}
}tree;
vector<int>tx[N];
int totx[N];//散点修改
struct SG2{
int val[N<<2];
void pup(int x){val[x]=val[ls]+val[rs];}
void upd(int x,int l,int r,int t,int v){
if(l>t||r<t)return;
if(l==r){val[x]+=v;return;}
int mid=l+r>>1;
upd(ls,l,mid,t,v);upd(rs,mid+1,r,t,v);pup(x);
}
int query(int x,int l,int r,int tl,int tr){
if(l>tr||r<tl)return 0;
if(l>=tl&&r<=tr)return val[x];
int mid=l+r>>1;
return query(ls,l,mid,tl,tr)+query(rs,mid+1,r,tl,tr);
}
}tr_x,tr_y;//散点计数
struct SG3{
int val[N<<2],tag[N<<2];
void pd(int x){
if(!tag[x])return;
tag[ls]=tag[rs]=tag[x];
val[ls]=val[rs]=0;tag[x]=0;
}
void pup(int x){val[x]=val[ls]+val[rs];}
void upd(int x,int l,int r,int t,int v){
if(l>t||r<t)return;
if(l==r){val[x]+=v;return;}
pd(x);int mid=l+r>>1;
upd(ls,l,mid,t,v);upd(rs,mid+1,r,t,v);pup(x);
}
void upd2(int x,int l,int r,int tl,int tr){
if(l>tr||r<tl)return;
if(l>=tl&&r<=tr){tag[x]=1;val[x]=0;return;}
pd(x);int mid=l+r>>1;
upd2(ls,l,mid,tl,tr);upd2(rs,mid+1,r,tl,tr);pup(x);
}
int query(int x,int l,int r,int tl,int tr){
if(l>tr||r<tl)return 0;
if(l>=tl&&r<=tr)return val[x];
pd(x);int mid=l+r>>1;
return query(ls,l,mid,tl,tr)+query(rs,mid+1,r,tl,tr);
}
}tr2_x,tr2_y;//轮廓线上点
struct SG4{
int minn[N<<2],tag[N<<2];
void pd(int x){
minn[ls]=max(minn[ls],tag[x]);
minn[rs]=max(minn[rs],tag[x]);
tag[ls]=max(tag[ls],tag[x]);
tag[rs]=max(tag[x],tag[rs]);
tag[x]=0;
}
void pup(int x){minn[x]=min(minn[ls],minn[rs]);}
void upd(int x,int l,int r,int tl,int tr,int v){
if(l>tr||r<tl)return;
if(l>=tl&&r<=tr){
minn[x]=max(minn[x],v);tag[x]=max(tag[x],v);return;
}
pd(x);int mid=l+r>>1;
upd(ls,l,mid,tl,tr,v);upd(rs,mid+1,r,tl,tr,v);pup(x);
}
int query1(int x,int l,int r,int t){
if(l>t||r<t)return 0;
if(l==r)return minn[x];
pd(x);int mid=l+r>>1;
return query1(ls,l,mid,t)+query1(rs,mid+1,r,t);
}
int query2(int x,int l,int r,int t){
if(minn[x]>t)return n+1;
if(l==r)return l;
pd(x);int mid=l+r>>1,X=query2(ls,l,mid,t);
if(X==n+1)return query2(rs,mid+1,r,t);
return X;
}
}sx,sy;//轮廓线
void updx(Qr x){
int YY=sx.query1(1,1,n,x.x),XX=sy.query1(1,1,n,x.y);
if(XX>x.x&&YY>x.y)return;
if(XX==x.x&&YY==x.y)return;
while(1){
int X=tree.query1(1,1,n,1,x.x);
if(X>x.y)break;
int Y=tree.query2(1,1,n,1,x.x,X),YYY=tx[Y][totx[Y]];
tr_x.upd(1,1,n,Y,-1);tr_y.upd(1,1,n,YYY,-1);
tr2_x.upd(1,1,n,Y,1);tr2_y.upd(1,1,n,x.y,1);
++totx[Y];
if(totx[Y]==tx[Y].size())tree.upd(1,1,n,Y,n+1);
else tree.upd(1,1,n,Y,tx[Y][totx[Y]]);
}
YY=sy.query2(1,1,n,x.x);XX=sx.query2(1,1,n,x.y);
int X=tr2_y.query(1,1,n,YY,x.y);
tr2_y.upd2(1,1,n,YY,x.y);
tr2_y.upd(1,1,n,x.y,X);
sx.upd(1,1,n,XX,x.x,x.y);
sy.upd(1,1,n,YY,x.y,x.x);
}
void updy(Qr x){
int YY=sx.query1(1,1,n,x.x),XX=sy.query1(1,1,n,x.y);
if(XX>x.x&&YY>x.y)return;
if(XX==x.x&&YY==x.y)return;
while(1){
int X=tree.query1(1,1,n,1,x.x);
if(X>x.y)break;
int Y=tree.query2(1,1,n,1,x.x,X),YYY=tx[Y][totx[Y]];
tr_x.upd(1,1,n,Y,-1);tr_y.upd(1,1,n,YYY,-1);
tr2_x.upd(1,1,n,x.x,1);tr2_y.upd(1,1,n,YYY,1);
++totx[Y];
if(totx[Y]==tx[Y].size())tree.upd(1,1,n,Y,n+1);
else tree.upd(1,1,n,Y,tx[Y][totx[Y]]);
}
YY=sy.query2(1,1,n,x.x);XX=sx.query2(1,1,n,x.y);
int X=tr2_x.query(1,1,n,XX,x.x);
tr2_x.upd2(1,1,n,XX,x.x);
tr2_x.upd(1,1,n,x.x,X);
sx.upd(1,1,n,XX,x.x,x.y);
sy.upd(1,1,n,YY,x.y,x.x);
}
int qry(Qr x){
int XX=sy.query1(1,1,n,x.y),YY=sx.query1(1,1,n,x.x);
if(XX>=x.X&&YY>=x.Y&&(XX!=x.X||YY!=x.Y))return n;
int ANS=0;
ANS=tr_x.query(1,1,n,1,x.X)+tr_y.query(1,1,n,1,x.Y);
ANS+=tr2_x.query(1,1,n,1,x.X)+tr2_y.query(1,1,n,1,x.Y);
ANS+=x.ans1;
return ANS;
}
signed main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)scanf("%d%d",&a[i].x,&a[i].y),tr_x.upd(1,1,n,a[i].x,1),tr_y.upd(1,1,n,a[i].y,1);
sort(a+1,a+n+1,cmp1);
for(int i=1;i<=n;++i)tx[a[i].x].push_back(a[i].y);
for(int i=1;i<=n;++i){
if(totx[i]==tx[i].size())tree.upd(1,1,n,i,n+1);
else tree.upd(1,1,n,i,tx[i][0]);
}
for(int i=1;i<=m;++i){
scanf("%d%d%d%d%d",&q[i].o,&q[i].x,&q[i].y,&q[i].X,&q[i].Y);
qr[q[i].X].push_back((Qr2){q[i].Y,n,i});
qr[n+1].push_back((Qr2){q[i].Y,n,i});
}
for(int i=1,j=1;i<=n+1;++i){
int res=-1;if(i==n+1)res=1;
while(j<=n&&a[j].x<=i){tr1.upd(a[j].y,1),++j;}
for(int k=0;k<qr[i].size();++k){
q[qr[i][k].id].ans1+=res*(tr1.qr(qr[i][k].y)-tr1.qr(qr[i][k].x));
}
}
for(int i=1;i<=m;++i){
if(q[i].o==1)updx(q[i]);
else updy(q[i]);
printf("%d\n",qry(q[i])-n);
}
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: 11ms
memory: 61440kb
input:
995 996 950 481 376 18 141 776 711 966 130 727 468 529 47 39 857 563 832 821 776 472 154 914 825 279 332 415 470 361 968 440 45 560 299 755 703 785 744 387 547 382 3 549 344 573 778 424 784 765 280 115 251 434 695 98 463 506 379 38 610 486 305 623 703 244 856 365 117 360 772 847 331 723 663 991 900 ...
output:
423 473 758 313 694 232 333 784 821 154 247 244 504 54 200 370 872 782 734 174 660 467 76 754 77 3 144 974 526 415 439 694 507 577 258 120 243 3 2 319 313 498 218 828 433 623 981 700 120 55 70 499 375 283 387 128 317 139 220 410 22 547 3 385 430 168 34 -3 178 625 677 561 488 672 577 64 144 537 235 5...
result:
wrong answer 67th numbers differ - expected: '32', found: '34'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 2830ms
memory: 240620kb
input:
999996 999996 921339 140126 955508 363759 958698 342406 280137 955674 907511 75721 189876 946586 152058 168837 541857 557702 84498 865987 185574 809224 704828 701026 815379 548000 989515 518951 335439 336866 745570 790616 766723 212893 926629 859003 51261 40866 592510 556235 324926 700261 320946 798...
output:
0 -54899 953730 0 0 512663 0 0 -8006 0 407467 0 0 0 0 420 0 0 0 0 0 0 513245 0 0 0 -86338 0 0 0 0 0 0 0 11756 -106783 0 7822 0 0 0 0 22726 0 0 0 8233 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21227 0 13818 0 0 0 0 0 0 0 6803 0 0 0 0 0 -147994 0 0 0 0 0 0 0 0 0 -108115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8602 0 0 0 0 ...
result:
wrong answer 2nd numbers differ - expected: '0', found: '-54899'
Subtask #3:
score: 0
Time Limit Exceeded
Test #17:
score: 0
Time Limit Exceeded
input:
999995 999997 261379 334440 985281 986034 549380 718157 670003 253925 533027 437989 326806 983213 965935 756259 229069 686789 331338 684961 957559 390618 937820 959719 338153 779814 582581 965418 634156 421264 308778 938878 913059 390904 481477 431492 739774 793015 901442 934600 256704 991485 366691...
output:
160635 633543 123519 313576 450015 383636 574186 2373 203701 326075 117994 567275 652824 199778 380317 380374 105875 373858 788346 703177 609802 648162 367059 497975 57979 478851 745055 75935 543066 251837 769828 436493 480966 235835 509629 757189 763490 396842 262684 2241 267172 165791 558963 16523...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%