当前位置: 首页>>代码示例>>C++>>正文


C++ BIT类代码示例

本文整理汇总了C++中BIT的典型用法代码示例。如果您正苦于以下问题:C++ BIT类的具体用法?C++ BIT怎么用?C++ BIT使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BIT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: solve

void solve()
{
    ll ans = 0;
    BIT b;
    for (int j = 0; j < n; j++) {
	ans += j - b.sum(b.a[j]);
    }
}
开发者ID:motxx,项目名称:cpro-mochinocha-library,代码行数:8,代码来源:the_num_of_bub.cpp

示例2: main

int main()
{
    ios::sync_with_stdio(false);
    int n = 10;
    int i, x;
    BIT T;
    while(cin >> i >> x){
        T.increment(i,x);
        FOR1(j,n) cout << T.read(j) << ' '; cout << endl;
    }
    
    return 0;
}
开发者ID:bloops,项目名称:Algorithms-and-Data-Structures,代码行数:13,代码来源:bit.cpp

示例3: main

int main(void){
    int T;
    scanf("%d", &T);
    while(T--) {
        scanf("%d", &n);
        int maxa = 0;
        for(int i = 1; i <= n; i++) {
            scanf("%d", a+i);
            maxa = maxa > a[i] ? maxa: a[i];
        }

        BIT t;
        t.resize(maxa);
        t.clear();
        for(int i = 1; i <= n; i++) {
            t.add(a[i], 1);
            c[i] = t.sum(a[i] - 1);
        }
        t.clear();
        for(int i = n; i > 0; i--) {
            t.add(a[i], 1);
            d[i] = t.sum(a[i] - 1);
        }

        long long ans = 0;
        for(int i = 1; i <= n; i++) {
            ans += (long long)c[i]*(n-i-d[i]) + (long long)(i-c[i]-1)*d[i];
        }
        printf("%lld\n", ans);
    }
    return 0;
}
开发者ID:jiang42,项目名称:AlgoContest,代码行数:32,代码来源:uva1428.cpp

示例4: solve

void solve(){
    if(!len){
        puts("Poor stack!");
        return;
    }
    b = BIT(ns);
    rep(i,ns) b.add(i,1);
    rep(i,ms){
        for(int j = k[i]-1; j >= 0; --j){
            int pos = b.find(a[j]);
            b.add(pos,-1);
        }
    }
    rep(i,ns) if(b.sum(i,i+1)) printf("%d", seq[i]);
    puts("");
}
开发者ID:hadrori,项目名称:hadrori.github.io,代码行数:16,代码来源:374D.cpp

示例5: main

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); 
	//freopen("d.in", "r", stdin);

	cin >> T;	
	while (T--){
		cin >> N;
		for (int i = 1 ; i <= N ; i++){
			cin >> A[i];
			B[i] = A[i];
		}
		
		sort(B + 1, B + N + 1);

		for (int i = 1 ; i <= N ; i++)
			ID[i] = lower_bound(B + 1, B + N + 1, A[i]) - B;

		S[N + 1] = 0;
		for (int i = N ; i >= 1 ; i--){
			S[i] = 1;
			if (ID[i] < ID[i + 1])
				S[i] += S[i + 1];
		}

		int sol = 0;
		BIT bit;

		for (int i = 1 ; i <= N ; i++){
			D[i] = 1;
			if (ID[i] > ID[i - 1])
				D[i] += D[i - 1];

			bit.update(ID[i], D[i]);

			int s = S[i] + bit.query(ID[i] - 1);

			if (sol < s)
				sol = s;
		}

		cout << sol << '\n';
	}

	return 0;
}
开发者ID:frarteaga,项目名称:cojSolutions,代码行数:45,代码来源:2074.frankr.cpp

示例6: CDQ

void CDQ(int nl, int nr)
{
	if(nl>=nr) return;
	int mid=(nl+nr)>>1;
	CDQ(nl, mid); CDQ(mid+1,nr);
	
	int tl=mid;
	for(int tr=nr; tr>mid; tr--)
	{
		while(tl>=nl && arry[tl].l >= arry[tr].l)
		{
			bit.add( arry[tl].r, arry[tl].v);
			tl--;
		}
		ans[ arry[tr].t ] += bit.sum( arry[tr].r );
	}
	for(int i=mid; i>tl; i--) bit.add( arry[i].r, -arry[i].v);
	
	tl=nl;
	int tp=nl;
	for(int tr=mid+1; tr<=nr; tr++)
	{
		while(tl<=mid && arry[tl].l < arry[tr].l) temp[tp++] = arry[tl++];
		temp[tp++] = arry[tr];
	}
	while(tl<=mid) temp[tp++] = arry[tl++];
	
	for(int i=nl; i<=nr; i++) arry[i]=temp[i];
}
开发者ID:XingMo,项目名称:ACM_Code,代码行数:29,代码来源:覆盖次数.cpp

示例7: Work

