不知道手写哈希会不会快一点,,
map如果赋了键,那么在后续判断的时候,当它的值为零时,size还是存在的,需要erase去除
算法1
C++ 代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 86400;
const int N = 4E5 + 5;
int n;
vector<ll> sum[N];
ll t[N], ans[N], fi, ho, tag = 1;
unordered_map<ll,ll> st;
int mov = 1, tagg = 1;
//-10%3=2 or -1
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n;
for(int i = 1; i <= n; ++ i){
int ss, tt; cin >> tt >> ss;
t[tagg ++] = tt;
for(int j = 1; j <= ss; ++ j){
ll x; cin >> x;
sum[i].push_back(x);
st[x] ++;
}
while(i >= mov && t[i] - inf >= t[mov]){
for(const auto &u : sum[mov]) {
st[u] --;
if(!st[u]) st.erase(u);
}
mov ++;
}
//cout << mov << '\n';
ho = st.size();
//cout << ho << ' ' << "!";
//cout << '\n';
ans[tag] = ans[tag - 1] + (ho - fi);
fi = st.size();
tag ++;
}
for(int i = 1; i < tag; ++ i) cout << ans[i] << '\n';
return 0;
}