首页 > 其他分享 >cpp-inheritance

cpp-inheritance

时间:2022-11-06 18:25:09浏览次数:72  
标签:10 cnt struct inheritance int dsu cpp

如何在 OI 中优雅地使用继承?

posted on 2022-08-12 20:02:40 | under 学术 | source

template<int N> struct dsu{
    int fa[N+10],siz[N+10],cnt;
    dsu(int n=N):cnt(n){for(int i=1;i<=n;i++) fa[i]=i,siz[i]=1;}
    int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
    void merge(int x,int y){if(x=find(x),y=find(y),x!=y) siz[x]<siz[y]&&(swap(x,y),0),cnt--,fa[y]=x,siz[x]+=siz[y];}
};
template<int N> struct exdsu:public dsu<N>{
    int a[N+10];
    dsu<N> &s=*this;//attention!
    exdsu(){memset(a,0,sizeof a);}
    void assign(int l,int r,int k){while(l<=r) if(s.find(l)==l) a[l]=k,s.fa[l]=s.find(l+1); else l=s.find(l);}
    bool remain(int l,int r){return s.find(l)<=r;}
    int operator[](int i){return a[i];}
};

标签:10,cnt,struct,inheritance,int,dsu,cpp
From: https://www.cnblogs.com/caijianhong/p/16863301.html

相关文章

  • cpp 并行编程 pthread 框架 绑定核心运行
    1#include<stdio.h>2#include<math.h>3#include<pthread.h>4#include<stdio.h>5#include<iostream>6#include<stdlib.h>7#include<time.h>......
  • activemq-cpp getCMSType类型判断是否有效
    场景   CMS消息类型有BytesMessage,TextMessage,MapMessage,StreamMessage,是否可以通过getCMSType知道是哪一个类型的消息?答案    不行,依然需要通过constcms::By......
  • cpp基础之二-结构体structure
    数组必须是同一类型type的集合,而结构体则是不同类型type的集合,类似python中的数组结构体的定义//长方形结构体structRectangle{intlength;intwi......
  • c/cpp基础之一:数组array
    在熟悉数组之前,我们先来认识一下在c/cpp中的mainmemory结构是什么样子的(简化版):heap堆stack栈codesection数组的声明与初始化intA[5];//声明int......
  • 高精度HighAccuracy_acwing.cpp
    ​​​ 文章:    力扣模板:字符串相加-字符串相加-力扣(LeetCode)    acwing模板:常用代码模板1——基础算法-AcWing 例题:        P100......
  • Homework 3 : C++ class inheritance Answer
    Homework3:C++classinheritanceAnswerHomework3:C++classinheritanceInstructor:ZhiyaoLiangCIS111&EIE1112021Spring源码传送门传送门:https://pan.ba......
  • VSCode-配置c_cpp环境
    VSCode-配置c_cpp环境mac下VSCode配置cpp环境记录:一.环境macOS:10.14VSCode:1.44.2Xcode:11.3.1(会用到Xcode的工具链,如lldb、clang)二.安装插件编辑、调试C/C++......
  • VScode配置cpp运行调试环境
    1.说明本文基于的操作系统环境为windows10,VScode版本为1.72.2。2.VScode安装及配置在VScode官网(https://code.visualstudio.com)下载安装包,按照提示一路安装下来即可。......
  • Qt利用cpphttp开发http服务器和客户端
    说明:cpphttp一个基于c++11的只有头文件的跨平台 HTTP/HTTPS 库。简单易用,只需要包含头文件 httplib,h 即可。注意:这个库是一个多线程阻塞式 Http 库,如果您需要的是......
  • 实用的C语言IDE——Dev-cpp 安装
    Dev-cpp安装安装包(百度网盘)链接:https://pan.baidu.com/s/1cf8v5uWoZo4TiXJi_XrecA?pwd=yxxx提取码:yxxx 原网站网站可以下载,可能会很慢,但是跟百度网盘比其实大同小异......