Codeforces Round #443 (Div. 2), problem: (E) Tournament Solution In C/C++

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
int n,k;
struct node
{
int maxx[15],minn[15],sz;
node()
{
int x;sz = 1;
for(int i = 1; i <= k ; i ++)
{
scanf(“%d”,&x);
minn[i] = maxx[i] = x;
}
}
bool operator<(const node &nd)const
{
for(int i = 1; i <= k; i ++)
if(maxx[i] > nd.minn[i]) return false;
return true;
}
void merge(const node &nd)
{
for(int i = 1; i <= k; i ++){
minn[i] = min(minn[i],nd.minn[i]);
maxx[i] = max(maxx[i],nd.maxx[i]);
}
sz += nd.sz;
}
};

set<node> tr;
int main()
{

//freopen(“1.in”,”r”,stdin);
scanf(“%d%d”,&n,&k);
set<node>::iterator ub,lb;
for(int i = 1; i <= n;i ++)
{
node nd = node();
lb = tr.lower_bound(nd);
ub = tr.upper_bound(nd);
while(lb!=ub){
nd.merge(*lb);
tr.erase(lb++);
}
tr.insert(nd);
printf(“%d\n”,(tr.rbegin()) -> sz);
}
}

📦 Looking for Codeforces Round 443 Div Problem Tournament? Check the best deals on Amazon.

🛒 Shop Codeforces Round 443 Div Problem Tournament on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
int n,k;
struct node
{
int maxx[15],minn[15],sz;
node()
{
int x;sz = 1;
for(int i = 1; i <= k ; i ++)
{
scanf(“%d”,&x);
minn[i] = maxx[i] = x;
}
}
bool operator<(const node &nd)const
{
for(int i = 1; i <= k; i ++)
if(maxx[i] > nd.minn[i]) return false;
return true;
}
void merge(const node &nd)
{
for(int i = 1; i <= k; i ++){
minn[i] = min(minn[i],nd.minn[i]);
maxx[i] = max(maxx[i],nd.maxx[i]);
}
sz += nd.sz;
}
};

set<node> tr;
int main()
{

//freopen(“1.in”,”r”,stdin);
scanf(“%d%d”,&n,&k);
set<node>::iterator ub,lb;
for(int i = 1; i <= n;i ++)
{
node nd = node();
lb = tr.lower_bound(nd);
ub = tr.upper_bound(nd);
while(lb!=ub){
nd.merge(*lb);
tr.erase(lb++);
}
tr.insert(nd);
printf(“%d\n”,(tr.rbegin()) -> sz);
}
}

📦 Looking for Codeforces Round 443 Div Problem Tournament? Check the best deals on Amazon.

🛒 Shop Codeforces Round 443 Div Problem Tournament on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

The Real Truth About Viral Kitchen Gadgets Before You Buy

📢 As an Amazon Associate, I earn from qualifying purchases.After putting the Viral Kitchen Gadgets through a proper 30-day real-world test, I can tell...

Is Viral Kitchen Gadgets Worth Your Money Here Is Our Full Review

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Yongxing YogasuitFactory Seamless Thermal Underwear For Winter

When winter arrives, dressing for the freezing weather often feels like an uncomfortable compromise between staying warm and retaining natural freedom of movement. Bulky...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!