2019nc#4
题号 | 标题 | 已通过代码 | 题解 | 通过率 | 团队的状态 |
---|---|---|---|---|---|
A | meeting | 点击查看 | 树直径 | 604/2055 | |
B | xor | 点击查看 | 线段树维护线性基交 | 81/861 | 未通过 |
C | sequence | 点击查看 | 单调栈,笛卡尔树 | 479/2755 | |
D | triples I | 点击查看 | 构造 | 464/2974 | |
E | triples II | 点击查看 | 进入讨论 | 35/84 | 未通过 |
F | merge | 点击查看 | splay,FHQ-TREE | 4/37 | |
G | tree | 点击查看 | 进入讨论 | 2/43 | 未通过 |
H | RNGs | 点击查看 | 进入讨论 | 1/66 | 未通过 |
I | string | 点击查看 | 后缀数组,回文树 | 157/677 | |
J | free | 点击查看 | 分层图最短路 | 784/2790 | |
K | number | 点击查看 | dp | 859/3484 |
K
题意
问一个字符串中有多少个连续子串是300的倍数
思路
O(300n)的dp即可
- #include <bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define fi first
- #define se second
- #define debug(x) cerr<<#x << " := " << x << endl;
- #define bug cerr<<"-----------------------"<<endl;
- #define FOR(a, b, c) for(int a = b; a <= c; ++ a)
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> pii;
- typedef pair<ll, ll> pll;
- template<typename T>
- inline T read(T&x){
- x=;int f=;char ch=getchar();
- while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
- while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
- return x=f?-x:x;
- }
- const int inf = 0x3f3f3f3f;
- const ll inff = 0x3f3f3f3f3f3f3f3f;
- const int mod = ;
- /**********showtime************/
- const int maxn = 1e5+;
- ll dp[maxn][];
- char str[maxn];
- int main(){
- scanf("%s", str + );
- int n = strlen(str + );
- // dp[0][0] = 1;
- ll ans = ;
- for(int i=; i<n; i++) {
- int tp = str[i + ] - '';
- for(int j=; j<; j++) {
- // debug(tp);
- dp[i+][(j* + tp) % ] += dp[i][j];
- }
- dp[i+][tp] ++;
- ans += dp[i+][];
- }
- printf("%lld\n", ans);
- return ;
- }
F merge
题意
给定一个1~n的排列,有两种操作,1)对区间 [le,mid]和[mid+1, ri] 进行一次归并排序,2)查询区间第i个位子上的值。
思路
利用fhq_tree。区间分裂操作。
- #pragma GCC optimize(2)
- #pragma GCC optimize(3)
- #pragma GCC optimize(4)
- #include <bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define fi first
- #define se second
- #define debug(x) cerr<<#x << " := " << x << endl;
- #define bug cerr<<"-----------------------"<<endl;
- #define FOR(a, b, c) for(int a = b; a <= c; ++ a)
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> pii;
- typedef pair<ll, ll> pll;
- template<typename T>
- inline T read(T&x){
- x=;int f=;char ch=getchar();
- while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
- while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
- return x=f?-x:x;
- }
- const int inf = 0x3f3f3f3f;
- const ll inff = 0x3f3f3f3f3f3f3f3f;
- const int mod = ;
- /**********showtime************/
- struct fhq_treap {
- static const int N = 1e5 + ;
- struct Node {
- int val, key, lc, rc, sz, mx;
- }tree[N];
- int rt, tot;
- inline void init() {
- rt = tot = ;
- tree[rt].sz = tree[rt].val = tree[rt].lc = tree[rt].rc = ;
- srand(time());
- }
- inline void update(int rt) {
- tree[rt].sz = tree[tree[rt].lc].sz + + tree[tree[rt].rc].sz;
- tree[rt].mx = max(tree[tree[rt].lc].mx,max(tree[rt].val,tree[tree[rt].rc].mx));
- }
- void split_val(int rt, int &a, int &b, int val) {
- if(rt == ) {a = b = ; return ;}
- if(max(tree[rt].val , tree[tree[rt].lc].mx) <= val) {
- a = rt;
- split_val(tree[rt].rc, tree[a].rc, b, val);
- }
- else {
- b = rt;
- split_val(tree[rt].lc, a, tree[b].lc, val);
- }
- update(rt);
- }
- void split_sz(int rt, int &a, int &b, int sz) {
- if(rt == ) {a = b = ; return ;}
- if(tree[tree[rt].lc].sz + > sz) {
- b = rt;
- split_sz(tree[rt].lc, a, tree[b].lc, sz);
- }
- else {
- a = rt;
- split_sz(tree[rt].rc, tree[a].rc, b, sz - - tree[tree[rt].lc].sz);
- }
- update(rt);
- }
- void merge(int &rt, int a, int b) {
- if(a== || b==) {
- rt = a+b;
- return ;
- }
- if(tree[a].key < tree[b].key) {
- rt = a;
- merge(tree[rt].rc, tree[a].rc, b);
- }
- else {
- rt = b;
- merge(tree[rt].lc, a, tree[b].lc);
- }
- update(rt);
- }
- inline int new_node(int val) {
- tree[++tot].sz = ;
- tree[tot].val = val;
- tree[tot].lc = tree[tot].rc = ;
- tree[tot].key = rand();
- tree[tot].mx = val;
- return tot;
- }
- void ins(int &rt, int val) {
- int x = , y = , node = new_node(val);
- merge(rt, rt, node);
- }
- void delete_node(int &rt, int val) {
- int x = , y = , z = ;
- split_val(rt, x, y, val);
- split_val(x, x, z, val-);
- merge(z, tree[z].lc, tree[z].rc);
- merge(x, x, z);
- merge(rt, x, y);
- }
- inline int get_kth(int rt, int k) {
- while(tree[tree[rt].lc].sz+ != k) {
- if(tree[tree[rt].lc].sz >= k) rt = tree[rt].lc;
- else k -= tree[tree[rt].lc].sz+, rt = tree[rt].rc;
- }
- return tree[rt].val;
- }
- int get_rnk(int &rt, int val) {
- int x = , y = ;
- split_val(rt, x, y, val-);
- int tmp = tree[x].sz+;
- merge(rt, x, y);
- return tmp;
- }
- int get_pre(int &rt, int val) {
- int x = , y = ;
- split_val(rt, x, y, val-);
- int tmp = get_kth(x, tree[x].sz);
- merge(rt, x, y);
- return tmp;
- }
- int get_scc(int &rt, int val) {
- int x = , y = ;
- split_val(rt, x, y, val);
- int tmp = get_kth(y, );
- merge(rt, x, y);
- return tmp;
- }
- }t;
- const int maxn = 1e5+;
- int n,m;
- int a[maxn];
- void display(int x) {
- if(t.tree[x].lc) display(t.tree[x].lc);
- if(t.tree[x].rc) display(t.tree[x].rc);
- }
- void solve(int le, int mid ,int ri) {
- int x, y, z;
- t.split_sz(t.rt, x, z, ri);
- t.split_sz(x, x, y, mid);
- int tmp;
- int r = ;
- while(x && y) {
- int p = t.get_kth(x, );
- int q = t.get_kth(y, );
- if(p > q) swap(p, q), swap(x, y);
- t.split_val(x, tmp, x, q);
- t.merge(r,r, tmp);
- }
- t.merge(r, r, x);
- t.merge(r, r, y);
- t.merge(r, r, z);
- t.rt = r;
- }
- int main(){
- t.init();
- scanf("%d%d", &n, &m);
- for(int i=; i<=n; i++) {
- scanf("%d", &a[i]);
- t.ins(t.rt, a[i]);
- }
- while(m--){
- int op; scanf("%d", &op);
- if(op == ) {
- int x; scanf("%d", &x);
- printf("%d\n", t.get_kth(t.rt, x));
- }
- else {
- int le, mid, ri;
- scanf("%d%d%d", &le, &mid, &ri);
- solve(le, mid, ri);
- }
- }
- return ;
- }
- /*
- 5 10
- 3 2 1 5 4
- 1 1 2 5
- */
2019nc#4的更多相关文章
- 2019nc#2
A Eddy Walker 题意 你有n个点(0-n-1),按顺序形成一个环,初始时你在0的位子,你随机顺时针走一步或者逆时针走一步, 一旦你走到一个点后,环上所有点都被经过至少一次后,你就必须停下来 ...
- 2019nc#10
题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Blackjack 点击查看 背包DP 32/109 补好了 B Coffee Chicken 点击查看 进入讨论 738/2992 通过 ...
- 2019nc#9
题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A The power of Fibonacci 点击查看 进入讨论 69/227 未通过 B Quadratic equation 点击查看 ...
- 2019NC#8
题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A All-one Matrices 点击查看 单调栈+前缀和 326/2017 通过 B Beauty Values 点击查看 进入讨论 8 ...
- 2019nc#7
题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A String 点击查看 进入讨论 566/3539 通过 B Irreducible Polynomial 点击查看 规律 730/229 ...
- 2019nc#6
https://ac.nowcoder.com/acm/contest/886#question 题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Garbage Classificatio ...
- 2019nc#5
题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A digits 2 点击查看 1017/2384 通过 B generator 1 点击查看 567/3692 通过 C generato ...
- 2019nc#3
题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Graph Games 点击查看 进入讨论 18/292 未通过 B Crazy Binary String 点击查看 1107/3615 ...
- 2019NC#1
LINK B Integration 题意: 给定$a_1,a_2,...,a_n$, 计算 $$\frac{1}{π}\int_{0}^{\infty}\frac{1}{\prod\limits_{ ...
随机推荐
- es6,@import一直报错 Can't resolve。。
最近在项目中新增了一个按钮组的组件页面,但是在其他页面引入时,一直报错 引入方式:
- 【iOS】Error: Error Domain=PBErrorDomain Code=7 "Cannot connect to pasteboard server
这几天在用 Swift 开发一个简单的键盘扩展,真机调试时遇到了这个问题,详细信息如下: ***[:] Could not save pasteboard named com.apple.UIKit. ...
- Android 开发使用自定义字体
有时候,系统自带的字体并不能满足我们特殊的需求,这时候就需要引用其他的字体了,可以把下载的字体文件放在 assets 目录下. 自定义字体文件不能使用xml代码读取而应该使用java代码: publi ...
- RGB颜色 三者都是0为黑色而255是白色 解释
问题: RGB颜色 都是0为黑色而255是白色 与日常生活的黑色白色差距怎么那么大,(与物理学中的黑色吸收光是否相悖)而且为什么要这样定义呢? 链接:https://www.zhihu.com/que ...
- Linux - 查看端口的占用情况、找出并杀死占用进程的方法
目录 1 lsof查看端口的占用情况 1.1 命令使用示例 1.2 查看某一端口的占用情况 1.3 杀死某个端口的所有进程 2 netstat查看端口占用情况 2.1 命令使用示例 2.2 查看占用某 ...
- Okhttp3 网络请求框架与 Gson
Maven环境 : <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>o ...
- iOS的录屏功能
iOS的录屏功能其实没什么好说的,因为网上的教程很多,但是网上的Demo无一例外几乎都有一个bug,那就是iPad上会出现闪退,这也体现了国内的教程文档的一个特点,就是抄袭,教程几乎千篇一律,bug也 ...
- git常用指令整理
git常用指令一览表 GIT指令 说明 git add . 将全部文件的内容加到Git索引以便执行commit. 这个指令不会检查文件夹中是否有文件被删除. 要注意的是,只有执行" git ...
- red hat enterprise Linux 64 bit 配置IP
在win7 64位操作系统的台式机器上,安装了VMware® Workstation,9.0.1 build-894247.新建一个虚拟机安装linux.具体过程请搜索相关文档.安装的时候选择的网络连 ...
- 虚拟机安装CentOS的简短教程
说明: 为什么要学Linux?因为现在互联网产品普遍使用Linux作为服务器系统. 测试工程师要学Linux吗?要,因为你会需要跟服务器打交道. 什么情况下测试工程师会跟服务器打交道?你可能要去部署测 ...