本文整理汇总了C++中set::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ set::erase方法的具体用法?C++ set::erase怎么用?C++ set::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类set
的用法示例。
在下文中一共展示了set::erase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addNum
void addNum(int val) {
if (isExist[val]) return;
isExist[val] = true;
int left = val, right = val;
if (leftBound.find(val+1) != leftBound.end()) {
right = leftBound[val+1].end;
interval.erase(leftBound[val+1]);
leftBound.erase(val+1);
rightBound.erase(right);
}
if (rightBound.find(val-1) != rightBound.end()) {
left = rightBound[val-1].start;
interval.erase(rightBound[val-1]);
leftBound.erase(left);
rightBound.erase(val-1);
}
Interval i = Interval(left, right);
interval.insert(i);
leftBound[left] = i;
rightBound[right] = i;
return;
}
示例2: insert_set
void insert_set(ll l, ll r) {
it = S.upper_bound({l, l + r - 1});
elem ra = *it; it--;
elem la = *it;
if(la.y + 1 >= l && ra.x - 1 <= (l + r - 1)) {
set<elem>::iterator temp = it;
printf("%lld %lld\n", la.y + 1, ra.x - 1);
S.erase(++it);
S.erase(temp);
S.insert({la.x, ra.y});
}
else {
if(l <= la.y + 1) {
ll left = la.x, right = la.y + r;
S.erase(it);
printf("%lld %lld\n", la.y + 1, min(right, ra.x - 1));
S.insert({left, min(right, ra.x - 1)});
}
else if((l + r - 1) >= ra.x - 1 ) {
S.erase(++it);
printf("%lld %lld\n", l, ra.x - 1);
S.insert({ l, ra.y });
}
else {
printf("%lld %lld\n", l, l + r - 1);
S.insert({l, l + r - 1});
}
}
}
示例3: check
bool check(int mid)
{
// debug(mid)
st.clear();
repI(i,v.size())st.insert({v[i],i});
queue<pair<ll,int> > q[2];
int cur = 0;
int prv = 1;
repI(i,mid)
{
q[cur].push(*st.begin());
st.erase(*st.begin());
}
示例4: calculate_combinations
void calculate_combinations(set< set < int > >& result,
set< int > stack,
vector< int > target, int offset, int number){
if(number == 0) {
result.insert(stack);
return;
}
for(int i = offset; i <= target.size() - number; i++){
stack.insert(target[i]);
calculate_combinations(result, stack, target, i + 1, number - 1);
stack.erase(target[i]);
}
}
示例5: discoverInstrumentationLevel
void discoverInstrumentationLevel(set<string> & UserFunctions, map<string, vector<string> > & LoopLevels)
{
set<string>::iterator uf_it = UserFunctions.begin();
set<string>::iterator uf_end = UserFunctions.end();
while(uf_it != uf_end)
{
vector<string> tokens;
string uf = *uf_it;
split(tokens, uf, SPLIT_CHAR);
if (tokens.size() > 1)
{
string uf_name = tokens[0]; // [kernel]+loop_1.1,loop_1.2
string bb_part = tokens[1]; // kernel+[loop_1.1,loop_1.2]
tokens.clear();
split(tokens, bb_part, ',');
for(unsigned i=0; i < tokens.size(); i++)
{
LoopLevels[uf_name].push_back(tokens[i]);
}
UserFunctions.erase(uf_it);
UserFunctions.insert(uf_name);
}
uf_it++;
}
uf_it = UserFunctions.begin();
uf_end = UserFunctions.end();
cout<< PACKAGE_NAME": XML functions parsed: ";
while(uf_it != uf_end){
if (LoopLevels.find(*uf_it) != LoopLevels.end())
{
cout<< "\""<<*uf_it<<"\"" <<"->[loops:";
for(unsigned i=0; i < LoopLevels[*uf_it].size(); i++){
cout<<LoopLevels[*uf_it][i]<<",";
}
cout<<"]";
}
else
{
cout<< "\""<<*uf_it<<"\"";
}
set<string>::iterator uf_it_plus_one = uf_it;
uf_it_plus_one++;
if (uf_it_plus_one != uf_end)
{
cout<<";";
} else cout<<endl;
uf_it++;
}
}
示例6: main
int main() {
int i, j, t, ans, now;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &c[i]);
for (j = 0; j < c[i]; j++) {
scanf("%d", &t);
q[i].pb(t);
}
}
scanf("%d", &m);
while (m--) {
scanf("%d %d %d %d", &X, &A, &Y, &B);
X--, Y--;
if (A > c[X]) A = c[X];
if (B > c[Y]) B = c[Y];
hx.clear(), hy.clear();
for (i = 0; i < A; i++) hy.pb(q[X][i]);
for (i = B; i < c[Y]; i++) hy.pb(q[Y][i]);
for (i = 0; i < B; i++) hx.pb(q[Y][i]);
for (i = A; i < c[X]; i++) hx.pb(q[X][i]);
q[X] = hx, q[Y] = hy;
c[X] = hx.size(), c[Y] = hy.size();
// for (i = 0; i < n; i++) {
// cout << "i= " << i << '\n';
// for (j = 0; j < c[i]; j++) cout << q[i][j] << ' ';
// puts("");
// }
// system("pause");
s.clear();
for (i = 0; i < n; i++) {
s.insert(gao(i));
}
ans = now = 0;
while (!s.empty()) {
it = s.begin();
s.erase(it);
if (it->X <= now) now += c[it->Y];
else {
ans += it->X - now;
now = it->X + c[it->Y];
}
}
printf("%d\n", ans);
}
return 0;
}
示例7: toggleSegment
void toggleSegment(int y1, int y2) {
vector<pii> addSegments;
vector<pii> remSegments;
set< pair<bool, pii> >::iterator lb;
// Remove intersection of segment starting BEFORE y1 with (y1, y2)
lb = segments.lower_bound(make_pair(END, make_pair(-y1, -oo)));
for (; lb != segments.end(); lb++) {
int _y1 = -lb->second.first, _y2 = -lb->second.second;
if (_y2 >= y1 && _y1 < y1) {
remSegments.push_back(make_pair(_y1, _y2));
if (_y1 < y1)
addSegments.push_back(make_pair(_y1, y1));
if (y2 < _y2)
addSegments.push_back(make_pair(y2, _y2));
y1 = _y2;
}
break;
}
// Remove intersection of segments starting AFTER y1 with (y1, y2)
lb = segments.lower_bound(make_pair(START, make_pair(y1, -oo)));
for (; lb != segments.end(); lb++) {
if (lb->first != START) break;
int _y1 = lb->second.first, _y2 = lb->second.second;
if (_y1 >= y2) break;
addSegments.push_back(make_pair(y1, _y1));
if (_y2 <= y2) {
remSegments.push_back(make_pair(_y1, _y2));
y1 = _y2;
} else {
remSegments.push_back(make_pair(_y1, _y2));
addSegments.push_back(make_pair(y2, _y2));
y1 = _y2;
}
}
if (y1 < y2)
addSegments.push_back(make_pair(y1, y2));
for (int i = 0; i < remSegments.size(); i++) {
segments.erase(make_pair(START, make_pair(remSegments[i].first, remSegments[i].second)));
segments.erase(make_pair(END, make_pair(-remSegments[i].first, -remSegments[i].second)));
}
for (int i = 0; i < addSegments.size(); i++) {
if (addSegments[i].first != addSegments[i].second) {
segments.insert(make_pair(START, make_pair(addSegments[i].first, addSegments[i].second)));
segments.insert(make_pair(END, make_pair(-addSegments[i].first, -addSegments[i].second)));
}
}
}
示例8: gotObject
virtual void gotObject( const BSONObj& obj ) {
if (_curns == OPLOG_SENTINEL) { // intentional ptr compare
if (obj["op"].valuestr()[0] == 'n') // skip no-ops
return;
// exclude operations that don't meet (timestamp) criteria
if ( _opmatcher.get() && ! _opmatcher->matches ( obj ) ) {
_oplogEntrySkips++;
return;
}
string db = obj["ns"].valuestr();
db = db.substr(0, db.find('.'));
BSONObj cmd = BSON( "applyOps" << BSON_ARRAY( obj ) );
BSONObj out;
conn().runCommand(db, cmd, out);
_oplogEntryApplies++;
// wait for ops to propagate to "w" nodes (doesn't warn if w used without replset)
if (mongoRestoreGlobalParams.w > 0) {
string err = conn().getLastError(db, false, false, mongoRestoreGlobalParams.w);
if (!err.empty()) {
error() << "Error while replaying oplog: " << err;
}
}
}
else if (nsToCollectionSubstring(_curns) == "system.indexes") {
createIndex(obj, true);
}
else if (mongoRestoreGlobalParams.drop &&
nsToCollectionSubstring(_curns) == ".system.users" &&
_users.count(obj["user"].String())) {
// Since system collections can't be dropped, we have to manually
// replace the contents of the system.users collection
BSONObj userMatch = BSON("user" << obj["user"].String());
conn().update(_curns, Query(userMatch), obj);
_users.erase(obj["user"].String());
}
else {
conn().insert( _curns , obj );
// wait for insert to propagate to "w" nodes (doesn't warn if w used without replset)
if (mongoRestoreGlobalParams.w > 0) {
string err = conn().getLastError(_curdb, false, false, mongoRestoreGlobalParams.w);
if (!err.empty()) {
error() << err;
}
}
}
}
示例9: update
void update(set<int>&s , int pos, int col){
if (a[pos]== col){
return ;
}
if (pos == 1){
if (a[pos] == a[pos+1]){
s.insert(2) ; a[pos] = col ; return ;
}
else{
if (col == a[pos+1]){
s.insert(1) ; s.erase(2) ; a[pos] = col ; return ;
}
}
}
if (a[pos-1] == a[pos+1]){
if (a[pos]==a[pos+1]){
s.insert(pos) ; s.insert(pos+1) ; a[pos] = col ; return ;
}
if (a[pos]!=a[pos+1]){
if (col == a[pos+1]){
s.erase(pos) ; s.erase(pos+1) ; a[pos] = col ; return ;
}
}
}
else {
if (a[pos]==a[pos+1]){
if (col != a[pos-1]){
s.insert(pos) ; s.insert(pos+1) ; a[pos] = col ; return ;
}
if (col == a[pos-1]){
s.insert(pos+1) ;s.erase(pos) ; a[pos] = col ; return ;
}
}
if (a[pos] == a[pos-1]){
if (col == a[pos+1]){
s.insert(pos) ; s.erase(pos+1) ; a[pos] = col ; return ;
}
else{
s.insert(pos) ; s.insert(pos+1) ; a[pos] = col ; return ;
}
}
if ((a[pos]!= a[pos-1]) && (a[pos]!= a[pos+1])){
if (col == a[pos-1]){
s.erase(pos) ; s.insert(pos+1) ; a[pos] = col ; return ;
}
if (col == a[pos+1]){
s.erase(pos+1) ; s.insert(pos) ; a[pos] = col ; return ;
}
}
}
}
示例10: remove_set
int remove_set(set<int> my_set) {
double start_time;
double end_time;
double result_time;
start_time = clock();
for (int i = 0; i < my_set.size(); ++i)
my_set.erase(i);
end_time = clock();
result_time = end_time - start_time;
cout << " Remove set: " << result_time / CLOCKS_PER_SEC << "s." << endl;
return 0;
}
示例11: main
int main()
{
int i,b,hh,len;
while(EOF!=scanf("%s",cc))
{
n=0;
hh=1;
len=strlen(cc);
cc[len++]='W';
for(i=0; i<=len; i++)
L[i]=i-1,R[i]=i+1,head[i]=tail[i]=i;
for(i=1; i<len; i++)
{
if(cc[i]==cc[i-1])
hh++;
else
{
++n;
self[n]=num[n]=hh;
color[n]=cc[i-1];
pos[n]=i-hh+1;///偏离量为1
hh=1;
}
}
H.clear();
for(i=1; i<=n; i++)
H.insert(i);
while(!H.empty())
{
it=--H.end();
b=*it;
if(num[b]==1)
break;
H.erase(it);
del(b);
}
}
return 0;
}
示例12: optimize_feedback
void optimize_feedback() {
for(set<uint64_t>::iterator optimize_it =
advertise_hashes.begin();
optimize_it!= advertise_hashes.end(); ){
if(hashes_seen_already.find(*optimize_it) != hashes_seen_already.end()) {
/* hash already seen so remove it*/
advertise_hashes.erase(optimize_it++);
} else {
hashes_seen_already[*optimize_it] = true;
++optimize_it;
}
}
return;
}
示例13: eliminate
void eliminate(set<pair<ull,int>,greater<pair<ull,int> > > & vec){
for(set<pair<ull,int> >::iterator it1=vec.begin();it1!=vec.end();it1++){
int l=it1->second;
ull f=it1->first;
if(l==0){
vec.erase(it1);
break;
}
set<pair<ull,int> >::iterator it2=it1;
it2++;
while(it2!=vec.end() && l==it2->second){
ull temp=f^(it2->first);
vec.erase(it2);
if(temp!=0)
vec.insert(make_pair(temp,length(temp)));
it2=it1;
it2++;
}
}
}
示例14: make_w
void make_w(int pos,int flag){
set<p3>::iterator it = b.lower_bound(p3(pii(pos,0),0));
if(it->second==flag)return;
//cout<<(it==b.end())<<endl;
int from = it->first.second;
int to = it->first.first;
b.erase(it);
if(pos-1>=from)
add(from, pos-1, 1-flag);
add(pos,pos,flag);
if(pos+1<=to)
add(pos+1,to,1-flag);
}
示例15: set_test
void set_test(set<int> a) {
a.erase(1);
return;
StaticVertex* st1 = new StaticVertex("1");
StaticVertex* st2 = new StaticVertex("1");
shared_ptr<StaticVertex> sh1(st1);
shared_ptr<StaticVertex> sh2(st2);
unordered_set<shared_ptr<StaticVertex>, KeyHasher>* s = new unordered_set<shared_ptr<StaticVertex>, KeyHasher>();
s->insert(s->begin(), sh1);
s->insert(s->begin(), sh2);
cout << s->size();
// delete s;
}