首页 > 其他分享 >set.erase()立大功

set.erase()立大功

时间:2024-10-17 21:44:11浏览次数:1  
标签:upper set int wmp hmp 立大功 -- erase del

set.erase(int x)可以将x删除,利用这个特性,可以做到一次性删除
https://atcoder.jp/contests/abc370/tasks/abc370_d

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define lowbit(x) (x&-x)
using namespace std;
const double pi=acos(-1);

void solve(){
    int h,w,q;cin>>h>>w>>q;
    vector<set<int>> hmp(h+1),wmp(w+1);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            hmp[i].insert(j);
            wmp[j].insert(i);
        }
    }

    auto del=[&](int x,int y){
        hmp[x].erase(y);
        wmp[y].erase(x);
    };

    while(q--){
        int x,y;cin>>x>>y;
        x--,y--;
        if(hmp[x].count(y)){
            del(x,y);
            continue;
        }

        if(!hmp[x].empty()){
            auto it=hmp[x].upper_bound(y);
            if(it!=hmp[x].end()) del(x,*it);
            if(!hmp[x].empty()){
                it=hmp[x].upper_bound(y);
                if(it!=hmp[x].begin()){
                    it--;del(x,*it);
                }
            }
        }

        if(!wmp[y].empty()){
            auto it=wmp[y].upper_bound(x);
            if(it!=wmp[y].end()) del(*it,y);

            if(!wmp[y].empty()){
                it=wmp[y].upper_bound(x);
                if(it!=wmp[y].begin()){
                    it--;del(*it,y);
                }
            }

        }
    }
    int ans=0;

    for(int i=0;i<h;i++){
        ans+=hmp[i].size();
    }

    cout<<ans<<endl;
}
signed main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}

标签:upper,set,int,wmp,hmp,立大功,--,erase,del
From: https://www.cnblogs.com/TaopiTTT/p/18473176

相关文章

  • java_day14_HashSet、TreeSet、增强for循环、Map、HashMap、TreeMap、可变参数
    一、HashSetSet:HashSet:底层数据结构是哈希表,查找速度快,且元素唯一HashSet中的add方法实际上调用的是HashMap中的put方法底层和元素的hashCode方法值有关我们发现,底层判断待插入的元素是否已经存在哈希表中的方式是:将待插入的元素的哈希值与已经存......
  • LangGraph 源码分析 | BaseTool 模板类
    文章目录BaseTool源码分析核心属性以`TavilySearchResults(BaseTool)`为例namedescriptionargs_schemaresponse_format查询选项属性需要子类实现的抽象方法以`TavilySearchResults(BaseTool)`为例核心方法`arun()`:`run()`的异步执行版本`invoke()`和`ainvoke()`......
  • weakmap、weakset、内存泄漏
    weakmap、weakset都是ES6的新增的数据结构WeakMapWeakMap对象是键值对的集合,提供了一种键值对的存储机制。它的键必须是对象类型,值可以是任意类型。它的键被弱保持,也就是说,当其键所指对象没有其他地方引用的时候,它会被GC回收掉。WeakMap提供的接口与Map相同。与Map......
  • Set集合的直接子类TreeSet
    一、TreeSet:底层数据结构是红黑树(自平衡二叉树),具备了可预测的排序1.自然排序通过实现comparable接口,重写里面的compareTo方法来进行排序1.编写一个Dog类,实现了Comparable接口,并重写里面的方法publicclassDogimplementsComparable<Dog>{privateStringname;pri......
  • Set集合具体实现子类HashSet的子类LinkedHashSet
    一、LinkedHashSet集合的特点:底层数据结构是哈希表和双链表。哈希表保证元素唯一,双链表保证元素有序,元素唯一二、LinkedHashSet集合的使用场景他保持了HashSet集合的特点,所以当我们传入一个对象想要进行去重的时候需要重写里面的hashCode方法和equals方法。publicclassLinke......
  • Set集合的具体子类:HashSet
    一、HashSet的特点:底层数据结构是哈希表,查找速度快,且元素唯一二、HashSet的使用特点:1.向HashSet集合中添加基本数据类型或者String元素的时候会自动去重importjava.util.HashSet;publicclassHashSetDemo1{publicstaticvoidmain(String[]args){//使用......
  • 【C++】C++ STL 树形结构容器全解析:map、set、multimap、multiset 的使用与区别
    C++语法相关知识点可以通过点击以下链接进行学习一起加油!命名空间缺省参数与函数重载C++相关特性类和对象-上篇类和对象-中篇类和对象-下篇日期类C/C++内存管理模板初阶String使用String模拟实现Vector使用及其模拟实现List使用及其模拟实现容器适配器Stack与QueuePriority......
  • C++ STL迭代器、resize和reserve区别、map和unordered_map区别,vector和List区别、map
    1.STL迭代器删除元素迭代器失效是指在对容器进行修改时,原有的迭代器可能变得不可用。正确删除元素的方法是使用erase,并返回新的有效迭代器。示例代码#include<iostream>#include<vector>intmain(){  std::vector<int>vec={1,2,3,4,5};  //输出......
  • Idea-Maven的Setting文件盘配置
    目录1.Setting.xml2.Setting.xml选其中之一就行。直接全部复制就行。1.Setting.xml<?xmlversion="1.0"encoding="UTF-8"?><!--LicensedtotheApacheSoftwareFoundation(ASF)underoneormorecontributorlicenseagreements.SeetheNOTI......
  • 3DRealCar: An In-the-wild RGB-D Car Dataset with 360-degree Views
    3DRealCar:AnIn-the-wildRGB-DCarDatasetwith360-degreeViewsDu,XiaobiaoandSun,HaiyangandWang,ShuyunandWu,ZhuojieandSheng,HongweiandYing 来自很多单位,其中企业所在单位是LiAuto项目地址:https://xiaobiaodu.github.io/3drealcar/ gitcode: h......