bb4a8a1a47[1].js

class MedianFinder {
list<vector> l;
int size = 0;
static const int N = 128;
void insert_v(vector &v, int x)
{
v.resize(v.size() + 1); int i;
for (i = v.size() – 1; i>=1; –i)
if (v[i-1] > x)
v[i] = v[i-1];
else
{
v[i] = x;
break;
}
if (!i) v[0] = x;
}
public:
/** initialize your data structure here. */
MedianFinder() {
l.clear();
size = 0;
}
</vector

void addNum(int num) {
if (l.empty())
l.push_back(vector {num});
else
for (auto it = l.begin() ; it != l.end(); ++it)
if (next(it) == l.end() || num < next(it)->begin())
{
insert_v(
it, num);
if (it->size() > 2 * N)
{
vector new_v(it->begin() + N, it->end());
it->resize(N);
l.insert(next(it), std::move(new_v));
}
break;class MedianFinder {
list<vector> l;
int size = 0;
static const int N = 128;
void insert_v(vector &v, int x)
{
v.resize(v.size() + 1); int i;
for (i = v.size() – 1; i>=1; –i)
if (v[i-1] > x)
v[i] = v[i-1];
else
{
v[i] = x;
break;
}
if (!i) v[0] = x;
}
public:
/** initialize your data structure here. */
MedianFinder() {
l.clear();
size = 0;
}
</vector

void addNum(int num) {
if (l.empty())
l.push_back(vector {num});
else
for (auto it = l.begin() ; it != l.end(); ++it)
if (next(it) == l.end() || num < next(it)->begin())
{
insert_v(
it, num);
if (it->size() > 2 * N)
{
vector new_v(it->begin() + N, it->end());
it->resize(N);
l.insert(next(it), std::move(new_v));
}
break;
}
++size;
// cout << “Added ” << num << endl;
}

double findMedian() {
    int cnt = 0;
    int sum = 0; /*
    for (auto &amp;&amp;block: l)
    {
        cout &lt;&lt; "Block: "; for(int i: block) cout &lt;&lt; i &lt;&lt; ",";
        cout &lt;&lt; " \t";
    }
    cout &lt;&lt; endl; */
    for (auto it = l.begin(); it != l.end(); ++it)
    {
        int r = cnt + it-&gt;size();

if (size / 2 >= cnt && size / 2 < r)
sum += (it)[size / 2 – cnt];
if (size % 2 == 0)
if (size / 2 – 1 >= cnt && size / 2 – 1 < r)
sum += (
it)[size / 2 – 1 – cnt];
cnt = r;
}
//cout << “Found!” << endl;
return size % 2 ? sum : sum / 2.0;
}
};window.FontAwesomeConfig = {
asyncEnabled: true,
autoAccessibility: true,
useUrl: “use.fontawesome.com”,
code: “bb4a8a1a47”,
webFontLoaderVersion: “1.6.24”
};
window.FontAwesome||(window.FontAwesome={}),function(){function a(a){this.el=a;for(var b=a.className.replace(/^\s+|\s+$/g,””).split(/\s+/),c=0;c<b.length;c++)d.call(this,b[c])}function b(a,b,c){object.defineproperty?object.defineproperty(a,b,{get:c}):a.definegetter(b,c)}if(!(“undefined”=”=typeof” window.element||”classlist”in=”” document.documentelement)){var=”” c=”Array.prototype,d=c.push,e=c.splice,f=c.join;a.prototype={add:function(a){this.contains(a)||(d.call(this,a),this.el.className=this.toString())},contains:function(a){return-1!=this.el.className.indexOf(a)},item:function(a){return” this[a]||null},remove:function(a){if(this.contains(a)){for(var=”” b=”0;b<this.length&&this[b]!=a;b++);e.call(this,b,1),this.el.className=this.toString()}},toString:function(){return” f.call(this,”=”” “)},toggle:function(a){return=”” this.contains(a)?this.remove(a):this.add(a),this.contains(a)}},window.domtokenlist=”a,b(Element.prototype,"classList",function(){return” new=”” a(this)})}}(),function(a,b,c){function=”” d(a){var=”” c,d=”[],e=b,f=e.documentElement.doScroll,g="DOMContentLoaded",h=(f?/^loaded|^c/:/^loaded|^i|^c/).test(e.readyState);h||e.addEventListener(g,c=function(){for(e.removeEventListener(g,c),h=1;c=d.shift();)c()}),h?setTimeout(a,0):d.push(a)}function” e(){var=”” a,c,d,e=”b.querySelectorAll(".fa");Array.prototype.forEach.call(e,function(e){a=e.getAttribute("title"),e.setAttribute("aria-hidden","true"),c=e.nextElementSibling?!e.nextElementSibling.classList.contains("sr-only"):!0,a&&c&&(d=b.createElement("span"),d.innerHTML=a,d.classList.add("sr-only"),e.parentNode.insertBefore(d,e.nextSibling))})}function” f(a){“undefined”!=”typeof” mutationobserver&&new=”” mutationobserver(a).observe(b,{childlist:!0,subtree:!0})}function=”” g(){var=”” a=”b.createElement("link");a.href="https://"+l+"/"+m+&quot;.css",a.media="all",a.rel="stylesheet",b.getElementsByTagName("head")[0].appendChild(a)}function” h(){var=”” i(){return=”” k&&(d(e),f(e)),j?h():g()}var=”” j=”a.FontAwesomeConfig.asyncEnabled,k=a.FontAwesomeConfig.autoAccessibility,l=a.FontAwesomeConfig.useUrl,m=a.FontAwesomeConfig.code,n=a.FontAwesomeConfig.webFontLoaderVersion;a.FontAwesome.load=i}(this,document);try{window.FontAwesome.load()}catch(e){}” }=”” ++size;=”” cout=”” <<=”” “added=”” “=”” num=”” endl;=”” double=”” findmedian()=”” {=”” int=”” cnt=”0;” sum=”0;” =”” for=”” (auto=”” &&block:=”” l)=”” “block:=”” “;=”” for(int=”” i:=”” block)=”” i=”” “,”;=”” \t”;=”” it=”l.begin();” !=”l.end();” ++it)=”” r=”cnt” +=”” it-=””>size();
if (size / 2 >= cnt && size / 2 < r)
sum += (
it)[size / 2 – cnt];
if (size % 2 == 0)
if (size / 2 – 1 >= cnt && size / 2 – 1 < r)
sum += (*it)[size / 2 – 1 – cnt];
cnt = r;
}
//cout << “Found!” << endl;
return size % 2 ? sum : sum / 2.0;
}
};window.FontAwesomeConfig = {
asyncEnabled: true,
autoAccessibility: true,
useUrl: “use.fontawesome.com”,
code: “bb4a8a1a47”,
webFontLoaderVersion: “1.6.24”
};
window.FontAwesome||(window.FontAwesome={}),function(){function a(a){this.el=a;for(var b=a.className.replace(/^\s+|\s+$/g,””).split(/\s+/),c=0;c<b.length;c++)d.call(this,b[c])}function b(a,b,c){object.defineproperty?object.defineproperty(a,b,{get:c}):a.definegetter(b,c)}if(!(“undefined”=”=typeof” window.element||”classlist”in=”” document.documentelement)){var=”” c=”Array.prototype,d=c.push,e=c.splice,f=c.join;a.prototype={add:function(a){this.contains(a)||(d.call(this,a),this.el.className=this.toString())},contains:function(a){return-1!=this.el.className.indexOf(a)},item:function(a){return” this[a]||null},remove:function(a){if(this.contains(a)){for(var=”” b=”0;b<this.length&&this[b]!=a;b++);e.call(this,b,1),this.el.className=this.toString()}},toString:function(){return” f.call(this,”=”” “)},toggle:function(a){return=”” this.contains(a)?this.remove(a):this.add(a),this.contains(a)}},window.domtokenlist=”a,b(Element.prototype,"classList",function(){return” new=”” a(this)})}}(),function(a,b,c){function=”” d(a){var=”” c,d=”[],e=b,f=e.documentElement.doScroll,g="DOMContentLoaded",h=(f?/^loaded|^c/:/^loaded|^i|^c/).test(e.readyState);h||e.addEventListener(g,c=function(){for(e.removeEventListener(g,c),h=1;c=d.shift();)c()}),h?setTimeout(a,0):d.push(a)}function” e(){var=”” a,c,d,e=”b.querySelectorAll(".fa");Array.prototype.forEach.call(e,function(e){a=e.getAttribute("title"),e.setAttribute("aria-hidden","true"),c=e.nextElementSibling?!e.nextElementSibling.classList.contains("sr-only"):!0,a&&c&&(d=b.createElement("span"),d.innerHTML=a,d.classList.add("sr-only"),e.parentNode.insertBefore(d,e.nextSibling))})}function” f(a){“undefined”!=”typeof” mutationobserver&&new=”” mutationobserver(a).observe(b,{childlist:!0,subtree:!0})}function=”” g(){var=”” a=”b.createElement("link");a.href="https://"+l+"/"+m+&quot;.css",a.media="all",a.rel="stylesheet",b.getElementsByTagName("head")[0].appendChild(a)}funclass” medianfinder=”” {=”” list<vector<int=””>> l;
int size = 0;
static const int N = 128;
void insert_v(vector &v, int x)
{
v.resize(v.size() + 1); int i;
for (i = v.size() – 1; i>=1; –i)
if (v[i-1] > x)
v[i] = v[i-1];
else
{
v[i] = x;
break;
}
if (!i) v[0] = x;
}
public:
/** initialize your data structure here. */
MedianFinder() {
l.clear();
size = 0;
}
</b.length;c++)d.call(this,b[c])}function></b.length;c++)d.call(this,b[c])}function>

