QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#381707#7436. Optimal Ordered Problem SolverQingyuCompile Error//C++239.3kb2024-04-07 20:30:142024-04-07 20:30:14

Judging History

你现在查看的是最新测评结果

  • [2024-04-07 20:30:14]
  • 评测
  • [2024-04-07 20:30:14]
  • 提交

answer

#include<bits/stdc++.h>
#define F(i,l,r) for(int i=l;i<r;++i)
#define Fe(i,l,r) for(int i=l;i<=r;++i)
#define Fer(i,l,r) for(int i=l;i>=r;--i)
#if 0
#define pr(...) fprintf(stderr,__VA_ARGS__)
#else
#define pr(...) void(0)
#endif

typedef long long i64;
const int maxn=1e6,maxm=1e6,N=maxn+10;

namespace IO{
const int BUF_SZ=1<<16;
char ib[BUF_SZ+1],*ip=ib+BUF_SZ;
void ipre(int n){
 int c=ib+BUF_SZ-ip;
 if(c<n){
  memcpy(ib,ip,c);
  ip=ib;
  fread(ib+c,1,BUF_SZ-c,stdin)[ib+c]=0;
 }
}
template<class T>
T read(T L,T R){
 ipre(100);
 T x=0,f=1;
 while(*ip<'0'||*ip>'9')if(*ip++=='-')f=-f;
 while(*ip>='0'&&*ip<='9')x=x*10+*ip++-'0';
 x*=f;
 if(\u0021(L<=x&&x<=R)){
  std::cerr<<x<<" not in ["<<L<<","<<R<<"]\n";
  exit(1);
 }
 return x;
}
char ob[BUF_SZ+1],*op=ob;
void opre(int n){
 int c=ob+BUF_SZ-op;
 if(c<n){
  fwrite(ob,1,BUF_SZ-c,stdout);
  op=ob;
 }
}
template<class T>
void write(T x){
 opre(100);
 char ss[100],*sp=ss;
 if(x<T(0))x=-x,*op++='-';
 do *sp++=x%10+'0';while(x/=10);
 while(sp\u0021=ss)*op++=*--sp;
}
template<class T>
void write(T x,char c){
 write(x);
 *op++=c;
}
struct __{
 __(){}
 ~__(){
  fwrite(ob,1,op-ob,stdout);
 }
}_;
};
using IO::read;
using IO::write;
const int MEM=1<<26;
char pool[MEM],*pool_p=pool;

template<class T>
void alloc(T *&p,int sz,bool init=1){
 //p=new T[sz]();
 //return;
 p=reinterpret_cast<T*>(pool_p);
 pool_p+=(sz*sizeof(T)+7)&~7;
 assert(pool_p<pool+MEM);
 if(init)F(i,0,sz)new(p+i)T();
}

template<class T>
struct Undo{
 T &x;
 T x0;
 Undo(T &x):x(x),x0(x){}
 ~Undo(){x=x0;}
};

#define alloc_scope Undo<char*> _##__LINE__(pool_p)
struct Void{
 char _[0];
 template<class T>
 friend void operator*=(T &,Void){}
 friend Void operator+(Void,Void){return Void();}
};

