【转载】常用外挂

转自http://blog.csdn.net/mxymxy1994mxy/article/details/47679971

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
using namespace std;

//C++扩栈
#pragma comment(linker, "/STACK:1024000000,1024000000")

//读入挂
inline char getc(){  
	static const int BUFLEN = 1 << 15;  
	static char B[BUFLEN], *S = B, *T = B;  
	if(S == T){  
		S = B;  
		T = S + fread(B, 1, BUFLEN, stdin);  
	}  
	return (S == T) ? 0 : *(S ++);  
}  
int ReadInt(){  
	char ch;  
	do ch = getc(); while(!isdigit(ch));  
	int aa = ch - '0';  
	for(ch = getc(); isdigit(ch); ch = getc())  
		aa = aa * 10 + ch - '0';  
	return aa;  
}

//O(N)排序+离散化
void Distinct(unsigned int arr[], const int N){
	int i, n2;
	static int cnt[0x10000], tab1[MAXN], tab2[MAXN];
	static unsigned int arr2[MAXN];

	//第一轮
	for(i = 0; i <= 0xFFFF; i ++) cnt[i] = 0;
	for(i = 0; i < N; i ++) cnt[arr[i]&0xFFFF] ++;
	for(i = 0; i < 0xFFFF; i ++) cnt[i + 1] += cnt[i];
	for(i = N - 1; i >= 0; i --){
		tab1[i] = -- cnt[arr[i]&0xFFFF];
		arr2[tab1[i]] = arr[i];
	}
	//第二轮
	for(i = 0; i <= 0xFFFF; i ++) cnt[i] = 0;
	for(i = 0; i < N; i ++) cnt[arr2[i]>>16] ++;
	for(i = 0; i < 0xFFFF; i ++) cnt[i + 1] += cnt[i];
	for(i = N - 1; i >= 0; i --){
		tab2[i] = -- cnt[arr2[i]>>16];
		arr[tab2[i]] = arr2[i];
	}
	//值离散化
	arr2[0] = n2 = 1;
	for(i = 1; i < N; i ++){
		if(arr[i] != arr[i - 1]) ++ n2;
		arr2[i] = n2;
	}
	//复原数组
	for(i = 0; i < N; i ++) arr[i] = arr2[tab2[tab1[i]]];
}

//大数乘法取模
//如果是64位要写imulq,idivq和r?x
#define MO 1000000007
#ifdef _MSC_VER
inline int ml(int a,int b){
    int ret;
    _asm{
        mov eax, a;
        mov ebx, b;
        mov ecx, MO;
        imul ebx;
        idiv ecx;
        mov ret, edx;
    }
    return ret;
}
#else
inline int ml(int a,int b){
    int ret;
    __asm__ __volatile__ ("\timull %%ebx\n\tidivl %%ecx\n" :"=d"(ret):"a"(a),"b"(b),"c"(MO));
    return ret;
}
#endif

  

posted @ 2015-08-17 19:26  Painting、时光  阅读(147)  评论(0编辑  收藏  举报