# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
298449 | 2020-09-12T21:23:27 Z | ElyesChaabouni | Wall (IOI14_wall) | C++14 | 0 ms | 0 KB |
//#pragma GCC optimize("O3") #include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#define ordered_set tree<int, null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> #define eps 1e-9 #define MOD1 998244353 #define MOD2 1000000007 #define INV_10 299473306 #define INF 1000000000 #define PI 3.14159265358979323846 using namespace std; void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) { int p=1; while(p <= n) p*=2; pair<int, int> max_tree[2*p+1], min_tree[2*p+1]; for(int i = 0; i < 2*p+1; i++) max_tree[i]=make_pair(0, -1); for(int i = 0; i < 2*p+1; i++) min_tree[i]=make_pair(1000000, -1); for(int i = 0; i < k; i++) { int x=left[i]+p, y=right[i]+p; if(op[i]==1) { while(x <= y) { if(x%2==1) { max_tree[x]=max(max_tree[x], make_pair(h[i], i)); x++; } if(y%2==0) { max_tree[y]=max(max_tree[y], make_pair(h[i], i)); y++; } } } else { while(x <= y) { if(x%2==1) { min_tree[x]=min(min_tree[x], make_pair(h[i], -i)); x++; } if(y%2==0) { min_tree[y]=min(min_tree[y], make_pair(h[i], -i)); y++; } } } } for(int i = 1; i <= n; i++) { int x=i+p; pair<int, int> ma=make_pair(0, -1), mi=make_pair(1000000, -1); while(x >= 1) { ma=max(ma, max_tree[x]); mi=min(mi, min_tree[x]); x/=2; } if(mi.first >= ma.first) finalHeight[i]=ma; else { if(mi.second*(-1) > ma.second) finalHeight[i]=mi.first; else finalHeight[i]=ma.first; } } } //size