-
Notifications
You must be signed in to change notification settings - Fork 481
/
1348.cpp
30 lines (26 loc) · 865 Bytes
/
1348.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class TweetCounts
{
public:
TweetCounts() {}
void recordTweet(string tweetName, int time)
{
tweets[tweetName].insert(time);
}
vector<int> getTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime)
{
int delta = 0;
if (freq == "minute") delta = 60;
else if (freq == "hour") delta = 60 * 60;
else if (freq == "day") delta = 60 * 60 * 24;
vector<int> res((endTime - startTime) / delta + 1);
const auto pos = tweets.find(tweetName);
if (pos != tweets.end())
{
for (auto t = pos->second.lower_bound(startTime); t != pos->second.end() && *t <= endTime; ++t)
++res[(*t - startTime) / delta];
}
return res;
}
private:
unordered_map<string, multiset<int>> tweets;
};