inline void Work(void) { 
    T.clear(); T.Add(b[1], 1); 
    int j = 0; last = 1; 
    for (int i = 2; i <= m; i++) { 
        while (j && Ask(b, i - j, b[i]) != rank[j + 1])  
            j = p[j]; 
        if (j == 0) Ask(b, i - j, b[i]);
        if (Ask(b, i - j, b[i]) == rank[j + 1]) j++; 
        p[i] = j; 
        T.Add(b[i], 1); 
    }
    T.clear(); 
    j = 0; last = 1; 
    for (int i = 1; i <= n; i++) { 
        while (j && Ask(a, i - j, a[i]) != rank[j + 1])
            j = p[j]; 
        if (j == 0) Ask(a, i - j, a[i]);
        if (Ask(a, i - j, a[i]) == rank[j + 1]) j++; 
        if (j == m) { 
            Ans[i] = true;
            j = p[j]; 
        } 
        T.Add(a[i], 1); 
    }
    f[0] = 0;
    for (int i = 1; i <= n; i++) {
//        printf("%d ", Ans[i]);
        f[i] = f[i - 1];
        if (Ans[i] > 0) f[i] = max(f[i], f[i - m] + 1);
    }
//    puts("");
    printf("%d\n", f[n]);
} 
开发者ID:ACM-Obsidian,项目名称:Obsidian,代码行数:33,代码来源:1002.cpp

示例8: Prepare

inline void Prepare(void) { 
    T.clear(); T.n = MAXH; 
    for (int i = 1; i <= m; i++) { 
        rank[i] = make_pair(T.Cal(b[i] - 1) + 1, T.Cal(b[i]));
        T.Add(b[i], 1); 
    }
}
开发者ID:ACM-Obsidian,项目名称:Obsidian,代码行数:7,代码来源:1002.cpp

示例9: add

 void add(int x, int c) {
   assert(!col[c].count(x));
   int a = prv(x, c);
   int b = nxt(x, c);
   if (a != -1) {
     bit.del(a, b);
     bit.add(a, x);
   }
   bit.add(x, b);
   col[c].insert(x);
 }
开发者ID:CoderINusE,项目名称:bcw_codebook,代码行数:11,代码来源:pC.cpp

示例10: del

 void del(int x, int c) {
   assert(col[c].count(x));
   int a = prv(x, c);
   int b = nxt(x, c);
   bit.del(x, b);
   if (a != -1) {
     bit.del(a, x);
     bit.add(a, b);
   }
   col[c].erase(x);
 }
开发者ID:CoderINusE,项目名称:bcw_codebook,代码行数:11,代码来源:pC.cpp

示例11: update

void HLD::update(int x, int y)
{
	while(ntop[x] != ntop[y])
	{
		if( dept[ ntop[x] ] > dept[ ntop[y] ] ) swap(x,y);
		bit.update( dfsn[ ntop[y] ], dfsn[ y ], 1);
		y = fath[ ntop[y] ];
	}
	if( dept[x] > dept[y] ) swap(x,y);
	x = bson[x];
	bit.update( dfsn[x], dfsn[y], 1);
}
开发者ID:XingMo,项目名称:ACM_Code,代码行数:12,代码来源:Minimum_Cut.cpp

示例12: kth_smallest

long long kth_smallest(long long k){
  long long lo = 0, hi = tree.size()-1;
  long long mid = -1;
  while(lo < hi){
    mid = (lo + hi)/2;
    if(k <= tree.get_sum(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  //cerr << "sum up to " << lo << " is " << tree.get_sum(lo) << endl;
  if(tree.get_sum(lo) < k) return -1;
  return lo;
}
开发者ID:laveesingh,项目名称:Competitive-Programming,代码行数:14,代码来源:main.cpp

示例13: main

int main () {
	int n, x, y;

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d %d", &x, &y);
		freq[tree.cnt(x+1)]++;
		tree.inc(x+1);
	}

	for (int i = 0; i < n; i++) {
		printf("%d\n", freq[i]);
	}
}
开发者ID:victorsenam,项目名称:treinos,代码行数:15,代码来源:1028.cpp

示例14: main

int main() {
	int C = 0, T, q, x, y;
	scanf("%d", &T);
	while (++C <= T) {
		bit.init();
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) {
			scanf("%d", &x);
			bit.modify(i, x);
		}
		scanf("%d", &q);
		while (q--) {
			scanf("%d %d", &x, &y);
			printf("%d\n", bit.query(x, y));
		}
	}
}
开发者ID:syw111111,项目名称:ACM,代码行数:17,代码来源:5443+-+The+Water+Problem.cpp

示例15: main

int main() {
	ios_base::sync_with_stdio(false);

	int n, m, k;
	int x, y;

	cin >> n >> m >> k;	

	op.init(m+10);
	a.init(n+10);

	for (int i=1; i<=n; ++i) {
		cin >> x;
		a.add_interval(i, i, x);
	}
	for (int i=1; i<=m; ++i) cin >> l[i] >> r[i] >> d[i];
	for (int i=0; i<k; ++i) {
		cin >> x >> y;	
		op.add_interval(x, y, 1);
	}
	for (int i=1; i<=m; ++i) a.add_interval(l[i], r[i], op.sum(i)*d[i]);
	for (int i=1; i<=n; ++i) cout << a.sum(i) << (i < n ? " " : "\n");

	return 0;
}
开发者ID:delta4d,项目名称:AlgoSolution,代码行数:25,代码来源:C.cpp


注:本文中的BIT类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。