My CodeStyle in OI
介绍下本蒟蒻的丑死的码风
在打CF时并不是这个码风
码风概述:
- 所有的
#include后必须有一个空格,例如#include <iostream> - 无论什么样子的程序,都必须写
cstdio cstring algorithm iostream这四个头文件。 - 在主程序的
int main()中要加void ,即为int main(void) - 一般不写
using namespace std; - 所有的变量必须定义在第一个自定义函数之前,且变量和第一个自定义函数,最后一个自定义函数和
main 之间必须有一个换行 - 每个函数之后尽可能有
return , - 在一般情况下,在花括号内的内容不加逗号
缩进:
对于每个代码块,使用4空格或者等长的Tab缩进。
括号:
大括号不换行
空格:
个人感觉自己的空格比较的
毒瘤。
1.在每个函数声明时,函数名后的括号与函数名之间必须有一个空格,而且括号内如果需要声明变量,则要先有一个空格,且逗号的前后都必须有一个空格。
2.在for循环的声明中,每一个字符(变量名除外),都要用空格隔开。
3.数组内一般不加空格,但是如果有运算符则运算符前后必须有空格。
4.每个可以前后匹配的括号前后必须有空格。
代码大概长这样...
struct wqwqwqwqwq {
int qwwq;
int qwq;
}wwq;
void qweqweqweq ( wqwqwqwq x , qwqwqwqwqwq y ) {
qweqweqweqweqweqweqweqwe;
if ( qweqweqweqweqwe ) {
qewqweqweqweqweq;
qweqweqweqweq;
}
else {
qweqweqweqweq;
qweqweqwrreeqwqqwe;
qweqewqweqweqewq;
}
return;
}
变量:
1.基本所有变量都是全局变量,但有些ans,sum最后统计答案时使用的变量可以定义为局部变量。
2.所有的变量名称都必须与要存储的东西的中文意思有沾边,比如树直接定义为tree而不是T。(极度不能容忍变量名直接为a,b,c,d,e,f,g,的情况。
3.定义N,M等时一般只用N,M为名称而不是MAXN,MAXM.
4.定义的结构体类型在定义变量时必须紧接着声明完成结构体后,并且结构体中变量需要定义一个加一个换行。
5.在变量命名时较长的变量名可以用_来连接,并且大小写交替使用,如
Add_Tree_Val
把上边所有毒瘤的码风结合起来之后代码大概长这个样子qwq..
update:还是加上模板舒服qwq
不要吐槽我的丑逼
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>
#include <vector>
#include <cstdlib>
#include <stack>
#define ll long long
#define pll std::pair<int,int>
#define mp std::make_pair
#define fi first
#define se second
#define oo 2147483647
#define PI 3.141592653590
#define rint register int
template < class T > inline void read ( T &x ) {T s = 0 , w = 1;char ch = getchar ();while ( ch > '9' || ch < '0' ) { if ( ch == '-' ) w = -1; ch = getchar ();}while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ();}x = s * w;return;}
template < class T , typename ...Argc > inline void read ( T &x , Argc &...Args ) {read ( x );read ( Args... );return;}
template < class T > inline T max ( T x , T y ) {return x > y ? x : y;}
template < class T > inline T min ( T x , T y ) {return x < y ? x : y;}
template < class T > inline void abs ( T x ) {return x > 0 ? x : -x;}
inline int _read () {int s = 0 , w = 1;char ch = getchar ();while ( ch > '9' || ch < '0' ) { if ( ch == '-' ) w = -1; ch = getchar ();}while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ();}return s * w;}
template <typename T> void write(T x) {if (x < 0) x = -x, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + 48);return;}
template <typename T> void writeln(T x) { write(x); printf ("\n"); }
/**********************************************************************************************************************************************************************************************************************************************************************/
const int N = 1e6 + 5;
int root , tot , n;
struct Tree {
int ch[2];
int val;
int father;
int size;
int cnt;
}tree[N];
void pushup ( int cur ) {
tree[cur].size = tree[tree[cur].ch[0]].size + tree[tree[cur].ch[1]].size + tree[cur].cnt;
return;
}
void rotate ( int x ) {
int y = tree[x].father;
int z = tree[y].father;
int k = tree[y].ch[1] == x;
tree[z].ch[tree[z].ch[1] == y] = x;
tree[x].father = z;
tree[y].ch[k] = tree[x].ch[k ^ 1];
tree[tree[x].ch[k ^1]].father = y;
tree[x].ch[k ^ 1] = y;
tree[y].father = x;
pushup ( x );
pushup ( y );
return;
}
void Splay ( int x , int goal ) {
while ( tree[x].father != goal ) {
int y = tree[x].father;
int z = tree[y].father;
if ( z != goal )
( tree[y].ch[0] == x ) ^ ( tree[z].ch[0] == y ) ? rotate ( x ) : rotate ( y );
rotate ( x );
}
if ( goal == 0 )
root = x;
return;
}
void insert ( int x ) {
int cur = root , father = 0;
while ( cur && tree[cur].val != x ) {
father = cur;
cur = tree[cur].ch[x > tree[cur].val];
}
if ( cur )
tree[cur].cnt++;
else {
cur = ++tot;
if ( father )
tree[father].ch[x > tree[father].val] = cur;
tree[cur].ch[0] = tree[cur].ch[1] = 0;
tree[cur].father = father;
tree[cur].val = x;
tree[cur].cnt = 1;
tree[cur].size = 1;
}
Splay ( cur , 0 );
return;
}
void Find ( int x ) {
int cur = root;
if ( !cur )
return;
while ( tree[cur].ch[x > tree[cur].val] && x != tree[cur].val )
cur = tree[cur].ch[ x > tree[cur].val];
Splay ( cur , 0 );
return;
}
int Next ( int x , int f ){
Find ( x );
int cur = root;
if ( tree[cur].val > x && f ) return cur;
if ( tree[cur].val < x && !f ) return cur;
cur = tree[cur].ch[f];
while ( tree[cur].ch[f ^ 1] )
cur = tree[cur].ch [f ^ 1];
return cur;
}
void Delete ( int x ) {
int last = Next ( x , 0 );
int next = Next ( x , 1 );
Splay ( last , 0 );
Splay ( next , last );
int del = tree[next].ch[0];
if ( tree[del].cnt > 1 ) {
tree[del].cnt--;
Splay ( del , 0 );
}
else
tree[next].ch[0] = 0;
return;
}
int kth ( int x ) {
int cur = root;
if ( tree[cur].size < x )
return 0;
while ( 1 ) {
int y = tree[cur].ch[0];
if ( x > tree[y].size + tree[cur].cnt ) {
x -= tree[y].size + tree[cur].cnt;
cur = tree[cur].ch[1];
}
else
if ( tree[y].size >= x )
cur = y;
else
return tree[cur].val;
}
}
int main ( void ) {
n = read ();
insert ( 2147483647 );
insert ( -2147483647 );
while ( n-- ) {
int opt = read ();
if ( opt == 1 ) {
int x = read ();
insert ( x );
}
else if ( opt == 2 ) {
int x = read ();
Delete ( x );
}
else if ( opt == 3 ) {
int x = read ();
Find ( x );
printf ( "%d\n" , tree[tree[root].ch[0]].size );
}
else if ( opt == 4 ) {
int x = read ();
printf ( "%d\n" , kth ( x + 1 ) );
}
else if ( opt == 5 ) {
int x = read ();
printf ( "%d\n" , tree[Next ( x , 0 )].val );
}
else if ( opt == 6 ) {
int x = read ();
printf ( "%d\n" , tree[Next ( x , 1 )].val );
}
}
return 0;
}