I love PPP!!!
PPP的博客
edge
// /// //// //// ||
// / /// / /// / /// ||||
// / /// / /// / /// ||||
// / /// / /// / /// ||||
// /// /// /// ||||
// / / / ||||
// / / / ||
// / / /
// / / / ||
// / / / ||||
// / / / ||
二叉堆(多类型,可传比较函数版):
template<typename T,typename Comp=less<T>>
struct heap{
vector<T>tree{1};
int n=0;
Comp comp;
heap(Comp cmp=Comp{}):comp(cmp){}
T top(){return tree[1];}
long long heap_size(){retern n;}
void push(T x){
n++;
tree.push_back(x);
int pthis=n,parent=n/2;
while(parent>=1&&comp(tree[pthis],tree[parent])){
swap(tree[pthis], tree[parent]);
pthis=parent;
parent/=2;
}
}void pop(){
swap(tree[1],tree[n]);
tree.pop_back();
n--;
int pthis=1;
while(pthis*2<=n){
int left=pthis*2,right=pthis*2+1,minchild=left;
if(right<=n&&comp(tree[right],tree[left]))minchild=right;
if(comp(tree[minchild],tree[pthis])){
swap(tree[pthis],tree[minchild]);
pthis=minchild;
}else break;
}
}
};
big_int
#include<bits/stdc++.h>
using namespace std;
struct big_int{
const int jw=100;
vector<short>str;
int size;
big_int():str(2,0),size(1){}
big_int(vector<short>s,int sz):str(s),size(sz){}
big_int(const big_int& x):str(x.str),size(x.size){}
big_int operator-(const big_int x)const{
int newsize=max(size,x.size);
vector<short>pnew(newsize+1,0);
pnew[0]=pnew[1]=0;
for(int i=1;i<=newsize;i++){
if(i<=size)pnew[i]=str[i];
if(i<=x.size)pnew[i]-=x.str[i];
}
for(int i=1;i<newsize;i++){
if(pnew[i]<0){
pnew[i+1]-=1;
pnew[i]+=jw;
}
}
for(int i=newsize;i>0;i--){
if(pnew[i]==0)newsize--;
else break;
}
return big_int{pnew,newsize};
}
big_int operator+(const big_int x)const{
int newsize=max(size,x.size);
vector<short>pnew(newsize+2,0);
pnew[0]=pnew[1]=0;
for(int i=1;i<=newsize;i++){
if(i<=size)pnew[i]=str[i];
if(i<=x.size)pnew[i]+=x.str[i];
}
for(int i=1;i<=newsize;i++){
if(pnew[i]>=jw){
pnew[i+1]+=pnew[i]/jw;
pnew[i]%=jw;
}
}if(!pnew[newsize+1])pnew.pop_back();
return big_int{pnew,newsize};
}
bool operator>(const big_int x)const{
if(size>x.size)return true;
if(size<x.size)return false;
for(int i=size;i>1;i--){
if(str[i]!=x.str[i])return str[i]>x.str[i];
}return str[1]>x.str[1];
}
friend ostream& operator<<(ostream& os,const big_int& num);
friend istream& operator>>(istream& is,big_int& num);
};
ostream& operator<<(ostream& os, const big_int& num) {
for(int i=num.size;i>=1;i--){
if(i==num.size)os<<num.str[i];
else os<<setw(2)<<setfill('0')<<num.str[i];
}
return os;
}
istream& operator>>(istream& is, big_int& num){
string input;
is>>input;
num.str.clear();
num.str.resize(2,0);
int len=input.length();
num.size=(len + 1)/2;
num.str.resize(num.size+2,0);
for(int i=0;i<len;++i) {
int pos=(len-1-i)/2+1;
num.str[pos]=num.str[pos]*10+(input[i]-'0');
}
return is;
}
int main(){
big_int a,b;
cin>>a>>b;
cout<<"\n\n"<<a+b;
return 0;
}
线段树:
#include <vector>
using namespace std;
template<typename T>
struct SegmentTree{
struct Node{
int l,r;
T sum=0,lazy=0;
};
vector<Node>tree;
vector<T>arr;
int n;
SegmentTree(vector<T>&data){
n=data.size()-1;
arr=data;
tree.resize(n*4);
build(1,1,n);
}void build(int node,int l,int r){
tree[node].l=l;
tree[node].r=r;
tree[node].lazy=0;
if(l==r){
tree[node].sum=arr[l];
return;
}
int mid=(l+r)/2;
build(node*2,l,mid);
build(node*2+1,mid+1,r);
push_up(node);
}void push_up(int node){tree[node].sum=tree[node*2].sum+tree[node*2+1].sum;}
void push_down(int node){
if(tree[node].lazy){
int left=node*2,right=node*2+1;
T k=tree[node].lazy;
tree[left].sum+=k*(tree[left].r-tree[left].l+1);
tree[right].sum+=k*(tree[right].r-tree[right].l+1);
tree[left].lazy+=k;
tree[right].lazy+=k;
tree[node].lazy=0;
}
}void update(int l,int r,T k){_update(1,l,r,k);}
void _update(int node,int l,int r,T k){
if (tree[node].l>=l&&tree[node].r<=r){
tree[node].sum+=k*(tree[node].r-tree[node].l+1);
tree[node].lazy+=k;
return;
}
push_down(node);
int mid=(tree[node].l+tree[node].r)/2;
if (l<=mid)_update(node*2,l,r,k);
if (r>mid)_update(node*2+1,l,r,k);
push_up(node);
}T query(int l,int r){return _query(1,l,r);}
T _query(int node,int l,int r){
if(tree[node].l>=l&&tree[node].r<=r)return tree[node].sum;
push_down(node);
T res=0;
int mid=(tree[node].l+tree[node].r)/2;
if(l<=mid)res+=_query(node*2,l,r);
if(r>mid)res+=_query(node*2+1,l,r);
return res;
}
};
上传图片
1.网页版红警:ra2web.com
2.假装Windows升级 :FakeUpdate.net
3.亿图脑图:https://sourl.cn/dDACUE
4.国家职业教育智慧平台:https://vocational.smartedu.cn/
5.表情包融合:https://tikolu.net/emojimix/
image.anosu.top/pixiv?keyword=bluearchive
https://t.mwm.moe/pc?json."url"