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

#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);
}
}

#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);
}
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Curiosity has found the largest field of honeycomb fractures it has ever encountered on Mars. Similar polygons elsewhere preserve mud repeatedly soaked and dried...

NASA’s Curiosity rover has made an extraordinary geological discovery on the Red Planet, uncovering the largest expanse of honeycomb-shaped fractures it has ever encountered....

7 Reasons This Viral Kitchen Gadgets Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.I stumbled across this while desperately trying to fix a recurring problem in my routine....

Stop Buying Cheap Alternatives This Viral Kitchen Gadgets Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases.I stumbled across this while desperately trying to fix a recurring problem in my routine....

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!