7-11和13都TLE了,然后第1题wa了(在本地测试的时候倒是没问题)
by 2320508123hzc @ 2024-04-27 14:44:08
如果你觉得太长,看下最后一句话。
```
#include <iostream>
#include <queue>
#include <vector>
class shape{
public:
int t,k;
std::vector <int> country;
};
int main(){
std::ios::sync_with_stdio(0);
std::cin.tie(0),std::cout.tie(0);
int n,num = 0;
std::queue <shape> Q;
std::vector <int> count(3e5 + 1,0);
std::cin >> n;
while (n--){
shape tmp;
std::cin >> tmp.t >> tmp.k;
tmp.country.resize(tmp.k + 1);
for (int i = 1;i <= tmp.k;i++)
std::cin >> tmp.country[i];
Q.push(tmp);
for (int i = 1;i <= tmp.k;i++){
count[tmp.country[i]]++;
if (count[tmp.country[i]] == 1) num++;
}
while (tmp.t - 86400 >= Q.front().t){
for (int i = 1;i <= Q.front().k;i++){
count[Q.front().country[i]]--;
if (!count[Q.front().country[i]]) num--;
}
Q.pop();
}
std::cout << num << '\n';
}
return 0;
}
```
别看我的很长,这53行里,空行一大堆,而且关同步的两行去掉也完全可以通过。
by asd890123 @ 2024-05-09 17:30:45
说错了,54行
by asd890123 @ 2024-05-09 17:31:32
vector就是可变长度数组,看不懂换成数组就行(最好还是学一下很有用)。
by asd890123 @ 2024-05-09 17:32:55