QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#654671 | #7436. Optimal Ordered Problem Solver | lichenghan | 0 | 3137ms | 262992kb | C++14 | 7.0kb | 2024-10-18 21:56:33 | 2024-10-18 21:56:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
inline constexpr int diff(const int& x,const int& y){ return x>y?x-y:y-x; }
#define USE_FREAD_FWRITE
// #define READ_NEGATIVE
// #define WRITE_NEGATIVE
namespace IO{
#ifdef USE_FREAD_FWRITE
#define SIZE (1<<20)
char in[SIZE],out[SIZE],*p1=in,*p2=in,*p3=out;
char getchar(){ return p1==p2&&(p2=(p1=in)+fread(in,1,SIZE,stdin),p1==p2)?EOF:*p1++; }
void flush(){ int len=p3-out; fwrite(p3=out,1,len,stdout); }
void putchar(char ch){ if(p3==out+SIZE)flush(); *p3++=(ch); }
struct Flush{~Flush(){flush();}}_;
#else
char getchar(){ return ::getchar(); }
void putchar(char ch){ ::putchar(ch); }
void flush(){}
#endif
template<typename type=int> inline type read(){
#ifdef READ_NEGATIVE
type x(0);bool flag(0);char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())flag^=ch=='-';
for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
return flag?-x:x;
#else
type x(0);char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar());
for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
return x;
#endif
}
template<typename type>
inline void write(type x){
#ifdef WRITE_NEGATIVE
if(x<0)x=-x,putchar('-');
#endif
static int Stack[50],top(0);
do Stack[++top]=x%10,x/=10;while(x);
while(top) putchar(Stack[top--]|48);
}
}
using IO::read;
using IO::write;
int n,m;
array<int,2> a[N];
int tim[N];
int stk[N],top;
int opt[N],cx[N],cy[N],qx[N],qy[N];
int ans[N];
struct segt{
// untouched
// obt: y min
int t[N<<2];
inline void psu(int p){ t[p]=min(t[p<<1],t[p<<1|1]); }
void build(int l,int r,int p){
if(l==r){
t[p]=a[l][1];
return;
}
int mid=(l+r)>>1;
build(l,mid,p<<1);
build(mid+1,r,p<<1|1);
psu(p);
}
void q(int l,int r,int p,int x,int y){
if(t[p]>y) return;
if(l==r){
t[p]=N;
stk[++top]=l;
return;
}
int mid=(l+r)>>1;
if(x<=mid) q(l,mid,p<<1,x,y);
else q(l,mid,p<<1,mid,y),q(mid+1,r,p<<1|1,x,y);
psu(p);
}
void init(){
build(1,n,1);
}
void q(int x,int y){
top=0;
x=upper_bound(a+1,a+n+1,(array<int,2>){x,N})-a-1;
if(!x) return;
q(1,n,1,x,y);
}
}Tw;
struct AVL{
struct node{
int ls,rs,ht,siz;
int x,y,cx,cy;
}; node t[N]; int nc,rt;
void psu(int p){
if(!p) return;
t[p].ht=max(t[t[p].ls].ht,t[t[p].rs].ht)+1;
t[p].siz=t[t[p].ls].siz+t[t[p].rs].siz+1;
}
void adtx(int p,int x){
if(p) t[p].x=t[p].cx=x;
}
void adty(int p,int y){
if(p) t[p].y=t[p].cy=y;
}
void psd(int p){
if(t[p].cx){
adtx(t[p].ls,t[p].cx);
adtx(t[p].rs,t[p].cx);
t[p].cx=0;
}
if(t[p].cy){
adty(t[p].ls,t[p].cy);
adty(t[p].rs,t[p].cy);
t[p].cy=0;
}
}
void print(int p){
if(!p) return;
psd(p);
print(t[p].ls);
printf("#%d: ls=%d rs=%d ht=%d siz=%d x=%d y=%d\n",
p,t[p].ls,t[p].rs,t[p].ht,t[p].siz,t[p].x,t[p].y);
print(t[p].rs);
}
void right(int& p){
int q=t[p].ls;
t[p].ls=t[q].rs;
t[q].rs=p;
psu(p); psu(q);
p=q;
}
void left(int& p){
int q=t[p].rs;
t[p].rs=t[q].ls;
t[q].ls=p;
psu(p); psu(q);
p=q;
}
void insert(int x,int y,int& p){
if(!p){
p=++nc;
t[p].x=x; t[p].y=y; t[p].siz=1;
return;
}
psd(p);
if(x<=t[p].x&&y>=t[p].y){
insert(x,y,t[p].ls);
if(t[t[p].ls].ht==t[t[p].rs].ht+2){
if(t[t[t[p].ls].ls].ht>=t[t[t[p].ls].rs].ht){
right(p);
}else{
left(t[p].ls);
right(p);
}
}
}else{
insert(x,y,t[p].rs);
if(t[t[p].rs].ht==t[t[p].ls].ht+2){
if(t[t[t[p].rs].rs].ht>=t[t[t[p].rs].ls].ht){
left(p);
}else{
right(t[p].rs);
left(p);
}
}
}
psu(p);
if(!(diff(t[t[p].ls].ht,t[t[p].rs].ht)<=1)){
print(p);
assert(("AVL incorrect",false));
}
// assert(t[0].siz==0);
}
void insert(int x,int y){
// printf("insert %d %d!\n",x,y);
insert(x,y,rt);
// print(rt);
}
int cov(int x,int y,int op){
// printf("cov %d %d %d\n",x,y,op);
int p=rt;
while(p){
if(t[p].x>x){
p=t[p].ls;
}else if(t[p].y>y){
p=t[p].rs;
}else{
break;
}
}
if(!p) return t[rt].siz;
// printf("p = %d\n",p);
if(op==1) t[p].x=x;
if(op==2) t[p].y=y;
int ans=1;
int u=t[p].ls;
while(u){
if(t[u].y<=y){
// printf("ans = %d\n",ans);
if(op==1) t[u].x=x;
if(op==2) t[u].y=y;
if(op==0) ans+=1+t[t[u].rs].siz;
else if(op==1) adtx(t[u].rs,x);
else adty(t[u].rs,x);
// printf("count %d\n",t[u].rs);
// printf("ans = %d\n",ans);
u=t[u].ls;
}else{
u=t[u].rs;
}
}
u=t[p].rs;
while(u){
if(t[u].x<=x){
// printf("ans = %d\n",ans);
if(op==1) t[u].x=x;
if(op==2) t[u].y=y;
if(op==0) ans+=1+t[t[u].ls].siz;
else if(op==1) adtx(t[u].ls,x);
else adty(t[u].ls,x);
// printf("count %d\n",t[u].ls);
// printf("ans = %d\n",ans);
u=t[u].rs;
}else{
u=t[u].ls;
}
}
// printf("tot=%d under=%d\n",t[rt].siz,ans);
// assert(t[0].siz==0);
// print(rt);
return t[rt].siz-ans;
}
}Ts;
struct BIT_suf{
int t[N];
void c(int x){ for(;x;x&=x-1) t[x]++; }
int q(int x){ int r=0; for(;x<N;x+=x&-x) r+=t[x]; return r; }
}T1,T2,T3;
struct BIT_sufmin{
int t[N];
BIT_sufmin(){ memset(t,0x3f,sizeof(t)); }
void c(int x,int d){ for(;x;x&=x-1) t[x]=min(t[x],d); }
int q(int x){ int r=1e9; for(;x<N;x+=x&-x) r=min(r,t[x]); return r; }
}T4;
vector<int> rtc[N],rxc[N],rxq[N],rxqc[N];
int main(){
n=read(),m=read();
for(int i=1;i<=n;i++) {
for(int &j:a[i]) j=read();
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++){
rxc[a[i][0]].push_back(i);
}
Tw.init();
for(int i=1;i<=m;i++){
opt[i]=read(); cx[i]=read(); cy[i]=read(); qx[i]=read(); qy[i]=read();
// printf("op: %d %d %d %d %d\n",opt[i],cx[i],cy[i],qx[i],qy[i]);
rxq[qx[i]].push_back(i);
rxqc[cx[i]].push_back(i);
}
for(int i=1;i<=m;i++){
if(opt[i]==1) Ts.cov(cx[i],cy[i],2);
else Ts.cov(cx[i],cy[i],1);
Tw.q(cx[i],cy[i]);
rtc[i]=vector<int>(stk+1,stk+top+1);
for(int j=1;j<=top;j++){
tim[stk[j]]=i;
int x=a[stk[j]][0],y=a[stk[j]][1];
// printf("online %d %d\n",x,y);
if(opt[i]==1) y=cy[i];
else x=cx[i];
Ts.insert(x,y);
}
ans[i]=Ts.cov(qx[i],qy[i],0);
// printf("ans[%d] = %d\n",i,ans[i]);
}
for(int i=1;i<=n;i++) if(!tim[i]) {
T1.c(a[i][0]);
T2.c(a[i][1]);
}
// puts("--------------");
for(int t=m;t>=1;t--){
ans[t]+=T1.q(qx[t]+1)+T2.q(qy[t]+1);
// printf("ans[%d] = %d\n",t,ans[t]);
for(int i:rtc[t]){
T1.c(a[i][0]);
T2.c(a[i][1]);
}
}
// puts("-------------");
for(int x=n;x>=1;x--){
// printf("x = %d: \n",x);
for(int i:rxq[x]){
ans[i]-=T3.q(qy[i]+1);
// printf("ans[%d] = %d\n",i,ans[i]);
}
for(int i:rxc[x]){
// printf("c %d!\n",a[i][1]);
T3.c(a[i][1]);
}
}
for(int x=n;x>=1;x--){
for(int i:rxq[x]){
if(T4.q(qy[i]+1)<=i) ans[i]=n;
// printf("q %d %d\n",qx[i],qy[i]);
}
for(int i:rxqc[x]){
T4.c(cy[i],i);
// printf("c %d %d\n",cx[i],cy[i]);
}
}
for(int i=1;i<=m;i++){
write(n-ans[i]);
IO::putchar('\n');
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 18ms
memory: 124196kb
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 32 0 178 625 677 561 488 672 577 64 144 537 235 54...
result:
wrong answer 269th numbers differ - expected: '130', found: '132'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 1843ms
memory: 257792kb
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 0 953730 0 0 512663 0 0 0 0 407467 0 0 0 0 420 0 0 0 0 0 0 513245 0 0 0 0 0 0 0 0 0 0 0 11756 0 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 0 0 13818 352748 0 0 0 0 0 0 6803 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8602 0 0 0 0 0 0 0 15717 0 0 0 0 0 0 0 0 0 0...
result:
wrong answer 66th numbers differ - expected: '349438', found: '352748'
Subtask #3:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 3137ms
memory: 262992kb
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 373857 788346 703176 609801 648161 367059 497975 57979 478851 745054 75935 543062 251837 769828 436489 480966 235835 509625 757188 763486 396842 262680 2240 267171 165787 558963 16523...
result:
wrong answer 55th numbers differ - expected: '515228', found: '515231'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%