示例#1
0
int main()
{
	#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	#endif
	
	int T;
	scanf("%d", &T);
	for(int ck=1; ck<=T; ck++)
	{
		scanf("%d", &N);
		
		scanf("%*s%*s");
		scanf("%d", &Q);
		tree.build(1,1,N);
		for(int i=1; i<=Q; i++)
		{
			int opt,a,b;
			scanf("%d%d%d", &opt, &a, &b);
			if(opt)
			{
				printf("%d\n", tree.query(1,a,b));
			}
			else
			{
				tree.update(1,a,a,b);
			}
		}
		
		scanf("%*s%*s");
		scanf("%d", &Q);
		tree.build(1,1,N);
		for(int i=1; i<=Q; i++)
		{
			int opt,a,b,c;
			scanf("%d", &opt);
			if(opt)
			{
				scanf("%d", &a);
				printf("%d\n", tree.query(1,a,a));
			}
			else
			{
				scanf("%d%d%d", &a, &b, &c);
				tree.update(1,a,b,c);
			}
		}
	}
	return 0;
}
示例#2
0
int main()
{
	#ifdef LOCAL
//	freopen("1008.in", "r", stdin);
//	freopen("out.txt", "w", stdout);
	#endif
	
	int T;
	scanf("%d", &T);
	for(int ck=1; ck<=T; ck++)
	{
		scanf("%d%d", &N, &M);
		for(int i=1; i<=N; i++) scanf("%d", &A[i]);
		tree.len=N;
		tree.build();
		for(int i=1,opt,l,r,x; i<=M; i++)
		{
			scanf("%d%d%d", &opt, &l, &r);
			if(opt==1) {scanf("%d", &x); tree.add(l,r,x);}
			if(opt==2) {tree.rsqrt(l,r);}
			if(opt==3) {printf("%lld\n", tree.sum(l,r));}
//			PCUT;
		}
	}
	return 0;
}
	void init(Graph *g)
	{
		G=g;
		dfst=0;
		CLR(dfsn); CLR(dept); CLR(size); CLR(bson); CLR(fath); CLR(ntop);
		CLR(pval); CLR(sque);
		dfs1(1);
		dfs2(1,1);
		tree.build(1,1,G->ndn,sque);
	}
示例#4
0
 /**
  *@param A, queries: Given an integer array and an query list
  *@return: The result list
  */
 vector<int> intervalMinNumber(vector<int> &A, vector<Interval> &queries) {
     // write your code here
     vector<int> r;
     SegmentTree st;
     Node* root = st.build(A, 0, A.size()-1);
     for(int i=0;i<queries.size();i++) {
         Interval tmp = queries[i];
         r.push_back(st.query(root, tmp.start, tmp.end));
     }
     return r;
 }
