codevs 1292 核仁巧克力

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codevs 1292 核仁巧克力相关的知识,希望对你有一定的参考价值。

我犯了跟上次一样地错误,又以为要可持久化了。。好在马上反应了过来

同样的扫描线线段树没啥意思

还有记着最大值变化后那个记录Ollie的数组要重新初始化。。。

只是数据有个点是个track

只有一列,答案都是0;我就挂了一次,特判掉就好

  1 #include<iostream>
  2 #include<cstdio>
  3 #include<algorithm>
  4 #include<vector>
  5 #include<ext/pb_ds/assoc_container.hpp>
  6 #define maxn 200020
  7 using namespace std;
  8 using namespace __gnu_pbds;
  9 gp_hash_table<int,int> ha;
 10 struct data{
 11     int x,y;
 12 }v[maxn];
 13 bool cmp(data a,data b){
 14     return a.x < b.x;
 15 }
 16 bool cmp2(data a,data b){
 17     return a.y < b.y;
 18 }
 19 struct node{
 20     int va;
 21     int l,r;
 22     node* left;
 23     node* right;
 24 }e[maxn*10];
 25 int tot = -1;
 26 int n;
 27 int a,b;
 28 int py[maxn];
 29 int cy[maxn];
 30 int h[maxn];
 31 int vh[maxn];
 32 vector<data> vec[maxn]; 
 33 int cnt1 = -1;
 34 int cnt = 0;
 35 int cnt3 = 0;
 36 inline void update(node* x){
 37     x->va = x->left->va + x->right->va;
 38 }
 39 node* build1(int l,int r){
 40     node* cur = &e[++tot];
 41     cur->l = l;
 42     cur->r = r;
 43     cur->va = 0;
 44     if(l == r){
 45         return cur;
 46     }
 47     int mid = (l+r) >>1;
 48     cur->left = build1(l,mid);
 49     cur->right = build1(mid+1,r);
 50     return cur;
 51 }
 52 void modify(node* cur,int p){
 53     if(cur->l == cur->r){
 54         cur->va++;
 55         return;
 56     }
 57     int mid = (cur->l + cur->r) >>1;
 58     if(p <= mid){
 59         modify(cur->left,p);
 60     }
 61     else{
 62         modify(cur->right,p);
 63     }
 64     update(cur);
 65 }
 66 int find(node* cur,int l,int r){
 67     if(cur->l == l && cur->r == r){
 68         return cur->va;
 69     }
 70     int mid = (cur->l + cur->r) >>1;
 71     if(r <= mid){
 72         return find(cur->left,l,r);
 73     }
 74     else if(l > mid){
 75         return find(cur->right,l,r);
 76     }
 77     else{
 78         return find(cur->left,l,mid) +find(cur->right,mid+1,r); 
 79     }
 80 }
 81 node* root1;
 82 int others[maxn];
 83 int cothers[maxn];
 84 int cnt2 = -1;
 85 int main(){
 86     scanf("%d",&n);
 87     for(int i =0;i<n;i++){
 88         scanf("%d %d",&a,&b);
 89         v[i].x =a;
 90         v[i].y =b;
 91         py[i] = b;
 92     }
 93     sort(py,py+n);
 94     cy[0] = py[0];
 95     for(int i =1;i<n;i++){
 96         if(py[i] != py[i-1]){
 97             cy[++cnt] = py[i];
 98         }
 99     }
100     for(int i =0;i<=cnt;i++){
101         ha[cy[i]] = i;
102     }
103     for(int i =0;i<n;i++){
104         h[ha[v[i].y]]++;
105     }
106     vh[cnt] = h[cnt];
107     for(int i =cnt-1;i>=0;i--){
108         vh[i] = vh[i+1] + h[i];
109     }
110     root1 = build1(0,cnt);
111     sort(v,v+n,cmp);
112     vec[++cnt1].push_back(v[0]);
113     for(int i =1;i<n;i++){
114         if(v[i].x != v[i-1].x){
115             sort(vec[cnt1].begin(),vec[cnt1].end(),cmp2);
116             cnt1++;
117         }
118         vec[cnt1].push_back(v[i]);
119     }
120     if(cnt1 == 0){
121         printf("Stan: 0; Ollie: 0;\n");
122         return 0;
123     }
124     int nowy;
125     int nowyid;
126     int find1;
127     int find2;
128     int cfind2;
129     int minfind;
130     int minfindc;
131     int maxfinda = -99999999;
132     int other = 0;
133     for(int i =0;i<=cnt1;i++){
134         minfind = 99999999;
135         for(int j =0;j<vec[i].size();j++){
136             nowy = vec[i][j].y;
137             nowyid = ha[nowy];
138             find1 = 0;
139             if(nowyid != 0){
140                 find1 = find(root1,0,nowyid-1);
141             }
142             cfind2 = find2 = 0;
143             if(nowyid != cnt){
144                 find2 = find(root1,nowyid+1,cnt);
145                 cfind2 = vh[nowyid+1] - find2 - (vec[i].size()-j-1);
146             }
147             if(find1 + cfind2 < minfind){
148                 minfind = find1+cfind2;
149                 minfindc = h[nowyid]+vec[i].size()-1;
150             }
151         }
152         if(maxfinda < minfind){
153             maxfinda = minfind;
154             other = n - maxfinda - minfindc;
155             cnt2 = -1;
156             others[++cnt2] = other;
157         }
158         else if(maxfinda == minfind){
159             other = n - maxfinda - minfindc;
160             others[++cnt2] = other;
161         }
162         for(int j = 0;j<vec[i].size();j++){
163             int check = ha[vec[i][j].y];
164             modify(root1,check);
165         }
166     }
167     printf("Stan: %d; ",maxfinda);
168     sort(others,others+cnt2+1);
169     cothers[0] = others[0];
170     for(int i =1;i<=cnt2;i++){
171         if(others[i] != others[i-1]){
172             cothers[++cnt3] = others[i];
173         }
174     }
175     printf("Ollie: ");
176     for(int i =0;i<=cnt3-1;i++){
177         printf("%d ",cothers[i]);
178     }
179     printf("%d;",cothers[cnt3]);
180     return 0;
181 } 

 

以上是关于codevs 1292 核仁巧克力的主要内容,如果未能解决你的问题,请参考以下文章

Brunch with a Friend 与朋友共进午餐

错误号:1292 在我的 SQL 错误中截断了不正确的 DOUBLE 值

CF 1292A 迷宫

AcWing 1292. 哥德巴赫猜想 线性筛+二分查找

[CF1292C] Xenon's Attack on the Gangs

热巧克力 v11 中的 DataLoaderOptions.AutoDispatch