惠山做网站公司,建设网站基本思路,网站开发用例说明,wordpress几种版本链接#xff1a;
2251. 花期内花的数目
题意
n朵花#xff0c;有n个花期#xff0c;m个人在m个时间来#xff0c;求每个时间有多少朵花
解#xff1a;
通过差分确定一个时间段内的花数量
再通过离线查询#xff08;因为返回答案数组#xff09;进行记忆存储#…链接
2251. 花期内花的数目
题意
n朵花有n个花期m个人在m个时间来求每个时间有多少朵花
解
通过差分确定一个时间段内的花数量
再通过离线查询因为返回答案数组进行记忆存储只需要一次遍历
实际代码
#includebits/stdc.h
using namespace std;
vectorint fullBloomFlowers(vectorvectorint flowers, vectorint people)
{mapint,intcf;for(const auto flower:flowers){cf[flower[0]];cf[flower[1]1]--;}vectorintpeople_sortpeople;sort(people_sort.begin(),people_sort.end());mapint,intS2S;int num0;auto itcf.begin();for(auto p:people_sort){while(it!cf.end() it-firstp){numit-second;it;}S2S[p]num;}vectorintans;for(auto p:people){ans.push_back(S2S[p]);}return ans;
}限制
1 flowers.length 5 * 104flowers[i].length 21 starti endi 1091 people.length 5 * 1041 people[i] 109