| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
想问个问题。。。。为什么程序的/* 1 */,/* 2 */里 把x+1改成x会TLE???#include <iostream>
using namespace std;
const int N = 32100;
int c[N];//树状数组
int lowBit(int x) {
return x & (x ^ (x - 1));
}
void add(int x, int k) {
//a[x] += k
while (x <= N) {
c[x] += k;
x += lowBit(x);
}
}
void sub(int x, int k) {
//a[x] -= k
while (x <= N) {
c[x] -= k;
x += lowBit(x);
}
}
int sum(int x) {
//return sum(1..x);
int ret = 0;
while (x > 0) {
ret += c[x];
x -= lowBit(x);
}
return ret;
}
int out[N]; //记录各个level的星星个数
int main() {
//pku2352
int i, j, k, x, y;
int n;
scanf("%d", &n);
for (i=0; i<n; i++) {
scanf("%d%d", &x, &y);
out[sum(x+1)]++; //树状数组下标从1开始 /* 1 */
add(x+1,1);//比x大的点全部都要+1 /* 2 */
}
for (i=0; i<n; i++) {
printf("%d\n", out[i]);
}
system("pause");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator