Skip to content

Instantly share code, notes, and snippets.

@fardinabir
Last active March 8, 2021 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fardinabir/6afbab19133125d1a36ef24debd442ce to your computer and use it in GitHub Desktop.
Save fardinabir/6afbab19133125d1a36ef24debd442ce to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define test_case printf("Case %d:\n",id++);
using namespace std;
using namespace __gnu_pbds;
ll arr[100005],fq[100000],node[100005],ind[26],ind1[26],n,m;
void update(int idx)
{
for(;idx<=n;node[idx]++,idx+=idx&(-idx));
}
int query(int idx)
{
int sum=0;
for(;idx>0;sum+=node[idx],idx-=idx&(-idx));
return sum;
}
int main()
{
ll t,i,j,k,r,c,cc,mn,mx=-1,g,s,a,d,b,l=1,li,id=1;
string st,st1,st2;
cin>>n>>m;
for(a=0;a<m;a++)
{
c=0;
for(i=0;i<n;i++)
{
cin>>arr[i];
c+=query(n+1-arr[i]);
update(n+1-arr[i]);
}
if(c>mx)
mx=c,mn=a+1;
memset(node,0,sizeof node);
}
cout<<mn<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment