QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#126975#21566. 四维偏序NOI_AK_ME#Compile Error//C++235.0kb2023-07-19 11:34:412023-07-19 11:34:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-19 11:34:42]
  • 评测
  • [2023-07-19 11:34:41]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#define siz(x) ((x)?((x)->size):(0))
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const int maxn=100010;
const double A=0.65;
struct node{//Scapegoat Tree
    int data,size;
    node *lc,*rc,*prt;
    node(int d=0):data(d),size(1),lc(NULL),rc(NULL),prt(NULL){}
    inline void refresh(){size=siz(lc)+siz(rc)+1;}
}*root[maxn];
struct B{
    int id,a,b,c;
    bool operator<(const B &a)const{return this->a<a.a;}
}a[maxn],b[maxn];
void CDQ(int,int);
void add(int,int);
void del(int,int);
int query(int,int);
void insert(int);
void erase(int);
int rank(int);
node *insert(node*);
node *find(int);
node *erase(node*);
node *findmax(node*);
void rebuild(node*);
void zorder(node*);
void removetree(node*);
node *rebuild(int,int);
int n,T,cnt,data[maxn];
long long ans=0ll;
int main(){
#define MINE
#ifdef MINE
    freopen("partial_order.in","r",stdin);
    freopen("partial_order.out","w",stdout);
#endif
    scanf("%d",&n);
    for(int i=1;i<=n;i++)a[i].id=i;
    for(int i=1;i<=n;i++)scanf("%d",&a[i].a);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].b);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].c);
    CDQ(1,n);
    printf("%lld",ans);
#ifndef MINE
    printf("\n-------------------------DONE-------------------------\n");
    for(;;);
#endif
    return 0;
}
void CDQ(int l,int r){
    if(l>=r)return;
    int mid=(l+r)>>1;
    CDQ(l,mid);
    CDQ(mid+1,r);
    int i=l,j=mid+1,k=l;
    while(i<=mid&&j<=r){
        if(a[i]<a[j])b[k++]=a[i++];
        else b[k++]=a[j++];
    }
    while(i<=mid)b[k++]=a[i++];
    while(j<=r)b[k++]=a[j++];
    for(int i=l;i<=r;i++){
        a[i]=b[i];
        if(a[i].id<=mid)add(a[i].b,a[i].c);
        else ans+=query(a[i].b,a[i].c);
    }
    for(int i=l;i<=r;i++)if(a[i].id<=mid)del(a[i].b,a[i].c);
}
void add(int x,int d){
    while(x<=n){
        T=x;
        insert(d);
        x+=lowbit(x);
    }
}
void del(int x,int d){
    while(x<=n){
        T=x;
        erase(d);
        x+=lowbit(x);
    }
}
int query(int x,int d){
    int ans=0;
    while(x){
        T=x;
        ans+=rank(d);
        x-=lowbit(x);
    }
    return ans;
}
void insert(int x){
    node *rt=insert(new node(x));
    if(rt)rebuild(rt);
}
void erase(int x){
    node *rt=erase(find(x));
    if(rt)rebuild(rt);
}
int rank(int x){
    node *rt=root[T];
    int ans=0;
    while(rt){
        if(x<=rt->data)rt=rt->lc;
        else{
            ans+=siz(rt->lc)+1;
            rt=rt->rc;
        }
    }
    return ans;
}
node *insert(node *x){
    if(!root[T]){
        root[T]=x;
        return NULL;
    }
    node *rt=root[T];
    for(;;){
        if(x->data<rt->data){
            if(rt->lc)rt=rt->lc;
            else{
                rt->lc=x;
                break;
            }
        }
        else{
            if(rt->rc)rt=rt->rc;
            else{
                rt->rc=x;
                break;
            }
        }
    }
    x->prt=rt;
    x=NULL;
    for(;rt;rt=rt->prt){
        rt->refresh();
        if(max(siz(rt->lc),siz(rt->rc))>A*rt->size)x=rt;
    }
    return x;
}
node *find(int x){
    node *rt=root[T];
    while(rt){
        if(x==rt->data)return rt;
        else if(x<rt->data)rt=rt->lc;
        else rt=rt->rc;
    }
    return NULL;
}
node *erase(node *x){
    if(x->lc&&x->rc){
        node *y=findmax(x->lc);
        x->data=y->data;
        return erase(y);
    }
    if(!x->lc&&!x->rc){
        if(x->prt){
            if(x==x->prt->lc)x->prt->lc=NULL;
            else x->prt->rc=NULL;
        }
        else root[T]=NULL;
    }
    else if(x->lc&&!x->rc){
        x->lc->prt=x->prt;
        if(x->prt){
            if(x==x->prt->lc)x->prt->lc=x->lc;
            else x->prt->rc=x->lc;
        }
        else root[T]=x->lc;
    }
    else if(!x->lc&&x->rc){
        x->rc->prt=x->prt;
        if(x->prt){
            if(x==x->prt->lc)x->prt->lc=x->rc;
            else x->prt->rc=x->rc;
        }
        else root[T]=x->rc;
    }
    node *rt=x->prt;
    delete x;
    x=NULL;
    for(;rt;rt=rt->prt){
        rt->refresh();
        if(max(siz(rt->lc),siz(rt->rc))>A*rt->size)x=rt;
    }
    return x;
}
node *findmax(node *x){
    while(x->rc)x=x->rc;
    return x;
}
void rebuild(node *rt){
    cnt=0;
    zorder(rt);
    node *x=rebuild(1,cnt);
    x->prt=rt->prt;
    if(rt->prt){
        if(rt==rt->prt->lc)rt->prt->lc=x;
        else rt->prt->rc=x;
    }
    else root[T]=x;
    removetree(rt);
}
void removetree(node *x){
    if(!x)return;
    removetree(x->lc);
    removetree(x->rc);
    delete x;
}
void zorder(node *x){
    if(!x)return;
    zorder(x->lc);
    data[++cnt]=x->data;
    zorder(x->rc);
}
node *rebuild(int l,int r){
    if(l>r)return NULL;
    int mid=(l+r)>>1;
    node *x=new node(data[mid]);
    x->lc=rebuild(l,mid-1);
    if(x->lc)x->lc->prt=x;
    x->rc=rebuild(mid+1,r);
    if(x->rc)x->rc->prt=x;
    x->refresh();
    return x;
}

