toj 3140
2011-09-08 21:04
225 查看
这个题简单模拟也能过,还是0ms!!
//修改段,问点 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <fstream> #define N 504 using namespace std; int tree ,n; int lowbit(int k) { return k&(-k); } void Modify(int num,int v) { while (num <= n) { tree[num] += v; num += lowbit(num); } } int sum(int num) { int ans = 0; while (num > 0) { ans += tree[num]; num -= lowbit(num); } return ans; } int main() { int m,k,i,j,p,e,s; while (scanf("%d%d",&n,&m)!=EOF) { memset(tree,0,sizeof(tree)); while (m--) { scanf("%d%d%d",&p,&s,&e); if(p) { k = 0; for(i = s;i <= e;i++) { k += sum(i)&1; } printf("%d\n",k); } else { Modify(s,1); Modify(e+1,-1); } } } return 0; }
相关文章推荐
- TOJ 2199 A+B Problem的无奈 2006-07-21
- toj 1705 Scavenger Hunt
- TOJ 3348 Scales
- 【TOJ】1416. Catenyms --欧拉路
- [TOJ] 3243 Blocked Road -- 树状数组、线段树
- TOJ 2273 POJ 2818 Making Change DFS C语言
- TOJ-1153 将字符串中的每个单词中的字符逆转
- poj 3140 树型DP
- 3989. I guess the gift is a calculator! toj
- (TOJ 4413)IP address
- TOJ 1132 ZOJ 1090 The Circumference of the Circle
- toj1987 Faulty Odometer
- TOJ 2641 Gene
- toj 3019 Hidden Password (最小表示法)
- TOJ 2909 ZOJ 3175 Number of Containers / 数论
- HOJ 3140 乌龟棋
- TOJ 2814
- TOJ-3499. Network
- TOJ 1283 A DP Problem 字符串处理,搜索
- 归并排序求 逆序对数 TOJ 1455 Ultra-QuickSort