예제 #1
0
파일: main.cpp 프로젝트: sqc1999/HDU
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	while (cin >> n >> m)
	{
		for (int i = 1; i <= n; i++)
		{
			int x;
			cin >> x;
			T.Update(i, x);
		}
		for (int i = 1; i <= m; i++)
		{
			char ch;
			int a, b;
			cin >> ch >> a >> b;
			if (ch == 'Q') cout << T.Query(a, b) << endl;
			else if (ch == 'U') T.Update(a, b);
		}
	}
}
예제 #2
0
파일: F.cpp 프로젝트: lyoz/contest
	#endif

	for(int n;cin>>n&&n;){
		vi b(n);
		rep(i,n) cin>>b[i];
		vector<tuple<int,int,int>> qs;
		rep(i,n) qs.emplace_back(i,i+1,0);
		int q; cin>>q;
		rep(i,q){
			int l,r; cin>>l>>r; l--;
			qs.emplace_back(l,r,1);
		}

		sort(all(qs),[](auto x,auto y){
			return mt(get<1>(x),get<2>(x))<mt(get<1>(y),get<2>(y));
		});

		SegmentTree st(n+1);
		st.Update(0,1,count(all(b),0));
		rep(i,qs.size()){
			int l,r,t; tie(l,r,t)=qs[i];
			int x=st.Query(l);
			if(t==0)
				st.Update(r,r+1,x+(b[l]==0?-1:1));
			else
				st.Update(l+1,r+1,x);
		}
		cout<<st.Query(n)<<endl;
	}
}