void addNum(int num) {
if (l.empty())
l.push_back(vector {num});
else
for (auto it = l.begin() ; it != l.end(); ++it)
if (next(it) == l.end() || num < next(it)->begin())
{
insert_v(
it, num);
if (it->size() > 2 * N)
{
vector new_v(it->begin() + N, it->end());
it->resize(N);
l.insert(next(it), std::move(new_v));
}
break;
}
++size;
// cout << “Added ” << num << endl;
}

double findMedian() {
    int cnt = 0;
    int sum = 0; /*
    for (auto &amp;&amp;block: l)
    {
        cout &lt;&lt; "Block: "; for(int i: block) cout &lt;&lt; i &lt;&lt; ",";
        cout &lt;&lt; " \t";
    }
    cout &lt;&lt; endl; */
    for (auto it = l.begin(); it != l.end(); ++it)
    {
        int r = cnt + it-&gt;size();

if (size / 2 >= cnt && size / 2 < r)
sum += (it)[size / 2 – cnt];
if (size % 2 == 0)
if (size / 2 – 1 >= cnt && size / 2 – 1 < r)
sum += (
it)[size / 2 – 1 – cnt];
cnt = r;
}
//cout << “Found!” << endl;
return size % 2 ? sum : sum / 2.0;
}
};window.FontAwesomeConfig = {
asyncEnabled: true,
autoAccessibility: true,
useUrl: “use.fontawesome.com”,
code: “bb4a8a1a47”,
webFontLoaderVersion: “1.6.24”
};
window.FontAwesome||(window.FontAwesome={}),function(){function a(a){this.el=a;for(var b=a.className.replace(/^\s+|\s+$/g,””).split(/\s+/),c=0;c<b.length;c++)d.call(this,b[c])}function b(a,b,c){object.defineproperty?object.defineproperty(a,b,{get:c}):a.definegetter(b,c)}if(!(“undefined”=”=typeof” window.element||”classlist”in=”” document.documentelement)){var=”” c=”Array.prototype,d=c.push,e=c.splice,f=c.join;a.prototype={add:function(a){this.contains(a)||(d.call(this,a),this.el.className=this.toString())},contains:function(a){return-1!=this.el.className.indexOf(a)},item:function(a){return” this[a]||null},remove:function(a){if(this.contains(a)){for(var=”” b=”0;b<this.length&&this[b]!=a;b++);e.call(this,b,1),this.el.className=this.toString()}},toString:function(){return” f.call(this,”=”” “)},toggle:function(a){return=”” this.contains(a)?this.remove(a):this.add(a),this.contains(a)}},window.domtokenlist=”a,b(Element.prototype,"classList",function(){return” new=”” a(this)})}}(),function(a,b,c){function=”” d(a){var=”” c,d=”[],e=b,f=e.documentElement.doScroll,g="DOMContentLoaded",h=(f?/^loaded|^c/:/^loaded|^i|^c/).test(e.readyState);h||e.addEventListener(g,c=function(){for(e.removeEventListener(g,c),h=1;c=d.shift();)c()}),h?setTimeout(a,0):d.push(a)}function” e(){var=”” a,c,d,e=”b.querySelectorAll(".fa");Array.prototype.forEach.call(e,function(e){a=e.getAttribute("title"),e.setAttribute("aria-hidden","true"),c=e.nextElementSibling?!e.nextElementSibling.classList.contains("sr-only"):!0,a&&c&&(d=b.createElement("span"),d.innerHTML=a,d.classList.add("sr-only"),e.parentNode.insertBefore(d,e.nextSibling))})}function” f(a){“undefined”!=”typeof” mutationobserver&&new=”” mutationobserver(a).observe(b,{childlist:!0,subtree:!0})}function=”” g(){var=”” a=”b.createElement("link");a.href="https://"+l+"/"+m+&quot;.css",a.media="all",a.rel="stylesheet",b.getElementsByTagName("head")[0].appendChild(a)}function” h(){var=”” i(){return=”” k&&(d(e),f(e)),j?h():g()}var=”” j=”a.FontAwesomeConfig.asyncEnabled,k=a.FontAwesomeConfig.autoAccessibility,l=a.FontAwesomeConfig.useUrl,m=a.FontAwesomeConfig.code,n=a.FontAwesomeConfig.webFontLoaderVersion;a.FontAwesome.load=i}(this,document);try{window.FontAwesome.load()}catch(e){}” ction=”” <=”” p=””></b.length;c++)d.call(this,b[c])}function>