板子集
工具-》编译选项-》(建议选择debug)
编译时加入以下命令:
-O2 -Wall -Wextra -Wpedantic
-
-O2:标准优化级别 含义:启用 GCC 推荐的“生产环境”优化级别。
-
-Wall:启用常用警告 含义:启用一组广泛认为有用的编译警告信息(注意:它并不表示“所有”警告)。
-
-Wextra:启用额外警告 含义:开启 -Wall 未覆盖的额外警告信息。
-
-Wpedantic:严格遵循语言标准 含义:强制编译器严格遵循 ISO C/C++ 标准,拒绝任何编译器特定的扩展用法。
在连接器命令行加入以下命令:
-static-libgcc -std=c++14 -Wl,-stack=1234567890
-
-std=c++14 含义:指定编译器使用 C++14 标准进行代码编译。
-
-static-libgcc 含义:强制静态链接 GCC 的底层运行时库(libgcc)。
-
-Wl,-stack=1234567890 的作用是将程序运行时的栈空间大小设置为指定字节数。
:::info[通用]
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define int long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(a) (a>0?a:-a)
using namespace std;
using namespace __gnu_cxx;
const int N=1e6+5;
int t,n,a[N];
rope <int> a;//平衡树,兑
inline int rd(){int x=0;bool f=0;char ch=getchar();while (ch<'0'||ch>'9'){if(ch=='-') f=1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}return f?-x:x;}
inline void wt(int x){if(x<0){x*=-1,putchar('-');}if(x>9){wt(x/10);}putchar(x%10+'0');}
//mt19937 qwq(/*一个整数作为种子*/114514);//定义完之后调用 qwq() 就可以获得一个随机数 qwq。
signed main(){
freopen(".in","r",stdin);
freopen(".out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//如果用手写快读记得把这三行注释了谢谢喵
//多测
cin>>t;
while(t--)solve();
//单测
cin>>n;
}
solution
使用 pb_ds 库中的 rope 解决。
介绍一下 rope
rope 是 pb_ds 库中的一个分支,内部是一个块状链表,支持可持久化。
需要 #include <bits/extc++.h> 和 using namespace __gnu_cxx;。
rope 的使用
可以直接使用 rope <int> a 来声明一个叫做 a 的 rope 。
a.append(x) 可以在 rope 后面添加一个元素
a[x] 可以询问 rope 中下标为
a.insert(x, y) 可以在下标为 |
|---|
| :::info[优先队列] |
| ```cpp |
| priority_queue<int>qwq;//大根堆 |
| priority_queue<int,vector<int>,greater<int>qaq;//小根堆 |
| priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >ovo;//如果均int |
| struct yzc{ |
| int a; |
| bool operator < (const yzc& b)const{ |
| return a<b.a; |
| } |
| /*或 |
| friend bool operator < (yzc a,yzc b)const{ |
| return a.a<b.a; |
| }*/ |
| }; |
| /*或 |
| bool operator <(const yzc& q,const yzc& p){ |
| return a.a<b.a; |
| } |
| */ |
| priority_queue<yzc>qu;//大根堆吧 |
| ``` |
| ::: |
| :::info[最小费用最大流] |
| ```cpp |
| #include<bits/stdc++.h> |
| using namespace std; |
| const int inf=0x7f7f7f7f; |
| int cnt=1,ans,res,head[80005],dis[80005],cur[80005]; |
| bool vis[80005]; |
| int n,m,s,t,liu; |
| struct Node { |
| int nxt,v,liu,c; |
| }node[800100]; |
| inline void add_bian(int u,int v,int liu,int c){ |
| node[++cnt].v=v; |
| node[cnt].liu=liu; |
| node[cnt].nxt=head[u]; |
| node[cnt].c=c; |
| head[u]=cnt; |
| node[++cnt].v=u; |
| node[cnt].liu=0; |
| node[cnt].nxt=head[v]; |
| node[cnt].c=-c; |
| head[v]=cnt; |
| } |
| queue<int>q; |
| int spfa(){ |
| memset(dis,0x7f,sizeof(dis)); |
| q.push(s); |
| dis[s]=0; |
| vis[s]=1; |
| while(!q.empty()){ |
| int u=q.front(); |
| q.pop(),vis[u]=0;cur[u]=head[u]; |
| for(int i=head[u];i;i=node[i].nxt){ |
| int v=node[i].v; |
| if(node[i].liu&&(dis[v]>dis[u]+node[i].c)){ |
| dis[v]=dis[u]+node[i].c; |
| if(!vis[v])q.push(v),vis[v]=1; |
| } |
| } |
| } |
| return dis[t]!=inf; |
| } |
| int dfs(int u,int flow){ |
| if(u==t)return flow; |
| vis[u]=1; |
| int ans=0; |
| for(int i=cur[u];i&&ans<flow;i=node[i].nxt){ |
| int v=node[i].v;cur[u]=i; |
| if(!vis[v]&&node[i].liu&&dis[v]==dis[u]+node[i].c){ |
| int x=dfs(v,min(node[i].liu,flow-ans)); |
| if(x)res+=x*node[i].c,node[i].liu-=x,node[i^1].liu+=x,ans+=x; |
| } |
| } |
| vis[u]=0; |
| return ans; |
| } |
| int Dinic(){ |
| int x; |
| while(spfa()){ |
| while(x=dfs(s,inf))ans+=x; |
| } |
| return ans; |
| } |
| int main(){ |
| ios::sync_with_stdio(0); |
| cin.tie(0); |
| cout.tie(0); |
| int u,v,w,c; |
| cin>>n>>m>>s>>t; |
| for(int i=1;i<=m;i++)cin>>u>>v>>w>>c,add_bian(u,v,w,c),add_bian(v,u,0,-c); |
| cout<<Dinic()<<' '; |
| cout<<res<<'\n'; |
| return 0; |
| } |
:::
:::info[分块]
抓一篇题解。
# 题解:P13981 数列分块入门 6
## solution
使用 pb\_ds 库中的 rope 解决。
### 介绍一下 rope
rope 是 pb\_ds 库中的一个分支,内部是一个块状链表,支持可持久化。
需要 `#include <bits/extc++.h>` 和 `using namespace __gnu_cxx;`。
### rope 的使用
可以直接使用 `rope <int> a` 来声明一个叫做 `a` 的 rope 。
`a.append(x)` 可以在 rope 后面添加一个元素 $x$,类似于 vector 。
`a[x]` 可以询问 rope 中下标为 $x$ 的元素,默认下标从 $0$ 开始。
`a.insert(x, y)` 可以在下标为 $x$ 的位置前插入元素 $y$。
## code
```cpp
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
int n, op, l, r, c;
rope <int> a;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
a.append(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c;
a.append(c);
}
for (int i = 1; i <= n; i++) {
cin >> op;
if (op) {
cin >> c;
cout << a[c] << '\n';
} else {
cin >> l >> r;
a.insert(l, r);
}
}
return 0;
}
::: :::info[提示] :::