Submission #608566

#TimeUsernameProblemLanguageResultExecution timeMemory
608566NicolaAbusaad2014Wall (IOI14_wall)C++14
61 / 100
3074 ms122192 KiB
#include "wall.h" #include <bits/stdc++.h> using namespace std; struct segment_tree { struct node { int mx,mn,left,right; }; int inf=1e9; node dum; vector<node>tree; vector<int>upd_mn,upd_mx; node operation(node x,node z) { node ret; ret.mx=max(x.mx,z.mx); ret.mn=min(x.mn,z.mn); ret.left=min(x.left,z.left); ret.right=max(x.right,z.right); return ret; } void push(int node) { tree[node].mx=min(tree[node].mx,upd_mn[node]); tree[node].mn=min(tree[node].mn,tree[node].mx); tree[node].mn=max(tree[node].mn,upd_mx[node]); tree[node].mx=max(tree[node].mn,tree[node].mx); if(node<tree[0].mx){ upd_mn[node*2]=min(upd_mn[node],upd_mn[node*2]); upd_mx[node*2]=max(upd_mx[node],upd_mx[node*2]); upd_mx[node*2]=min(upd_mn[node],upd_mx[node*2]); upd_mn[node*2]=max(upd_mx[node],upd_mn[node*2]); upd_mn[node*2+1]=min(upd_mn[node],upd_mn[node*2+1]); upd_mx[node*2+1]=max(upd_mx[node],upd_mx[node*2+1]); upd_mx[node*2+1]=min(upd_mn[node],upd_mx[node*2+1]); upd_mn[node*2+1]=max(upd_mx[node],upd_mn[node*2+1]); } upd_mn[node]=inf; upd_mx[node]=-inf; } void build(vector<int>v) { tree.clear(); upd_mn.clear(); upd_mx.clear(); int x=((v.size())*2)-1; while(x&(x-1)){ x=x&(x-1); } tree.resize(x*2); upd_mn.resize(x*2); upd_mx.resize(x*2); tree[0].mx=x; dum.mx=0; dum.mn=0; dum.left=-1e18; dum.right=1e18; for(int i=0;i<v.size();i++){ upd_mn[i]=inf; upd_mx[i]=-inf; tree[i+x].mx=v[i]; tree[i+x].mn=v[i]; tree[i+x].left=i; tree[i+x].right=i; } for(int i=v.size();i<x;i++){ upd_mn[i]=inf; upd_mx[i]=-inf; tree[i+x].left=i; tree[i+x].right=i; } for(int i=x-1;i>0;i--){ upd_mn[i]=inf; upd_mx[i]=-inf; tree[i]=operation(tree[i*2],tree[(i*2)+1]); } } node get(int l,int r,int node=1) { push(node); if(tree[node].left>r||tree[node].right<l){ return dum; } if(tree[node].left>=l&&tree[node].right<=r){ return tree[node]; } return operation(get(l,r,node*2),get(l,r,(node*2)+1)); } void update_mx(int l,int r,int z,int node=1) { push(node); if(tree[node].left>r||tree[node].right<l){ return; } if(tree[node].left>=l&&tree[node].right<=r){ upd_mx[node]=z; push(node); return; } update_mx(l,r,z,node*2); update_mx(l,r,z,(node*2)+1); tree[node]=operation(tree[node*2],tree[(node*2)+1]); } void update_mn(int l,int r,int z,int node=1) { push(node); if(tree[node].left>r||tree[node].right<l){ return; } if(tree[node].left>=l&&tree[node].right<=r){ upd_mn[node]=z; push(node); return; } update_mn(l,r,z,node*2); update_mn(l,r,z,(node*2)+1); tree[node]=operation(tree[node*2],tree[(node*2)+1]); } }; void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){ vector<int>dum(n); segment_tree st; st.build(dum); for(int i=0;i<k;i++){ if(op[i]==1){ st.update_mx(left[i],right[i],height[i]); continue; } st.update_mn(left[i],right[i],height[i]); } for(int i=0;i<n;i++){ finalHeight[i]=st.get(i,i).mx; } return; }

Compilation message (stderr)

wall.cpp: In member function 'void segment_tree::build(std::vector<int>)':
wall.cpp:59:18: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
   59 |         dum.left=-1e18;
      |                  ^~~~~
wall.cpp:60:19: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   60 |         dum.right=1e18;
      |                   ^~~~
wall.cpp:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for(int i=0;i<v.size();i++){
      |                     ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...