詳細信息

answer.code: In function ‘int query(int, int)’:
answer.code:92:14: error: reference to ‘rank’ is ambiguous
   92 |         ans+=rank(d);
      |              ^~~~
In file included from /usr/include/c++/11/bits/move.h:57,
                 from /usr/include/c++/11/bits/stl_pair.h:59,
                 from /usr/include/c++/11/utility:70,
                 from /usr/include/c++/11/algorithm:60,
                 from answer.code:3:
/usr/include/c++/11/type_traits:1319:12: note: candidates are: ‘template<class> struct std::rank’
 1319 |     struct rank
      |            ^~~~
answer.code:25:5: note:                 ‘int rank(int)’
   25 | int rank(int);
      |     ^~~~
answer.code: In function ‘void zorder(node*)’:
answer.code:219:5: error: reference to ‘data’ is ambiguous
  219 |     data[++cnt]=x->data;
      |     ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/streambuf:41,
                 from /usr/include/c++/11/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/11/iterator:66,
                 from /usr/include/c++/11/bits/ranges_algobase.h:36,
                 from /usr/include/c++/11/bits/ranges_algo.h:35,
                 from /usr/include/c++/11/algorithm:64,
                 from answer.code:3:
/usr/include/c++/11/bits/range_access.h:319:5: note: candidates are: ‘template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)’
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:310:5: note:                 ‘template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])’
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:300:5: note:                 ‘template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)’
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:290:5: note:                 ‘template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)’
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
answer.code:34:13: note:                 ‘int data [100010]’
   34 | int n,T,cnt,data[maxn];
      |             ^~~~
answer.code: In function ‘node* rebuild(int, int)’:
answer.code:225:22: error: reference to ‘data’ is ambiguous
  225 |     node *x=new node(data[mid]);
      |                      ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/streambuf:41,
                 from /usr/include/c++/11/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/11/iterator:66,
                 from /usr/include/c++/11/bits/ranges_algobase.h:36,
                 from /usr/include/c++/11/bits/ranges_algo.h:35,
                 from /usr/include/c++/11/algorithm:64,
                 from answer.code:3:
/usr/include/c++/11/bits/range_access.h:319:5: note: candidates are: ‘template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)’
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:310:5: note:                 ‘template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])’
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:300:5: note:                 ‘template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)’
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:290:5: note:                 ‘template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)’
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
answer.code:34:13: note:                 ‘int data [100010]’
   34 | int n,T,cnt,data[maxn];
      |             ^~~~
answer.code: In function ‘int main()’:
answer.code:39:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |     freopen("partial_order.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:40:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |     freopen("partial_order.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:42:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn...