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


C++ SegmentTree::init方法代码示例

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


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

示例1: main

int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  const double pi = 2 * acos(0.0);

  while (scanf("%d%d", &N, &C) != EOF) {
    REP(i, N) scanf("%d", L+i);
    REP(i, C) scanf("%d%d", S+i, A+i);

    double prv[10000];

    SegmentTree T;
    T.init(0,0,N);
    for (int i = 1; i < N; ++i) prv[i] = pi;

    REP(i, C) {
      int s = S[i];
      double a = (A[i] / 360.0) * 2 * pi;
      T.change(s, a-prv[s], 0, 0, N);
      prv[s] = a;
      printf("%.2f %.2f\n", T.vx[0], T.vy[0]);
    }
    puts("");
  }
开发者ID:daimatz,项目名称:contest,代码行数:25,代码来源:2991.cpp

示例2: main

int main(){
  //Treap::Node* test = Treap::nil;
  //Treap::insert(test, 1);
  //cout << Treap::getRank(test, 2) << endl;
  scanf("%d", &TestNum);
  while (TestNum--){
    scanf("%d", &n);
    int m; scanf("%d", &m);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    SegmentTree::Node root(0, n - 1); 
    tree.init(root);
    while (m--){
      char buf[32]; scanf("%s", buf);
      if (buf[0] == 'Q'){
        int i, j, k; scanf("%d %d %d", &i, &j, &k);
        printf("%d\n", getKth(i - 1, j - 1, k - 1));
      }else{
        int i, t; scanf("%d %d", &i, &t);
        tree.gao(i -1 , i - 1).update(root, a[i - 1], t);
        a[i - 1] = t;
      }
      //printf("new_cnt: %d\n", new_cnt);
    }
    tree.clear(root);
    //printf("new_cnt: %d\n", new_cnt);
    assert(new_cnt == 0);
    //len = 1;
  }
}
开发者ID:LiaoZhuo,项目名称:Practice,代码行数:29,代码来源:zoj2112_segmentTree_Treap_IntervalLabel.cpp

示例3: main

int main() {
	int x[] = {4, 2, 19, 24, 11, -1, 100, 32};
	int size = sizeof(x) / sizeof(x[0]);

	SegmentTree seg;
	seg.init(size);

	rep(i, size) {
		seg.update(i, x[i]);
	}
开发者ID:omuretsu,项目名称:Competition,代码行数:10,代码来源:SegmentTree.cpp

示例4: main

int main()
{
	node identity;
	identity.val = -1;
	SegmentTree<node> s;
	int n , k;
	scanf( "%d" , &n );
	vector<node> v( n );
	for ( int i = 0; i < n; ++i )
	{
		int x;
		scanf( "%d" , &x );
		v[ i ].val = x;
	}
	scanf( "%d" , &k );
	s.init( v , identity );
	for ( int i = 0; i <= n - k; ++i )
		printf( "%d " , s.rangeQuery( i , i + k-1 ).val );
	return 0;
}
开发者ID:ashrko619,项目名称:Spoj-Solutions,代码行数:20,代码来源:subarrays.cpp

示例5: countRangeSum

 int countRangeSum(vector<int>& nums, int lower, int upper) {
     if(nums.empty()) return 0;
     int n = (int)nums.size();
     vector<long> sums;
     set<long> values;
     long sum = 0L;
     for(int i = 0; i < (int)nums.size(); ++i) {
         sum += nums[i];
         values.insert(sum);
     }
     for(auto it = values.begin(); it != values.end(); ++it) {
         sums.push_back(*it);
     }
     
     int result = 0;
     SegmentTree segmentTree;
     segmentTree.init(sums);
     for(int i = n - 1; i >= 0; --i) {
         segmentTree.update(sum);
         sum -= nums[i];
         result += segmentTree.query(lower + sum, upper + sum);
     }
     return result;
 }
开发者ID:Kaidul,项目名称:LeetCode_problems_solution,代码行数:24,代码来源:Count_of_Range_Sum.cpp


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