879E - Tournament - CodeForces Solution


data structures *2700

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>

using namespace std;
set<pair<int,int> >::iterator it;
int sef[500005];
int sz[500005];
int mat2[15][500005];
int mat3[15][500005];
int mat[15][500005];
int n,k;
struct grup
{
    int sz,mat3[15],mat2[15];
    bool operator < (const grup&rhs) const
    {
        for(int j=1; j<=k; j++)if(mat2[j]>rhs.mat3[j])return 0;
        return 1;
    }
};
set<grup>st;
void merge(grup x,grup y)
{
    int i;
    x.sz+=y.sz;
    for(i=1; i<=k; i++)
    {
        x.mat3[i]=min(x.mat3[i],y.mat3[i]);
        x.mat2[i]=max(x.mat2[i],y.mat2[i]);
    }
}
int main()
{
    long long n,i,j,l,z,m,a,b,t=1,suma=0,h,poz1,poz2,x,y,c,d,c1,c2,nra,nrc,sol,x2,y2,val,op,q,tip,gc,prod,u,dr,diffst,diffdr,ramase,nr,cate,curr,rez,rad,rest,ultimu,primu,leng,e,f,semn   ;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    t=1;
    string s;
    string s1;
    char ch;
    cin>>n>>k;
    for(i=1; i<=n; i++)
    {
        sef[i]=i;
        sz[i]=1;
    }
    for(i=1; i<=n; i++)
    {
        grup curr;
        for(j=1; j<=k; j++)
        {
            cin>>mat[j][i];
            curr.mat2[j]=mat[j][i];
            curr.mat3[j]=mat[j][i];
            curr.sz=1;
        }
        set <grup> :: iterator l, r;
        l=st.lower_bound(curr);
        r=st.upper_bound(curr);
        while(l!=r)
        {
            curr.sz+=l->sz;
            for(j=1; j<=k; j++)
            {
                curr.mat3[j]=min(curr.mat3[j],l->mat3[j]);
                curr.mat2[j]=max(curr.mat2[j],l->mat2[j]);
            }
            st.erase(l++);
        }
        st.insert(curr);
        cout<<st.rbegin()->sz<<endl;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1475A - Odd Divisor
1454B - Unique Bid Auction
978C - Letters
501B - Misha and Changing Handles
1496A - Split it
1666L - Labyrinth
1294B - Collecting Packages
1642B - Power Walking
1424M - Ancient Language
600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND
1669E - 2-Letter Strings
483A - Counterexample
3C - Tic-tac-toe
1669F - Eating Candies
1323B - Count Subrectangles
991C - Candies
1463A - Dungeon
1671D - Insert a Progression
1671A - String Building
1671B - Consecutive Points Segment
1671C - Dolce Vita
1669G - Fall Down
4D - Mysterious Present
1316B - String Modification
1204A - BowWow and the Timetable
508B - Anton and currency you all know