其他分享
首页 > 其他分享> > le

le

作者:互联网

点击查看代码
#include <cstdio>
#include <vector>
#include <map>
#include <iostream>
//我就知道使map之类的东西绝对不是什么好事;
using namespace std;

namespace bikuhiku {
	signed bikuhiku_signal;
    char bikuhiku_temp_char;
    long long bikuhiku_count;
    #define _sg bikuhiku_signal
    #define _tc bikuhiku_temp_char
    #define _ct bikuhiku_count
    //These functions are used to judge the type of char;
    bool Digit(char _target) {
        if(_target >= '0'&&_target <= '9') return true;
        return false;
    }
    bool Break(char _target) {
        if(_target == 10) return false;
        if(_target == 32) return false;
        return _target;
    }
    bool Little(char _target) {
        if(_target >= 'a'&&_target <= 'z') 
            return true;
        return false;
    }
    bool Great(char _target) {
        if(_target >= 'A'&&_target <= 'Z') 
            return true;
        return false;
    }
    int allType(char _target) {
        if(_target == 32) return 0;
        if(_target == 10) return 10;
        if(Digit(_target)) return 1;
        if(Little(_target)) return 2;
        if(Great(_target)) return 3;
        return 4;
    }
    //These functions are used to input;
    template <typename Tec> 
    int get_int(Tec &_aim) {
        _aim = 0, _sg = 1;
        _tc = getchar();
        for(;!Digit(_tc);_tc = getchar()) {
            if(_tc == '-') _sg = -1;
            if(_tc == 0) return 0;
        }
        for(;Digit(_tc);_tc = getchar()) 
            _aim = (_aim<<1)+(_aim<<3)+_tc-'0';
        _aim *= _sg;
        return 1;
    }
    template <typename Tec,typename ...Args>
    inline void get_int(Tec &aim,Args &...args) {
        get_int(aim);
        get_int(args...);
    }
    template <typename Tec> 
    int format_get_int(Tec &_aim,Tec _length) {
        _aim = 0, _sg = 1;
        _tc = getchar();
        for(;!Digit(_tc);_tc = getchar()) {
            if(_tc == '-') _sg = -1;
            if(_tc == 0) return 0;
        }
        for(;Digit(_tc);_tc = getchar(),--_length) {
            _aim = (_aim<<1)+(_aim<<3)+_tc-'0';
            if(_length == 1) 
                break;
        }
        _aim *= _sg;
        return 1;
    }
    int get_str(char *_aim) {
        _ct = 0;
        _tc = getchar();
        for(;Break(_tc);_tc = getchar()) 
            _aim[_ct++] = _tc;
        _aim[_ct] = 0;
        return _tc;
    }
    int get_line(char *_aim) {
        _ct = 0;
        _tc = getchar();
        for(;Break(_tc)|(_tc == 32);_tc = getchar()) 
            _aim[_ct++] = _tc;
        _aim[_ct] = 0;
        return _tc;
    }
    template <typename Tec>
    void put_int(Tec contents) {
        if(contents > 9) put_int(contents/10);
        putchar(contents%10+48);
    }
    template <typename Tec,typename ...Args>
    inline void put_int(Tec &aim,Args &...args) {
        put_int(aim);
        put_int(args...);
    }
    #undef _sg
    #undef _tc
    #undef _ct
    
    template <typename Tec> 
    Tec max(Tec comp_x,Tec comp_y) {
        return comp_x > comp_y ? comp_x : comp_y;
    }
    template <typename Tec>
    Tec min(Tec comp_x,Tec comp_y) {
        return comp_x < comp_y ? comp_x : comp_y;
    }
} using namespace bikuhiku;

