1
#include <iostream>
#include <stdio.h>
using namespace std;
int n , a[1024][1024];
void cal( int n , int x , int y )
{
if( n == 0 ) a[x][y] = 1;
else
{
cal( n - 1 , x + ( 1 << n - 1 ) , y );
cal( n - 1 , x , y + ( 1 << n - 1 ) );
cal( n - 1 , x + ( 1 << n - 1 ) , y + ( 1 << n - 1 ) );
}
}
int main()
{
cin >> n;
cal( n , 0 , 0 );
for( register int i = 0 ; i < 1 << n ; i++ )
for( register int j = 0 ; j < 1 << n ; j++ )
cout << a[i][j] << ( j == ( 1 << n ) - 1 ? '\n' : ' ' );
return 0;
}
# 2
# 3
#include <stdio.h>
#include
#include <string.h>
#define MAXN 1000010
#define lowbit( i ) i & -i
using namespace std;
int T , n , a[ MAXN ] , b[ MAXN ] , v[ 32 ];
long long t[ MAXN ];
struct io
{
char ibuf[10 << 20] , * s;
io()
{
fread( s = ibuf , 1 , 10 << 20 , stdin );
}
inline int read()
{
register int u = 0;
while( * s < 48 ) s++;
while( * s > 32 )
u = u * 10 + * s++ - 48;
return u;
}
} ip;
#define read ip.read
inline void insert( int x , int y )
{
for( register int i = x ; i <= n ; i += lowbit( i ) ) t[i] += y;
}
inline long long find( int x )
{
long long ans = 0;
for( register int i = x ; i ; i -= lowbit( i ) ) ans += t[i];
return ans;
}
inline void add( long long x )
{
int pos = 0;
while( x )
{
v[ pos++ ] += x % 10;
x /= 10;
}
}
inline void print()
{
int pos = 0;
for( register int i = 0 ; i < 30 ; i++ )
{
v[i + 1] += v[i] / 10 , v[i] %= 10;
if( v[i] ) pos = i;
}
for( register int i = pos ; ~i ; i-- )
putchar( v[i] + ‘0’ );
putchar( ‘\n’ );
}
int main()
{
n = read();
for( register int i = 1 ; i <= n ; i++ ) a[i] = b[i] = read();
sort( b + 1 , b + n + 1 );
for( register int i = 1 ; i <= n ; i++ )
{
a[i] = lower_bound( b + 1 , b + n + 1 , a[i] ) - b;
add( ( ( i * 1ll * ( i - 1 ) >> 1 ) - find( a[i] ) ) * 1ll * ( n - i + 1 ) );
insert( a[i] , i );
}
print();
return 0;
}