地址
考虑pre[5][maxn]个布尔数组,pre[i][j]代表科目i前j小的位置情况。那么我们只需要知道对于每个人他是第几小,然后把所有科目都取&,有多少1就代表有多少小于等于它的数。
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int maxn = 30005;
typedef long long ll;
const ll mod = 1e9+7;
int Case = 1;
int n, m;
int id[maxn], s[maxn][6], a[maxn][5];
bitset<maxn>st[maxn][6];
void solve() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= 5; j++) {
scanf("%d", &a[i][j]);
s[a[i][j]][j] = i;
}
}
for(int j = 1; j <= 5; j++) {
for(int i = 2; i <= n; i++) {
st[i][j] |= st[i-1][j];
st[i][j].set(s[i-1][j]);
}
}
for(int i = 1; i <= n; i++) {
bitset<maxn>t;t.set();
for(int j = 1; j <= 5; j++) {
t &= st[a[i][j]][j];
}
printf("%d\n", (int)t.count());
}
return;
}
int main() {
//g++ -std=c++11 -o2 1.cpp -o f && ./f < in.txt
//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
//freopen("in.txt", "r", stdin);
//freopen("out.txt","w",stdout);
#endif
while(Case--) {
solve();
}
return 0;
}