示例#5
0
int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d %d %I64d", &rings[i].a, &rings[i].b, &rings[i].h);
  }
  sort(rings, rings + n);
  n = merge();
  tree.build(1, 0, n - 1);
  for(int i = 0; i < n; i++) {
    int update_idx = lower_bound(ranks.begin(), ranks.end(), rings[i].a) - ranks.begin();
    int idx = lower_bound(ranks.begin(), ranks.end(), rings[i].b) - ranks.begin();
    long long val = rings[i].h;
    if(idx) {
      val += tree.query(1, 0, idx - 1);
    }
    tree.update(1, update_idx, val);
  }
  printf("%I64d\n", tree.query(1, 0, n - 1));
  return 0;
}
示例#6
0
int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d %d", &v[i].r, &v[i].h);
    ranks[i] = i;
  }
  sort(ranks, ranks+n, cmp);
  for(int i = 0; i < n; i++)
    v[ranks[i]].i = i;
  SegmentTree tree;
  tree.build(1, 0, n-1);
  long long ans = 0;
  for(int i = 0; i < n ; i++) {
    int r = v[i].i;
    long long now = tree.query(1, 0, r) + v[i].r * 1LL * v[i].r * v[i].h;
    ans = max(ans, now);
    tree.update(1, r, now);
  }
  printf("%.9lf\n", pi * ans);
  return 0;
}
示例#7
0
文件: H.cpp 项目: hphp/Algorithm
int main()
{
    int test;
    scanf("%d",&test);
    while(test--)
    {
        scanf("%d",&n);
        int cnt = 0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&h[i]);
            rec[cnt++] = h[i];
        }
        std::sort(rec,rec+cnt);
        rcnt = 1;
        for(int i=0; i<cnt; i++)
            if(i == 0 || rec[i]!=rec[i-1])
            {
                real[rcnt++] = rec[i];
            }
        for(int i=0; i<n; i++)
            conh[i] = find(h[i]);
        SegmentTree sgt = SegmentTree();
        sgt.build(1,0,n);
        for(int i=0; i<n; i++)
        {
            int cur = sgt.query(1,conh[i]+1,n,1);
            if(cur >= 0)
                sgt.insert(1,conh[i],conh[i],0,cur+1);
//			printf("to be low %d ",cur);
            cur = sgt.query(1,0,conh[i]-1,0);
            if(cur >= 0)
                sgt.insert(1,conh[i],conh[i],1,cur+1);
            //		printf("to be high %d\n",cur);
        }
        int ans = Max(sgt.query(1,0,n,0),sgt.query(1,0,n,1));
        printf("%d\n",ans);
    }
    return 0;
}
示例#8
0
int main()
{
	#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	#endif
	
	int T;
	scanf("%d", &T);
	for(int ck=1; ck<=T; ck++)
	{
		scanf("%d%d", &N, &M);
		
		G.init(N);
		for(int i=1; i<N; i++)
		{
			int u,v;
			scanf("%d%d", &u, &v);
			G.adde(u,v); G.adde(v,u);
		}
		hld.init(&G);
		tree.build(1,1,N);
		CLR(sum); CLR(dp);
		
		
		for(int i=1; i<=N; i++) chain[i].clear();
		for(int i=0; i<M; i++)
		{
			int x,y,w;
			scanf("%d%d%d", &x, &y, &w);
			chain[ hld.LCA(x,y) ].push_back(data(x, y, w));
		}
		
		DP(1,0);
		printf("%d\n", dp[1]);
	}
	return 0;
}
示例#9
0
int main()
{
	#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	#endif
	
	while(~scanf("%s", str+1))
	{
		N = strlen(str+1);
		tree.build(1,1,N);
		scanf("%d", &Q);
		for(int i=0; i<Q; i++) scanf("%d%d", &qry[i].l, &qry[i].r), qry[i].id=i;
		CLR(near[0]);
		for(int i=1; i<=N; i++)
		{
			for(int j=0; j<4; j++) near[i][j] = near[i-1][j];
			for(int j=0; j<4; j++) if(str[i] == chr[j]) {near[i][j] = i; break;}
		}
		sort(qry, qry+Q);
		int np=0;
		for(int q=0; q<Q; q++)
		{
			printf("%d %d\n", qry[q].l, qry[q].r);
			while(np<qry[q].r) expend(++np);
			int res = tree.query(1,qry[q].l,qry[q].r);
			printf("res: %d test:%d\n", res, tree.query(1,1,N));
			int temp;
			int lm = startE(temp=tree.leftmost(1,qry[q].l,qry[q].r)); // bug
			printf("lm: %d lef: %d\n", lm, temp);
			if(lm<qry[q].l && res) res--;
			ans[qry[q].id] = res;
		}
		for(int q=0; q<Q; q++) printf("%d\n", ans[q]);
	}
	return 0;
}
示例#10
0
文件: Walls.cpp 项目: XingMo/ACM_Code
void Scan(int flr)
{
	tree.build(1,0,ais[flr].siz);
	for(int i=0; i<isiz[flr]; i++)
	{
//		if(debug)
//		{
//			Object &now=inpt[flr][i];
//			puts((inpt[flr][i].flag==WALL)?"wall":"bird");
//			printf("%d: %d %d %d\n", now.id, now.u, now.v, now.h);
//		}
		if(inpt[flr][i].flag == WALL)
		{
			tree.update(1, ais[flr].id(inpt[flr][i].u), ais[flr].id(inpt[flr][i].v), inpt[flr][i].id, inpt[flr][i].h);
		}
		else
		{
//			if(debug) 
//			{
//				printf("%d\n", ais[flr].siz);
//				for(int i=0; i<ais[flr].siz; i++) printf("%d ", tree.query(1,i).first);puts("");
//				for(int i=0; i<ais[flr].siz; i++) printf("%d ", tree.query(1,i).second);puts("");
//			}
			Pii info=tree.query(1, ais[flr].id(inpt[flr][i].u));
			if(info.first==-1) continue;
//			if(debug) printf("wid=%d\n", info.first);
			int res, id;
			id=inpt[flr][i].id;
			res=abs(inpt[flr][i].h - info.second);
			if(res < bird[0][id])
			{
				bird[0][id] = res;
				bird[1][id] = info.first;
			}
		}
	}
}