Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

想问个问题。。。。为什么程序的/* 1 */,/* 2 */里 把x+1改成x会TLE???

Posted by lgq1205 at 2009-08-23 00:22:52 on Problem 2352 and last updated at 2009-08-23 00:23:08
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator