QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#116041 | #4772. Movie collection | momoyuu# | AC ✓ | 42ms | 4692kb | C++17 | 1.2kb | 2023-06-28 00:53:19 | 2023-06-28 00:53:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template< typename T >
struct BIT{
int n;
vector<T> data;
BIT(int n):n(n),data(n+1,0){}
void add(int i,T x){
i++;
while(i<=n){
data[i] += x;
i += i & (-i);
}
}
//sum of [l,r)
T sum(int l,int r){
return sum(r-1)-sum(l-1);
}
T sum(int i){
i++;
T now = 0;
while(i>0){
now += data[i];
i -= i & (-i);
}
return now;
}
};
void solve(){
int n,m;
cin>>n>>m;
BIT<int> bit(n+m+10);
for(int i =0;i<n;i++) bit.add(i,1);
vector<int> idx(n,0);
for(int i = 0;i<n;i++) idx[i] = n - i - 1;
int ni = n;
for(int i = 0;i<m;i++){
int a;
cin>>a;
a--;
if(i) cout<<" ";
cout<<bit.sum(idx[a],n+m+10)-1;
bit.add(idx[a],-1);
idx[a] = ni++;
bit.add(idx[a],1);
}
cout<<endl;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3468kb
input:
2 3 3 3 1 1 5 3 4 4 5
output:
2 1 0 3 0 4
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 42ms
memory: 4692kb
input:
25 3 3 3 1 1 5 3 4 4 5 84 887 10 20 30 32 11 73 58 74 3 20 63 68 84 71 25 79 17 17 60 57 76 10 3 27 27 56 44 20 6 43 67 55 18 52 2 29 80 59 58 82 34 36 21 74 63 45 24 79 18 83 8 9 9 10 75 75 65 74 10 70 33 76 81 6 83 82 74 78 13 4 31 46 39 52 75 57 52 15 8 25 13 15 33 61 64 24 51 44 13 61 69 1 8 65 ...
output:
2 1 0 3 0 4 9 19 29 31 13 72 58 73 10 7 64 69 83 73 33 79 28 0 66 65 77 18 12 39 0 66 55 15 26 55 73 67 38 65 29 47 80 69 27 82 53 55 47 31 31 62 51 29 15 83 43 44 0 28 80 0 76 11 3 79 59 33 83 29 11 20 8 83 52 49 61 69 66 32 17 41 2 57 21 45 10 3 18 77 79 27 76 43 7 5 81 57 11 28 74 60 64 38 72 55 ...
result:
ok 25 lines