zoukankan      html  css  js  c++  java
  • LuoguU72177 火星人plus (逆康拓展开)

    没开long long见祖宗。。。
    BIT先求逆序对来造表存展开关系,线段树维护01进制

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Abs(a) ((a) < 0 ? -(a) : (a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    
    //#define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    #define FileOpen() freopen("in.txt","r",stdin);
    
    #else
    
    #define D_e_Line ;
    #define D_e(x)  ;
    #define Pause() ;
    #define FileOpen() ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    
    const int N = 100007;
    #define int long long
    int n;
    
    namespace BIT{
    int t[N];
    int tmp[N];
    inline void Updata(int x, int w){
    	for(; x <= n; x += x&-x) t[x] += w;
    }
    inline int Query(int x){
    	int sum = 0;
    	for(; x; x -= x&-x) sum += t[x];
    	return sum;
    }
    inline void CreatContor(){
    	R(i,1,n){
    		int x;
    		io >> x;
    		Updata(x, 1);
    		tmp[i] = x - Query(x);
    //		D_e(tmp[i]);
    	}
    }
    }
    
    namespace SegTree{
    int t[N << 2];
    #define lson rt << 1, l, mid
    #define rson rt << 1 | 1, mid + 1, r
    inline void Pushup(int rt){
    	t[rt] = t[rt << 1] + t[rt << 1 | 1];
    }
    inline void Build(int rt, int l, int r){
    	if(l == r){
    		t[rt] = 1;
    		return;
    	}
    	int mid = (l + r) >> 1;
    	Build(lson), Build(rson);
    	Pushup(rt);
    }
    inline void Updata(int rt, int l, int r, int x){
    	if(l == r){
    		t[rt] = 0;
    		return;
    	}
    	int mid = (l + r) >> 1;
    	if(mid >= x)
    		Updata(lson, x);
    	else
    		Updata(rson, x);
    	Pushup(rt);
    }
    inline int Query(int rt, int l, int r, int w){
    	if(l == r) return l;
    	int mid = (l + r) >> 1;
    	if(t[rt << 1] >= w)
    		return Query(lson, w);
    	else
    		return Query(rson, w - t[rt << 1]);
    	
    }
    }
    #undef int
    int main(){
    #define int long long
    	FileOpen();
    		
    	int m;
    	io >> n >> m;
    	
    	BIT::CreatContor();
    	
    	//R(i,1,n) D_e(BIT::tmp[i]) ;
    	BIT::tmp[n] += m;
    	nR(i,n,1){
    		BIT::tmp[i - 1] += BIT::tmp[i] / (n - i + 1);
    		BIT::tmp[i] %= (n - i + 1);
    	//	D_e(BIT::tmp[i]);
    	}
    	
    	SegTree::Build(1, 1, n);
    	
    	R(i,1,n-1){
    		//D_e(BIT::tmp[i]);
    		int x = SegTree::Query(1, 1, n, BIT::tmp[i] + 1);
    		printf("%d ", x);
    		SegTree::Updata(1, 1, n, x);
    	}
    	printf("%d", SegTree::Query(1, 1, n, BIT::tmp[n] + 1));
    	
    	return 0;
    }
    

  • 相关阅读:
    CS231n assignment3 Q1 Image Captioning with Vanilla RNNs
    使用tensorflow预测函数的参数值(a simple task)
    CS231n assignment2 Q5 TensorFlow on CIFAR-10
    CS231n assignment2 Q4 Convolutional Networks
    HDU 1561 The more, The Better
    HDU4003 Find Metal Mineral
    poj 1947 Rebuilding Roads
    2090 背包
    poj 2408 Apple Tree
    奔跑的xiaodao
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11232269.html
Copyright © 2011-2022 走看看