ural 1090 In the Army Now

时间:2023-03-09 12:46:18
ural 1090 In the Army Now

http://acm.timus.ru/problem.aspx?space=1&num=1090

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 20000
using namespace std; int c[maxn],n,a[maxn];
int lowbit(int x)
{
return x&(-x);
} void add(int pos)
{
while(pos<=n)
{
c[pos]++;
pos+=lowbit(pos);
}
} int sum1(int pos)
{
int sum=;
while(pos>)
{
sum+=c[pos];
pos-=lowbit(pos);
}
return sum;
} int main()
{
int m;
scanf("%d%d",&n,&m);
int max1=-,x;
for(int i=; i<=m; i++)
{
memset(c,,sizeof(c));
for(int j=; j<=n; j++)
{
scanf("%d",&a[j]);
}
int s=;
for(int j=n; j>=; j--)
{
add(a[j]);
s+=sum1(a[j]-);
}
if(s>max1){max1=s; x=i;}
}
printf("%d\n",x);
return ;
}