【hihoCoder 1513】小Hi的烦恼

http://hihocoder.com/problemset/problem/1513
h[j][i]记录第j个学科排名小于等于i的状态,bitset压位就可以了。

#include<bitset>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N = 30003;

int n, S[N][5], id[N], c;
bitset <N> h[5][N], t;

bool cmp(int x, int y) {return S[x][c] < S[y][c];}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j < 5; ++j)
			scanf("%d", &S[i][j]);
	
	for (int i = 1; i <= n; ++i) id[i] = i;
	for (int j = 0; j < 5; ++j) {
		c = j;
		stable_sort(id + 1, id + n + 1, cmp);
		for (int i = 1; i <= n; ++i) {
			h[j][S[id[i]][j]] = h[j][S[id[i]][j] - 1];
			h[j][S[id[i]][j]].set(id[i]);
		}
	}
	
	for (int i = 1; i <= n; ++i) {
		t = h[0][S[i][0] - 1];
		for (int j = 1; j < 5; ++j)
			t &= h[j][S[i][j] - 1];
		printf("%d\n", t.count());
	}
	return 0;
}
posted @ 2017-04-25 11:26  abclzr  阅读(243)  评论(0编辑  收藏  举报