enum {
	the_size = 100010
};
class SPLAY {
	private : 
		struct TREE {
			int cid[2], pid;
			int val;
			int size, cnt;
		} tree[the_size];
		#define cid(id,which) tree[id].cid[which]
		#define rid(id) tree[id].cid[1]
		#define lid(id) tree[id].cid[0]
		#define pid(id) tree[id].pid
		#define val(id) tree[id].val
		#define size(id) tree[id].size
		#define cnt(id) tree[id].cnt
		int tree_tot, ROOT;
		void initial() {
			tree_tot = ROOT = 0;
		}
		void pushup(int id) {
			size(id) = size(cid(id,0))+size(cid(id,1))+cnt(id);
		}
		bool get(int id) {
			return id == rid(pid(id));
			//if id is pid(id)'s right son return 1;
			//else return 0;
		}
		void clear(int id) {
			lid(id) = rid(id) = pid(id) = val(id) = size(id) = cnt(id) = 0;
		}
		void _rorate(int id) {
			int f = pid(id), g = pid(f), ch = get(id);
			cid(f,ch) = cid(id,ch^1);
			if(cid(id,ch^1)) pid(cid(id,ch^1)) = f;
			cid(id,ch^1) = f;
			pid(f) = id;
			pid(id) = g;
			if(g) cid(g,f == cid(g,1)) = id;
			pushup(f);
			pushup(id);
		}
		void _splay(int id) {
			for(int f = pid(id);f = pid(id), f;_rorate(id)) 
				if(pid(f)) _rorate(get(id) == get(f) ? f : id);
			ROOT = id;
			//把id旋转到根节点;
		}
		void conduct_insert(int v) {
			if(!ROOT) {
				val(++tree_tot) = v;
				cnt(tree_tot)++;
				ROOT = tree_tot;
				pushup(ROOT);
				return;
			}
			int id = ROOT, f = 0;
			while(1) {
				if(val(id) == v) {
					cnt(id)++;
					pushup(id);
					pushup(f);
					_splay(id);
					break;
				}
				f = id;
				id = cid(id,val(id) < v);
				if(!id) {
					id = ++tree_tot;
					val(id) = v;
					cnt(id)++;
					pid(id) = f;
					cid(f,val(f) < v) = id;
					pushup(id);
					pushup(f);
					_splay(id);
					break;
				}
			}
		}
		int conduct_rank(int v) {
			int res = 0;
			int id = ROOT;
			while(1) {
				if(v < val(id)) {
					id = lid(id);
				} else {
					res += size(lid(id));
					if(v == val(id)) {
						_splay(id);
						return res+1;
					}
					res += cnt(id);
					id = rid(id);
				}
			}
		}
		int conduct_number(int k) {
			int id = ROOT;
			while(1) {
				if(lid(id)&&k <= size(lid(id))) {
					id = lid(id);
				} else {
					k -= cnt(id)+size(lid(id));
					if(k <= 0) {
						_splay(id);
						return val(id);
					}
					id = cid(id,1);
				}
			}
		}
		int conduct_pre() {
			int id = lid(ROOT);
			if(!id) return id;
			while(rid(id)) id = rid(id);
			_splay(id);
			return id;
		}
		int conduct_suc() {
			int id = rid(ROOT);
			if(!id) return id;
			while(lid(id)) id = lid(id);
			_splay(id);
			return id;
		}
		void conduct_delete(int v) {
			conduct_rank(v);
			int id = ROOT;
			if(cnt(id) > 1) {
				cnt(id)--;
				pushup(id);
				return;
			}
			if(!lid(id)&&!rid(id)) {
				clear(id);
				ROOT = 0;
				return;
			}
			if(!lid(id)) {
				ROOT = rid(ROOT);
				pid(ROOT) = 0;
				clear(id);
				return;
			}
			if(!rid(id)) {
				ROOT = lid(ROOT);
				pid(ROOT) = 0;
				clear(id);
				return;
			}
			int x = conduct_pre();
			pid(rid(id)) = x;
			rid(x) = rid(id);
			clear(id);
			pushup(ROOT);
		}
		#undef cid
		#undef rid
		#undef lid
		#undef pid
		#undef val
		#undef size
		#undef cnt
	public : 
		void Init() {
			initial();
		}
		void Insert(int v) {
			conduct_insert(v);
		}
		void Delete(int v) {
			conduct_delete(v);
		}
		int Rank(int v) {
			return conduct_rank(v);
		}
		int Number(int k) {
			return conduct_number(k);
		}
		int Pre(int v) {
			conduct_insert(v);
			int ans = conduct_pre();
			conduct_delete(v);
			return tree[ans].val;
		}
		int Suc(int v) {
			conduct_insert(v);
			int ans = conduct_suc();
			conduct_delete(v);
			return tree[ans].val;
		}
};

map<string,SPLAY> splayrefer;
SPLAY aim_splay;

char command[65536];
string temp;
void command_deal() {
	int dot, left, right;
	for(int i = 0;command[i];++i) {
		if(command[i] == '.') {
			dot = i;
			for(int j = 0;j < dot;++j) 
				temp[j] = command[j];
			aim_splay = splayrefer[temp];
		}
	}
}

void work() {
	printf("welcome to bikuhiku's program!");
	while(1) {
		get_line(command);
	}
}
signed main() {
	work();
}

标签:le,return,cid,int,pid,ROOT,id
来源: https://www.cnblogs.com/bikuhiku/p/ee.html