标签:down 维护 int can bsp pre 线段 acm blank
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 25511 Accepted Submission(s): 12393
线段树区间维护(水水水)
#include <stdio.h> #include <algorithm> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <utility> #include <vector> #define mem(arr, num) memset(arr, 0, sizeof(arr)) #define _for(i, a, b) for (int i = a; i <= b; i++) #define __for(i, a, b) for (int i = a; i >= b; i--) #define IO \ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f; const double EPS = 1e-10; const ll mod = 1000000007LL; const int N = 1 << 19; int dat[N],n; void update(int a,int b,int k,int l,int r) { if(a<=l && b >= r) { dat[k]++; } else if(a <= r && b >=l) { update(a,b,k<<1,l,(l+r)/2); update(a,b,k<<1|1,(l+r)/2+1,r); } } void down(int l,int r,int k) { if(l==r) { l==n?printf("%d\n",dat[k]):printf("%d ",dat[k]); } else { dat[k<<1] += dat[k]; dat[k<<1|1] += dat[k]; down(l,(l+r)/2,k<<1); down((l+r)/2+1,r,k<<1|1); } } int main() { int a,b; while(scanf("%d",&n),n) { mem(dat,0); _for(i,1,n) { scanf("%d%d",&a,&b); update(a,b,1,1,n); } down(1,n,1); } return 0; }
hdu 1556 Color the ball(线段树区间维护+单点求值)
标签:down 维护 int can bsp pre 线段 acm blank
原文地址:https://www.cnblogs.com/GHzz/p/8921727.html