【hihoCoder】#1513 : 小Hi的烦恼
题解
我会五维数点辣
只要用个bitset乱搞就好了
记录一下rk[i][j]表示第j科排名为i的是谁
用30000 * 5个大小为30000的bitset
s[i][j]是一个bitset表示第j科,排名为1 - i的人是多少
最后只要对于每个人,把每一维小于它的集合and起来,然后用count()函数输出里面1的个数
代码
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>
#include <bitset>
#define enter putchar('\n')
#define space putchar(' ')
//#define ivorysi
#define pb push_back
#define MAXN 30005
#define mo 974711
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 - '0' + c;
c = getchar();
}
res = res * f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) out(x / 10);
putchar('0' + x % 10);
}
int N;
bitset <MAXN> s[MAXN][6];
int a[MAXN][6],rk[MAXN][6];
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {
for(int j = 1 ; j <= 5 ; ++j) {
read(a[i][j]);
rk[a[i][j]][j] = i;
}
}
for(int j = 1 ; j <= 5 ; ++j) {
for(int i = 1 ; i <= N ; ++i) {
s[i][j] = s[i - 1][j];
s[i][j][rk[i][j]] = 1;
}
}
for(int i = 1 ; i <= N ; ++i) {
bitset <MAXN> tmp;
tmp = s[a[i][1] - 1][1];
for(int j = 2 ; j <= 5 ; ++j) tmp &= s[a[i][j] - 1][j];
out(tmp.count());enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}