Exemple #1
0
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("");
  }
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;
  }
}
Exemple #3
0
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]);
	}
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;
}
 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;
 }