本文整理汇总了C++中map::upper_bound方法的典型用法代码示例。如果您正苦于以下问题:C++ map::upper_bound方法的具体用法?C++ map::upper_bound怎么用?C++ map::upper_bound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map
的用法示例。
在下文中一共展示了map::upper_bound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
int n,W,H;
while(~scanf("%d%d%d",&n,&W,&H)) {
init();
maxbright = 0;
for(int i = 0;i < n;i ++) {
scanf("%d%d%d",&all[i].x,&all[i].y,&all[i].shine);
mapy[all[i].y] = 0;
}
sort(all,all+n,cmp);
int countf = 0;
for(map<int ,int >::iterator it = mapy.begin();it != mapy.end();it ++) {
countf ++;
it -> second = countf;
}
int i,j ;
i = 0;j= 0;
while(i < n) {
while(all[i].x - all[j].x >= W) {
add(1,countf,1,-all[j].shine,mapy.upper_bound(all[j].y - H) -> second,mapy[all[j].y]);
j ++;
}
add(1,countf,1,all[i].shine,mapy.upper_bound(all[i].y - H) -> second,mapy[all[i].y]);
maxbright = max(maxbright,getMax());
i ++;
}
printf("%d\n",maxbright);
}
}
示例2: solve
long long solve(long long x){
long long res = 0;
int r = 0, l = 0;
queue<STAR> q;
for(int i = 0;i < n;i++){
if(stars[i].second != x)continue;
while(stars[r].first.first < stars[i].first.first - x)r++;
while(l < n && stars[i].first.first >= stars[l].first.first - x) l++;
i = l;
for(;r < l;r++){
if(stars[r].second < x)continue;
q.push(stars[r]);
while(!q.empty() && q.front().first.first < stars[r].first.first - x){
STAR tmp = q.front();q.pop();
map<long long, long long>::iterator it = zahyou.upper_bound(tmp.first.second + x);
add_segtree(zahyou[tmp.first.second], (*--it).second, root, -1);
}
map<long long, long long>::iterator it = zahyou.upper_bound(stars[r].first.second + x);
add_segtree(zahyou[stars[r].first.second], (*--it).second, root, 1);
res = max(res, root -> all + root -> maximum);
}
r = i;
}
while(!q.empty()){
STAR tmp = q.front();q.pop();
map<long long, long long>::iterator it = zahyou.upper_bound(tmp.first.second + x);
add_segtree(zahyou[tmp.first.second], (*--it).second, root, -1);
}
return res;
}
示例3: 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;
}
示例4: main
int main()
{
int T;
cin >> T;
while(T--)
{
cin >> N;
init();
M.clear();
for(int t = 0; t < N; t++)
{
int x;
scanf("%d", &x);
//printf("input %d\n", x);
//for(map<int, int>::iterator it = M.begin(); it != M.end(); it++)
//printf("%d ", it->first);
//cout << endl;
map<int, int>::iterator it = M.upper_bound(x + 1);
if(it == M.begin())
{
int i = insert(x, -1, head);
M[x] = i;
}
else
{
it--;
int i = insert(x, it->second, list[it->second][2]);
if(it->first == x + 1) M.erase(it);
M[x] = i;
}
//print();
}
print();
}
}
示例5: addNum
void addNum(int val)
{
if (intervals_.empty()) {
intervals_[val] = val;
return;
}
auto ub = intervals_.upper_bound(val);
if (ub == intervals_.begin()) {
if (ub->first - 1 == val) {
intervals_[val] = ub->second;
intervals_.erase(ub);
} else
intervals_[val] = val;
} else {
auto p = prev(ub);
if (ub == intervals_.end() || ub->first - 1 > val) {
if (p->second + 1 < val)
intervals_[val] = val;
else if (p->second + 1 == val)
p->second = val;
} else {
if (p->second + 1 < val)
intervals_[val] = ub->second;
else if (p->second + 1 == val)
p->second = ub->second;
intervals_.erase(ub);
}
}
}
示例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:
string
find_symbol (int addr)
{
map<uint16_t,string>::iterator mi;
mi = exports.upper_bound(addr);
if (exports.empty() || mi == exports.begin())
{
std::stringstream ss;
ss << '$' << std::hex << addr;
return ss.str();
}
else
{
mi--;
if (mi->first == addr)
return mi->second;
else
{
std::stringstream ss;
ss << mi->second << "+" << addr - mi->first;
return ss.str();
}
}
}
示例8: get_value
/* This function returns the minimum/maximum value at x. */
double get_value(double x)
{
map<double, Line>::iterator it = query_set.upper_bound(x);
it--;
return x*it->s.m + it->s.c;
}
示例9: f
string f (int x) {
auto up = mapa.upper_bound(x);
up --;
int key = up -> first;
if (key == x) return mapa[x];
return mapa[key] + f(x - key);
}
示例10: canInsert
bool canInsert(int p, int q)
{
auto upper = nerds.upper_bound(p);
if (upper == nerds.end()) return true;
return upper->second <= q;
}
示例11: main
int main() {
int q;
cin >> q;
char c;
int x, l, h, t, b;
while (q--) {
// cin >> c >> x;
scanf(" %c %d", &c, &x); // faster than cin
if (c == '+') {
hmap[x]++;
} else if (c == '-'){
hmap[x]--;
if (hmap[x] == 0)
hmap.erase(x);
} else { // find max value
l = 0;
h = ((ll)1 << 31) - 1;
t = h ^ x; // this is the target we want to find in A
for (int i = 30; i >= 0; i--) {
b = t & (1 << i);
if (b) { // i th target bit is 1
h = h | (1 << i);
l = l | (1 << i);
if (hmap.lower_bound(l) == hmap.upper_bound(h)) { // no value between l and h
// reverse
h = h & (~(1 << i));
l = l & (~(1 << i));
}
} else {
h = h & (~(1 << i));
l = l & (~(1 << i));
if (hmap.lower_bound(l) == hmap.upper_bound(h)) { // no value between l and h
h = h | (1 << i);
l = l | (1 << i);
}
}
}
cout << max(x, l^x) << endl;
}
}
return 0;
}
示例12: main
int main(){
scanf("%d %d",&n,&m);
low.insert(0);
low.insert(n);
high.insert(n);
high.insert(2*n);
for(int i=0; i<m; i++){
char b[5];
int x, y;
scanf("%s %d %d",b,&x,&y);
if(*b == 'B'){
if(x > y) swap(x, y);
if(y <= n){
low.insert(x);
}
else{
high.insert(x);
}
}
if(*b == 'Q'){
if((x-1) / n == (y-1) / n){
if(x <= n && x > y){
auto u = mp1.lower_bound(x);
auto v = low.lower_bound(x);
if(u == mp1.end() || (v != low.end() && *v < u->first)) puts("NE");
else move(u->second, y);
}
else if(x <= n && x <= y){
auto t = low.lower_bound(x);
puts(y <= *t ? "DA" : "NE");
}
else if(x > n && x >= y){
auto t = --high.lower_bound(x);
puts(*t+1 <= y ? "DA" : "NE");
}
else{
auto u = mp2.upper_bound(x);
auto v = high.lower_bound(x);
if(u == mp2.begin()) puts("NE");
else{
u--;
if(v != high.begin() && *--v >= u->first){
puts("NE");
}
else move(u->second, y);
}
}
}
else move(x, y);
}
if(*b == 'A'){
if(x > y) swap(x, y);
ins(x, y);
}
}
}
示例13: 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;
}
示例14: get
struct Node* get(size_t key){
struct Node* getNode;
map<size_t, struct Node*>::iterator it = consistentHash.upper_bound(key);
if (it == consistentHash.end()){
getNode = consistentHash.begin()->second;
}
else{
getNode = it->second;
}
return getNode;
}
示例15: gao
bool gao()
{
int a,b;
map<int,int>::iterator it;
scanf("%d%d",&a,&b);
it=mp0.lower_bound(a);
if(b<it->second) return 0;
it=mp1.upper_bound(a);
--it;
if(b>it->second) return 0;
return 1;
}