蒟蒻的FHQ-Treap 编译不过,求调QWQ

P3391 【模板】文艺平衡树

Leonard_Mitchell @ 2023-06-19 18:02:10

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<cstring>
#include<string>
#include<random>

using namespace std;

int n,m;
int cnt;
int root;

struct str{
    int val,key,size,l,r,lazy;
}fhq[1000005];

void update(int x){
    fhq[x].size=fhq[fhq[x].l].size+fhq[fhq[x].r].size+1;
    return ;
}

void pushdown(int dat){
    if(fhq[dat].lazy){
        swap(fhq[dat].l,fhq[dat].r);
        fhq[fhq[dat].l].lazy^=1;
        fhq[fhq[dat].r].lazy^=1;
        fhq[dat].lazy=0;
    }
    return ;
}

void split(int now,int dat,int &x,int &y){//分裂 
    if(now==0){
        x=y=0;
        return ;
    }
    pushdown(now);
    if(dat<fhq[now].val)
    {
        y=now;
        split(fhq[now].l,dat,x,fhq[now].l);
    }else{
        x=now;
        split(fhq[now].r,dat-fhq[fhq[now].l].size-1,fhq[now].r,y);
    }
    update(now);
}

int merge(int x,int y){//合并,返回合并后的根 
    if(x==0||y==0) return x+y;
    if(fhq[x].key<=fhq[y].key){
        pushdown(x);
        fhq[x].r=merge(fhq[x].r,y);
        update(x);
        return x;
    }else{
        pushdown(y);
        fhq[y].l=merge(x,fhq[y].l);
        update(y);
        return y;
    }
}

int add(int dat){//增加结点 
    fhq[++cnt].size=1;
    fhq[cnt].key=rand();
    fhq[cnt].val=dat;
    return cnt;
}

void ins(int dat){//结点进树
    int x,y,z;  
    split(root,dat,x,y);
    z=add(dat);
    root=merge(merge(x,z),y);
    return ;
}

void traversal(int dat){
    pushdown(dat);
    if(fhq[dat].l) traversal(fhq[dat].l);
    cout<<fhq[dat].val<<" ";
    if(fhq[dat].r) traversal(fhq[dat].r);
    return ;
}

int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        ins(i);
        root=merge(root,i);
    }
    while(m--){
        int l,r;
        cin>>l>>r;
        int x,y,z;
        split(root,r,x,y);
        split(x,l-1,x,z);
        fhq[z].lazy^=1;
        root=merge(merge(x,z),y);
    }
    traversal(root);
    return 0;
}

rt,DEVC++编译蹦了个

// Copyright (C) 2007-2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file bits/c++0x_warning.h
 *  This is an internal header file, included by other library headers.
 *  Do not attempt to use it directly. @headername{iosfwd}
 */

#ifndef _CXX0X_WARNING_H
#define _CXX0X_WARNING_H 1

#if __cplusplus < 201103L
#error This file requires compiler and library support for the \
ISO C++ 2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options.
#endif

#endif

不知道怎么错了


by CarrotMeow @ 2023-06-19 18:40:17

@Grace 用什么版本编译的?这里应该是提示版本太低,要到 C++11。


by CarrotMeow @ 2023-06-19 18:41:11

@Grace Dev C++ 默认是 C++98。

题外话:Dev C艹 是真的难用啊啊啊


by Leonard_Mitchell @ 2023-06-19 19:12:48

@StandardManager 好的,我试一下


by Leonard_Mitchell @ 2023-06-19 19:14:57

@StandardManager 我用洛谷试了一下,结果数组都开得很小了,还是超出内存限制


|