template<class D=Void,class M=Void>
struct MSegTree{
 struct Node{
  D d;
  M m;
  void app(const M &t){
   d*=t;
   m*=t;
  }
  void up(const Node &a,const Node &b){
   d=a.d+b.d;
   d*=m;
  }
 }*tr;
 int mx;
 int n;
 void in(int x){assert(1<=x&&x<=n);}
 void in(int l,int r){assert(1<=l&&l<=r&&r<=n);}
 void alloc(int n){
  for(mx=1;mx<n+2;mx<<=1);
  ::alloc(tr,mx+n+3);
  this->n=n;
 }
 void init(int n,D d0){
  alloc(n);
  Fe(i,1,n)tr[mx+i].d=d0;
  range_update(1,n);
 }
 template<class T>
 void init(int n,T *d0){
  alloc(n);
  Fe(i,1,n)tr[mx+i].d=d0[i];
  range_update(1,n);
 }
 Node &at(int x){
  in(x);
  return tr[mx+x];
 }
 D &operator[](int x){
  in(x);
  return tr[mx+x].d;
 }
 void range_update(int l,int r){
  in(l),in(r);
  l+=mx,r+=mx;
  for(l>>=1,r>>=1;l<r;l>>=1,r>>=1){
   Fe(x,l,r)up(x);
  }
  for(;l;l>>=1)up(l);
 }
 void up(int x){
  tr[x].up(tr[x*2],tr[x*2+1]);
 }
 void add(int x,const D &y){//M=Void
  in(x);
  for(x+=mx;x;x>>=1)tr[x].d=tr[x].d+y;;
 }
 void update(const M &t){
  tr[1].app(t);
 }
 template<class T>
 void update(int x,T y){
  in(x);
  for(tr[x+=mx].d=y;x>1;up(x>>=1));
 }
 void update(int l,int r,const M &t){
  in(l),in(r);
  for(l+=mx-1,r+=mx+1;l^r^1;up(l>>=1),up(r>>=1)){
   if(~l&1)tr[l+1].app(t);
   if(r&1)tr[r-1].app(t);
  }
  for(;l>1;up(l>>=1));
 }
 void update_prefix(int x,const M &t){
  in(x);
  for(x+=mx+1;x>1;up(x>>=1)){
   if(x&1)tr[x-1].app(t);
  }
 }
 void update_suffix(int x,const M &t){
  in(x);
  for(x+=mx-1;x>1;up(x>>=1)){
   if(~x&1)tr[x+1].app(t);
  }
 }
 D query(){
  return tr[1].d;
 }
 D query(int l,int r){
  in(l),in(r);
  assert(l<=r);
  D a1,a2;
  for(l+=mx-1,r+=mx+1;l^r^1;a1*=tr[l>>=1].m,a2*=tr[r>>=1].m){
   if(~l&1)a1=a1+tr[l+1].d;
   if(r&1)a2=tr[r-1].d+a2;
  }
  a1=a1+a2;
  for(;l>1;a1*=tr[l>>=1].m);
  return a1;
 }
 D query_prefix(int r){
  in(r);
  D a1;
  for(r+=mx+1;r>1;r>>=1,a1*=tr[r].m){
   if(r&1)a1=tr[r-1].d+a1;
  }
  return a1;
 }
 D query_suffix(int l){
  in(l);
  D a1;
  for(l+=mx-1;l>1;l>>=1,a1*=tr[l].m){
   if(~l&1)a1=a1+tr[l+1].d;
  }
  return a1;
 }
 void dn(int x){
  tr[x*2].app(tr[x].m);
  tr[x*2+1].app(tr[x].m);
  tr[x].m=M();
 }
 void dna(int x){
  in(x);
  x+=mx;
  for(int c=__builtin_ctz(mx);c>0;--c)dn(x>>c);
 }
 void dna(int l,int r){
  in(l,r);
  l+=mx,r+=mx;
  for(int c=__builtin_ctz(mx);c>0;--c){
   int L=l>>c,R=r>>c;
   Fe(i,L,R)dn(i);
  }
 }
 void dna(){
  F(i,1,mx){
   tr[i*2].app(tr[i].m);
   tr[i*2+1].app(tr[i].m);
   tr[i].m=M();
  }
 }
 template<class T>
 int bsearch_l(int x,T f){//M=Void
  in(x);
  for(x+=mx+1;;x>>=1){
   if(x&1){
    if(f(tr[x-1].d))break;
   }
  }
  for(--x;x<mx;){
   x<<=1;
   if(f(tr[x+1].d))++x;
  }
  x-=mx;
  return x+1;
 }
 template<class T>
 int bsearch_r(int x,T f){//M=Void
  in(x);
  for(x+=mx-1;;x>>=1){
   if(~x&1){
    if(f(tr[x+1].d))break;
   }
  }
  for(++x;x<mx;){
   x<<=1;
   if(\u0021f(tr[x].d))++x;
  }
  x-=mx;
  return x-1;
 }
 template<class T>
 int find_lm(T f){
  int x=1;
  while(x<mx){
   dn(x);
   x<<=1;
   if(\u0021f(tr[x].d))++x;
  }
  x-=mx;
  return x;
 }
};

template<class T>
struct BIT{
 T *a;
 int n;
 void alloc(int n0){
  n=n0;
  ::alloc(a,n+1);
 }
 void add(int x,T y){
  assert(1<=x&&x<=n);
  int _n=n;
  for(;x<=_n;x+=x&-x)a[x]+=y;
 }
 T sum(int x){
  assert(0<=x&&x<=n);
  T s=0;
  for(;x;x-=x&-x)s+=a[x];
  return s;
 }
 void dna(){
  Fe(i,1,n)a[i]+=a[i-(i&-i)];
 }
 T at(int x){
  assert(0<=x&&x<=n);
  return a[x];
 }
 void build(){
  Fe(i,1,n){
   int j=i+(i&-i);
   if(j<=n)a[j]+=a[i];
  }
 }
};
#define CMP(T,x) bool operator<(const T &w)const{return x<w.x;}
#define CMPL(T,x) [](const T &a,const T &b)->bool{return a.x<b.x;}
#define KEYL(T,x) [](const T &a){return a.x;}
template<class T,class F>
void rsort(T *d0,T *d1,int n,int v,F key){
 static int t[1<<20];
 F(i,0,v)t[i]=0;
 F(i,0,n)++t[key(d0[i])];
 int s=0;
 F(i,0,v){
  int a=t[i];
  t[i]=s;
  s+=a;
 }
 F(i,0,n)d1[t[key(d0[i])]++]=d0[i];
}

template<class T,class F>
void rsort2(T *d0,int n,F key){
 alloc_scope;
 T *d1;
 alloc(d1,n,0);
 rsort(d0,d1,n,2048,[key](const T &x){return key(x)&2047;});
 rsort(d1,d0,n,2048,[key](const T &x){return key(x)>>11;});
}
using std::max;
using std::min;

const int inf=1e9;

struct Pos{
 int x,y;
}ps[N],ds[N],ps0[N];
bool in(int x,int l,int r){return l<=x&&x<=r;}

struct XY{
 int x,y;
 XY(int x0=0,int y0=inf):x(x0),y(y0){}
};
XY operator+(XY a,XY b){
 return a.y<b.y?a:b;
}
MSegTree<XY> xyt;
BIT<int> xs0,ys0;
int cur[N];
int f1(int x1,int x2,int y1,int y2){
 if(x1>x2)return 0;
 XY xy=xyt.query(x1,x2);
 if(xy.y>y2)return 0;
 int id=cur[xy.x]++;
 xy.y=(ps0[id].x==ps0[id+1].x?ps0[id+1].y:inf);
 xyt.update(xy.x,xy);
 return id;
}
template<class T>
struct Sum{
 T x;
 Sum(T x0=0):x(x0){}
 operator T(){return x;}
 friend Sum operator+(Sum a,Sum b){return Sum(a.x+b.x);}
};
MSegTree<Sum<int>> xs,ys;
int sumclr(MSegTree<Sum<int>> &ws,int l,int r){
 if(l>r)return 0;
 int s0=ws.query(l,r);
 int s=s0;
 while(s0){
  int x=ws.bsearch_r(l,[](Sum<int> d){return d.x;})+1;
  s0-=ws[x];
  ws.add(x,-ws[x]);
  l=x+1;
 }
 return s;
}
struct Q{
 int x,y,id;
}qs[N];
int qp=0;
int ans[N];

struct MinI{
 int x;
 MinI(int x0=inf):x(x0){}
};
MinI operator+(MinI a,MinI b){return MinI(min(a.x,b.x));}
MSegTree<MinI> domt;
int main(){
 int n=read(1,maxn);
 int m=read(1,maxm);
 bool REV=0;
 Fe(i,1,n){
  ps[i].x=read(1,n);
  ps[i].y=read(1,n);
  if(REV)std::swap(ps[i].x,ps[i].y);
 }
 int n0=n;
 xs0.alloc(n);
 ys0.alloc(n);
 Fe(i,1,n){
  ++xs0.a[ps[i].x];
  ++ys0.a[ps[i].y];
  ps0[i]=ps[i];
 }
 xs0.build();
 ys0.build();
 rsort2(ps0+1,n,KEYL(Pos,y));
 rsort2(ps0+1,n,KEYL(Pos,x));
 xyt.alloc(n);
 Fe(i,1,n){
  Pos &p=ps0[i];
  if(p.x\u0021=ps0[i-1].x){
   xyt[p.x]=XY(p.x,p.y);
   cur[p.x]=i;
  }
 }
 xyt.range_update(1,n);
 xs.alloc(n);
 ys.alloc(n);
 domt.alloc(n+2);
 domt[1]=1;
 domt[n+2]=1;
 domt.range_update(1,n+2);
 Fe(qi,1,m){
  int o=read(1,2);
  int x=read(1,n),y=read(1,n);
  int qx=read(1,n),qy=read(1,n);
  if(REV){
   o=3-o;
   std::swap(x,y);
   std::swap(qx,qy);
  }
  int mx=x+(o==1),my=y+(o==2);
  int dp=0;
  for(;;){
   int i=domt.find_lm([my](MinI d){return d.x<=my;});
   if(i>mx)break;
   ds[++dp]={i,domt[i].x};
   domt.update(i,inf);
  }
  if(dp){
   int x0=ds[1].x,y0=ds[dp].y;
   ds[0].y=my;
   ds[dp+1].x=mx;
   Fe(i,1,dp){
    int x1=ds[i].x,x2=ds[i+1].x-1;
    int y1=ds[i].y,y2=my-1,y3=ds[i-1].y-1;
    if(o==1&&x1<=x2){
     int s=sumclr(ys,y1,y3);
     if(s)xs.add(x1,s);
    }
    if(o==2&&y1<=y3){
     int s=sumclr(xs,x1,x2);
     if(s)ys.add(y1,s);
    }
    for(;;){
     int id=f1(x1,x2,y1,y2);
     if(\u0021id)break;
     Pos &p=ps0[id]; 
     if(o==1)xs.add(p.x,1);
     else ys.add(p.y,1);
     --n0;
     xs0.add(p.x,-1);
     ys0.add(p.y,-1);
    }
   }
   if(x0<mx||x0==mx&&y0==my){
    domt.update(x0,my);
   }
   if(y0<my){
    domt.update(mx,y0);
   }
  }
  int y0=domt.query_prefix(qx).x;
  int ans0=0;
  if(y0<=qy){
   int x0=domt.find_lm([qy](MinI d){return d.x<=qy;});
   qs[qp++]={qx+1,qy+1,qi};
   ans0+=n;
   ans0-=n0-xs0.sum(qx);
   ans0-=n0-ys0.sum(qy);
   ans0-=xs.query().x-xs.query(x0,qx).x;
   ans0-=ys.query().x-ys.query(y0,qy).x;
   ans[qi]=ans0;
  }
 }
 rsort2(qs,qp,KEYL(Q,x));
 BIT<int> bit;
 bit.alloc(n+1);
 int pp=n;
 Fer(i,qp-1,0){
  Q &q=qs[i];
  for(;pp&&ps0[pp].x>=q.x;--pp)bit.add(n+1-ps0[pp].y,1);
  ans[q.id]+=bit.sum(n+1-q.y);
 }
 Fe(i,1,m)write(ans[i],'\n');
 return 0;
}

