题目链接
题解
cdq 套cdq 套cdq 套cdq就完了呀
对每一科开n个bitset 表示该科目前i个有谁
每次查询都&起来就好了
代码
#include<cstdio>
#include<bitset>
#include<cstring>
#include<algorithm>
#define LL long long
#define gc getchar()
#define pc putchar
inline int read() {
int x = 0,f = 1;
char c = gc;
while(c < '0' || c > '9' )c = gc;
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc;
return x * f ;
}
void print(LL x) {
if(x >= 10) print(x / 10);
pc(x % 10 + '0');
}
const int maxn = 30007;
std::bitset<maxn>b[6][maxn];
int a[maxn][6];
int rk[maxn];
int main() {
int n = read();
for(int i = 1;i <= n;++ i)
for(int j = 1;j <= 5;++ j) {
a[i][j] = read();
}
for(int j = 1;j <= 5;++ j) {
for(int i = 1;i <= n;++ i) rk[a[i][j]] = i - 1;
for(int i = 1;i <= n;++ i) {
b[j][i] = b[j][i - 1];
b[j][i].set(rk[i]);
}
}
std::bitset<maxn>ans;
for(int i = 1;i <= n;++ i) {
ans.set();
for(int j = 1;j <= 5;++ j) ans &= b[j][a[i][j] - 1];
print(ans.count());
pc('\n');
}
return 0;
}