标签:for str bit update size amp val type while
3 1 1 2 2 3 3 3 1 1 1 2 1 3 0Sample Output
1 1 1 3 2 1
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include <stdio.h> #include <string.h> #define rep(i , n) for(int i = 0 ; i < (n) ; i++) using namespace std; typedef unsigned long long ull; int fa[100009] ; long long ans = 0 ; int a[100009] , sum[10009]; int c[100009] ; int n ; int lowerbit(int x) { return x & (-x); } void update(int x , int value) { for(int i = x ; i <= n ; i += lowerbit(i)) { c[i] += value ; } } int getsum(int x) { int ans = 0 ; for(int i = x ; i > 0 ; i -= lowerbit(i)) { ans += c[i]; } return ans ; } int main() { while(~scanf("%d" , &n) && n) { memset(c , 0 , sizeof(c)); for(int i = 0 ; i < n ; i++) { int l , r ; scanf("%d%d" , &l , &r); update(l , 1); update(r+1 , -1); } for(int i = 1 ; i <= n ; i++) { if(i == 1) cout << getsum(i) ; else cout <<" " << getsum(i) ; } cout << endl ; } return 0 ; }
标签:for str bit update size amp val type while
原文地址:https://www.cnblogs.com/nonames/p/11274503.html