本文整理汇总了C++中map::lower_bound方法的典型用法代码示例。如果您正苦于以下问题:C++ map::lower_bound方法的具体用法?C++ map::lower_bound怎么用?C++ map::lower_bound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map
的用法示例。
在下文中一共展示了map::lower_bound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void run() {
scanf("%d%d", &n, &m);
last.clear(); last[m] = 1;
for (int i = 0; i < n; ++i) {
int x, s = 0; scanf("%d", &x);
auto it = last.lower_bound(x);
for (; it != last.end(); ) {
last[it->first % x] += it->second;
s += it->second * (it->first / x);
it = last.erase(it);
}
if (s) last[x - 1] += s;
}
int s = 0;
for (auto it = last.rbegin(); it != last.rend(); ++it) {
it->second += s; s = it->second;
}
int q, ret = 0; scanf("%d", &q);
for (int i = 1; i <= q; ++i) {
int x; scanf("%d", &x);
auto it = last.lower_bound(x);
if (it != last.end()) ret += 1ll * it->second * i % M;
if (ret >= M) ret -= M;
}
printf("%d\n", ret);
}
示例2: main
int main() {
scanf("%d",&n);
for (int i=0; i<n; i++) {
scanf("%d %d",&q[i].first,&q[i].second);
}
sort(q,q+n);
for (int i=0; i<n; i++) {
int h = q[i].second;
mp[q[i].first]--;
int piv = q[i].first-h;
aauto it = mp.lower_bound(piv);
pi t = *it;
mp.erase(it);
int gap = t.first - piv;
if(t.second != -1) mp.insert(pi(t.first,t.second + 1));
it = mp.lower_bound(piv);
if(it == mp.begin()) {
mp[gap]--;
}
else {
it--;
t = *it;
mp.erase(it);
if(t.second != -1) mp.insert(pi(t.first,t.second + 1));
mp[t.first + gap]--;
}
}
long long ret = 0, cnts = 0;
for (int i=q[n-1].first; i>=0; i--) {
ret += cnts * (cnts - 1) / 2;
cnts -= mp[i];
}
printf("%lld",ret);
}
示例3: query
bool query(int sx, int ex, int sy, int ey){
auto itl = mp1.lower_bound(sx);
auto itr = mp1.upper_bound(ex);
if(itl == mp1.end() || itl->first > ex) return 0;
if(itl->second > ey) return 0;
itr--;
if(itr->second < sy) return 0;
auto ity = mp2.lower_bound(sy);
if(ity == mp2.end() || ity->first > ey) return 0;
return 1;
}
示例4: get
string get(string key) {
if (circle.empty()) {
return "";
}
int code = hash<string>()(key);
if (circle.find(code) ==circle.end()) {
if(circle.lower_bound(code) != circle.end()) return circle.lower_bound(code)->second;
else return circle.begin()->second;
}
return circle.find(code)->second;
}
示例5: scanAscending
void scanAscending(RecordListResponse& _return, const map<string, string>& mymap,
const string& startKey, const bool startKeyIncluded,
const string& endKey, const bool endKeyIncluded,
const int32_t maxRecords, const int32_t maxBytes) {
map<string, string>::const_iterator itr = startKeyIncluded ?
mymap.lower_bound(startKey):
mymap.upper_bound(startKey);
int numBytes = 0;
while (itr != mymap.end()) {
if (!endKey.empty()) {
if (endKeyIncluded && endKey < itr->first) {
break;
}
if (!endKeyIncluded && endKey <= itr->first) {
break;
}
}
Record record;
record.key = itr->first;
record.value = itr->second;
numBytes += record.key.size() + record.value.size();
_return.records.push_back(record);
if (_return.records.size() >= (uint32_t)maxRecords || numBytes >= maxBytes) {
_return.responseCode = ResponseCode::Success;
return;
}
itr++;
}
_return.responseCode = ResponseCode::ScanEnded;
}
示例6: work
bool work(int t, int m) {
int x = max_x[0];
rep(i, m) {
auto next = yc.upper_bound(max_y[xc.lower_bound(x - t)->snd] + t);
if(next == yc.end()) return true;
x = max_x[next->snd];
}
示例7: computeCost
void computeCost(int node , stack<Pair> st , map<lli , lli> mp)
{
///Pair : (cost from that node , level of that node) -->
/// (cost , level)
///mp[level]= cost ---> for easy searching
//cout<<"At node "<<node<<endl;
if(node==0)
{
st.push(make_pair(0,0));
mp[0]=0;
cost[0] =0;
}
else
{
int i;
int currentlevel = st.top().second + 1;
lli tmpcost , mincost= inf;
for(i=0;i<tickets[node].size();i++)
{
Pair t = tickets[node][i];
lli t_k = t.first;
lli t_w = t.second;
if(t_k>=currentlevel)
tmpcost = t_w ;
else
{
tmpcost = t_w + (mp.lower_bound(currentlevel - t_k)->second) ;
}
if(tmpcost<mincost) mincost = tmpcost ;
}
lli top_cost = st.top().first ;
lli top_level = st.top().second ;
while(top_cost >= mincost)
{
st.pop();
mp.erase(mp.find(top_level));
top_cost = st.top().first ;
top_level = st.top().second ;
}
st.push(make_pair(mincost,currentlevel));
mp[currentlevel] = mincost ;
cost[node]=mincost;
}
int i,v;
for(i=0;i<children[node].size();i++)
{
v = children[node][i];
computeCost(v, st , mp);
}
}
示例8: next
pair<int, int> next(const map<int, int>& mp, int k) {
map<int, int>::const_iterator it = mp.lower_bound(k);
if (it == mp.end()) {
it = mp.begin();
}
return *it;
}
示例9: update_bp
void update_bp(pos & a, pos & b) {
if (a>b) {
pos t = a;
a=b;
b=t;
}
if (a>b || a.chr!=b.chr) {
cerr << " Failed pre condition " << endl;
exit(1);
}
//find the nearest bp
map<pos, bp>::iterator it= bps.lower_bound(a);
while (it!=bps.end() && it->first.chr==a.chr && it->first.coord>=a.coord && it->first.coord<=b.coord) {
if (a.marked) {
it->second.lefts++;
}
if (b.marked) {
it->second.rights++;
}
it++;
}
return ;
}
示例10: work
bool work() {
if(cntn==0)return false;
for(int i=1;i<=n;i++)
if(a[i]==n &°n[i]<=1){
newcntn=0;
dfs1(i,0);
break;
}
if(cntn!=newcntn)return false;
memset(acer,0,sizeof(acer));
int root=n+1;
for(int i=1;i<=n;i++)
if(a[i]==n && degn[i]<=1){
root=i;
break;
}
if((!dfs(root,0)))
return false;
for(int i=n;i>=1;i--) {
if(acer[i])continue;
map<int,bool>::iterator it=ma.lower_bound(n+1-a[i]);
if(it==ma.end()) return false;
a[i]=n+1-it->first;
ma.erase(n+1-a[i]);
}
return true;
}
示例11: invertParity
int invertParity(int n){
int extra_shifts = 0;
if ((n & 1) == 1){
return n<<1;
}else {
unsigned int inverted = n;
int shift = 1; // for 2
while ((inverted & 1) == 0){
if (shiftFor.count(inverted) == 1){
shift = shiftFor[inverted];
if (extra_shifts > 0){
extra_shifts += shift;
shiftFor[n] = extra_shifts;
extra_shifts = 0;
}
return inverted>>shift;
}else{
it = shiftFor.lower_bound(inverted);
if (it != shiftFor.begin()){
--it;
}
shift = shiftFor[inverted % it->first];
extra_shifts += shift;
}
inverted>>=shift;
}
示例12: findSongPrefixes
void findSongPrefixes(string prefix) {
map<string,songData*>::const_iterator it = songList.lower_bound(prefix); // looks for song that starts with prefix
int prefixLength = prefix.size();
string songMatch;
multimap<int,string> songsWithPrefix; // list of songs that has the prefix sorted by popularity
if( it != songList.end() ){ //if there is a song that starts with the prefix
do{
songMatch = it->first;
if (songMatch.compare(0, prefixLength, prefix) == 0){ // check to see it if it a prefix
if(playlistChange) updateSongPopularity(it -> first); // update song's popularity if there was a change to the playlist databse
songsWithPrefix.insert( std::pair<int,string>(it -> second->popularity, it -> first) ); // add song to map sorted by popularity
}
it++;
}while(songMatch.compare(0, prefixLength, prefix) == 0); // check if there is anymore songs with prefix
}
playlistChange = false; // update to show changes in playlist database has been taken into account
multimap<int, string>:: iterator iter = songsWithPrefix.end();
for( int count = 0; count < 4 && iter != songsWithPrefix.begin() ; count++){ /*** O(n) where n is 8 ***/
iter--;
cout<< iter -> second<<endl; // print out songs sorted by popularity
}
}
示例13:
/**
* ByteRangeIndex::trunc_map: truncate a C++ index map (low-level helper fn)
*
* @param mymap the map to truncate
* @param nzo non-zero offset to truncate to
*/
void
ByteRangeIndex::trunc_map(map<off_t,ContainerEntry> &mymap, off_t nzo) {
map<off_t,ContainerEntry>::iterator itr, prev;
bool first;
if (mymap.size() == 0) { /* no entries? then nothing to do... */
return;
}
/* use stab query to find first element with offset >= nzo */
itr = mymap.lower_bound(nzo);
first = ( itr == mymap.begin() );
/* remove everything past nzo */
mymap.erase(itr, mymap.end());
/* see if previous entry (if any) needs to be internally truncated */
if (!first) {
prev = itr;
prev--;
if (prev->second.logical_offset + (off_t)prev->second.length > nzo) {
prev->second.length = nzo - prev->second.logical_offset;
}
}
}
示例14: lower_bound
VPtr lower_bound(const K& key) {
VPtr val;
list<VPtr> to_release;
{
Mutex::Locker l(lock);
bool retry = false;
do {
retry = false;
if (weak_refs.empty())
break;
typename map<K, WeakVPtr>::iterator i = weak_refs.lower_bound(key);
if (i == weak_refs.end())
--i;
val = i->second.lock();
if (val) {
lru_add(i->first, val, &to_release);
} else {
retry = true;
}
if (retry)
cond.Wait(lock);
} while (retry);
}
return val;
}
示例15: add
void add(int x,int y)
{
map<int,int>::iterator lb=M.lower_bound(x),i2;
i2=lb;
while (i2!=M.end()&&i2->second>=y)
i2++;
M.erase(lb,i2);
M.insert(pair<int,int>(x,y));
}