标签:des style class blog c code
Time Limit: 2000/1000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 117 Accepted
Submission(s): 25
我的做法就是在修改的时候,暴力修改和这个点相关的。
找出景点会影响哪些休息区,然后修改的时候暴力,查询的时候树状数组求前n项和
1 /* *********************************************** 2 Author :kuangbin 3 Created Time :2014/5/25 14:22:19 4 File Name :E:\2014ACM\比赛\百度之星初赛2\A.cpp 5 ************************************************ */ 6 7 #include <stdio.h> 8 #include <string.h> 9 #include <iostream> 10 #include <algorithm> 11 #include <vector> 12 #include <queue> 13 #include <set> 14 #include <map> 15 #include <string> 16 #include <math.h> 17 #include <stdlib.h> 18 #include <time.h> 19 using namespace std; 20 21 const int MAXN = 100010; 22 long long c[MAXN]; 23 int lowbit(int x) 24 { 25 return x&(-x); 26 } 27 long long sum(int i) 28 { 29 long long ret = 0; 30 while(i > 0) 31 { 32 ret += c[i]; 33 i -= lowbit(i); 34 } 35 return ret; 36 } 37 void add(int i,long long val) 38 { 39 while(i <= 100000) 40 { 41 c[i] += val; 42 i += lowbit(i); 43 } 44 } 45 46 int s1[MAXN]; 47 int s2[MAXN]; 48 int sz1,sz2; 49 50 vector<int>vec1[10010]; 51 vector<int>vec2[10010]; 52 int a[10010]; 53 int b[10010]; 54 55 void calc(int u) 56 { 57 int id = lower_bound(s1,s1+sz1,s2[u]) - s1; 58 if(id == 0) 59 { 60 vec1[0].push_back(u); 61 vec2[u].push_back(0); 62 } 63 else if(id == sz1) 64 { 65 vec1[sz1-1].push_back(u); 66 vec2[u].push_back(sz1-1); 67 } 68 else 69 { 70 if(s2[u] - s1[id-1] < s1[id] - s2[u] ) 71 { 72 vec1[id-1].push_back(u); 73 vec2[u].push_back(id-1); 74 } 75 else if(s2[u] - s1[id-1] > s1[id] - s2[u]) 76 { 77 vec1[id].push_back(u); 78 vec2[u].push_back(id); 79 } 80 else 81 { 82 vec1[id-1].push_back(u); 83 vec2[u].push_back(id-1); 84 vec1[id].push_back(u); 85 vec2[u].push_back(id); 86 } 87 } 88 } 89 int get(int u) 90 { 91 if(vec2[u].size() == 1) 92 { 93 return a[vec2[u][0]]; 94 } 95 else 96 { 97 return max(a[vec2[u][0]],a[vec2[u][1]]); 98 } 99 } 100 101 int link[10010]; 102 103 int main() 104 { 105 //freopen("in.txt","r",stdin); 106 //freopen("out.txt","w",stdout); 107 int T; 108 int iCase = 0; 109 int n; 110 scanf("%d",&T); 111 while(T--) 112 { 113 iCase++; 114 printf("Case #%d:\n",iCase); 115 sz1 = 0;sz2 = 0; 116 memset(c,0,sizeof(c)); 117 int u,v; 118 scanf("%d",&n); 119 for(int i = 0;i < n;i++) 120 { 121 scanf("%d%d",&u,&v); 122 if(v == 0) 123 s2[sz2++] = u; 124 else 125 { 126 s1[sz1++] = u; 127 link[i] = sz1-1; 128 add(v,1); 129 a[sz1-1] = v; 130 } 131 vec1[i].clear(); 132 vec2[i].clear(); 133 } 134 for(int i = 0;i < sz2;i++) 135 calc(i); 136 for(int i = 0;i < sz2;i++) 137 { 138 b[i] = get(i); 139 add(b[i],1); 140 } 141 char op[10]; 142 int m; 143 scanf("%d",&m); 144 while(m--) 145 { 146 scanf("%s",op); 147 if(op[0] == ‘Q‘) 148 { 149 scanf("%d",&u); 150 printf("%d\n",(int)sum(u)); 151 } 152 else 153 { 154 scanf("%d%d",&u,&v); 155 u = link[u]; 156 add(a[u],-1); 157 a[u] = v; 158 add(a[u],1); 159 for(int i = 0;i < vec1[u].size();i++) 160 { 161 int p = get(vec1[u][i]); 162 add(b[vec1[u][i]],-1); 163 b[vec1[u][i]] = p; 164 add(p,1); 165 } 166 } 167 } 168 } 169 return 0; 170 }
HDU 4831 Scenic Popularity,布布扣,bubuko.com
标签:des style class blog c code
原文地址:http://www.cnblogs.com/kuangbin/p/3751403.html