Details

answer.code:32:5: error: universal character \u0021 is not valid in an identifier
   32 |  if(\u0021(L<=x&&x<=R)){
      |     ^
answer.code:52:8: error: universal character \u0021 is not valid in an identifier
   52 |  while(sp\u0021=ss)*op++=*--sp;
      |        ^
answer.code:263:7: error: universal character \u0021 is not valid in an identifier
  263 |    if(\u0021f(tr[x].d))++x;
      |       ^
answer.code:274:7: error: universal character \u0021 is not valid in an identifier
  274 |    if(\u0021f(tr[x].d))++x;
      |       ^
answer.code:424:8: error: universal character \u0021 is not valid in an identifier
  424 |   if(p.x\u0021=ps0[i-1].x){
      |        ^
answer.code:470:9: error: universal character \u0021 is not valid in an identifier
  470 |      if(\u0021id)break;
      |         ^
answer.code: In function ‘void IO::write(T)’:
answer.code:52:8: error: ‘sp!’ was not declared in this scope; did you mean ‘sp’?
   52 |  while(sp\u0021=ss)*op++=*--sp;
      |        ^~~~~~~~
      |        sp
answer.code: In function ‘int main()’:
answer.code:424:8: error: ‘struct Pos’ has no member named ‘x!’; did you mean ‘x’?
  424 |   if(p.x\u0021=ps0[i-1].x){
      |        ^~~~~~~
      |        x
answer.code:470:9: error: ‘!id’ was not declared in this scope; did you mean ‘id’?
  470 |      if(\u0021id)break;
      |         ^~~~~~~~
      |         id
answer.code: In instantiation of ‘int MSegTree<D, M>::bsearch_r(int, T) [with T = sumclr(MSegTree<Sum<int> >&, int, int)::<lambda(Sum<int>)>; D = Sum<int>; M = Void]’:
answer.code:381:21:   required from here
answer.code:263:14: error: ‘!f’ was not declared in this scope; did you mean ‘f’?
  263 |    if(\u0021f(tr[x].d))++x;
      |       ~~~~~~~^~~~~~~~~
      |       f
answer.code: In instantiation of ‘T IO::read(T, T) [with T = int]’:
answer.code:401:12:   required from here
answer.code:32:11: error: ‘!’ was not declared in this scope
   32 |  if(\u0021(L<=x&&x<=R)){
      |     ~~~~~~^~~~~~~~~~~~
answer.code: In instantiation of ‘int MSegTree<D, M>::find_lm(T) [with T = main()::<lambda(MinI)>; D = MinI; M = Void]’:
answer.code:448:22:   required from here
answer.code:274:14: error: ‘!f’ was not declared in this scope; did you mean ‘f’?
  274 |    if(\u0021f(tr[x].d))++x;
      |       ~~~~~~~^~~~~~~~~
      |       f
answer.code: In instantiation of ‘int MSegTree<D, M>::find_lm(T) [with T = main()::<lambda(MinI)>; D = MinI; M = Void]’:
answer.code:489:23:   required from here
answer.code:274:14: error: ‘!f’ was not declared in this scope; did you mean ‘f’?
  274 |    if(\u0021f(tr[x].d))++x;
      |       ~~~~~~~^~~~~~~~~
      |       f