题号 标题 已通过代码 题解 通过率 团队的状态
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即可

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define pb push_back
  5. #define fi first
  6. #define se second
  7. #define debug(x) cerr<<#x << " := " << x << endl;
  8. #define bug cerr<<"-----------------------"<<endl;
  9. #define FOR(a, b, c) for(int a = b; a <= c; ++ a)
  10.  
  11. typedef long long ll;
  12. typedef long double ld;
  13. typedef pair<int, int> pii;
  14. typedef pair<ll, ll> pll;
  15.  
  16. template<typename T>
  17. inline T read(T&x){
  18. x=;int f=;char ch=getchar();
  19. while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
  20. while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
  21. return x=f?-x:x;
  22. }
  23.  
  24. const int inf = 0x3f3f3f3f;
  25. const ll inff = 0x3f3f3f3f3f3f3f3f;
  26. const int mod = ;
  27.  
  28. /**********showtime************/
  29. const int maxn = 1e5+;
  30. ll dp[maxn][];
  31. char str[maxn];
  32. int main(){
  33. scanf("%s", str + );
  34. int n = strlen(str + );
  35. // dp[0][0] = 1;
  36. ll ans = ;
  37. for(int i=; i<n; i++) {
  38. int tp = str[i + ] - '';
  39. for(int j=; j<; j++) {
  40. // debug(tp);
  41. dp[i+][(j* + tp) % ] += dp[i][j];
  42. }
  43. dp[i+][tp] ++;
  44. ans += dp[i+][];
  45. }
  46. printf("%lld\n", ans);
  47. return ;
  48. }

F merge

题意

给定一个1~n的排列,有两种操作,1)对区间 [le,mid]和[mid+1, ri] 进行一次归并排序,2)查询区间第i个位子上的值。

思路

利用fhq_tree。区间分裂操作。

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include <bits/stdc++.h>
  5.  
  6. using namespace std;
  7. #define pb push_back
  8. #define fi first
  9. #define se second
  10. #define debug(x) cerr<<#x << " := " << x << endl;
  11. #define bug cerr<<"-----------------------"<<endl;
  12. #define FOR(a, b, c) for(int a = b; a <= c; ++ a)
  13.  
  14. typedef long long ll;
  15. typedef long double ld;
  16. typedef pair<int, int> pii;
  17. typedef pair<ll, ll> pll;
  18.  
  19. template<typename T>
  20. inline T read(T&x){
  21. x=;int f=;char ch=getchar();
  22. while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
  23. while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
  24. return x=f?-x:x;
  25. }
  26.  
  27. const int inf = 0x3f3f3f3f;
  28. const ll inff = 0x3f3f3f3f3f3f3f3f;
  29. const int mod = ;
  30.  
  31. /**********showtime************/
  32.  
  33. struct fhq_treap {
  34. static const int N = 1e5 + ;
  35. struct Node {
  36. int val, key, lc, rc, sz, mx;
  37. }tree[N];
  38. int rt, tot;
  39. inline void init() {
  40. rt = tot = ;
  41. tree[rt].sz = tree[rt].val = tree[rt].lc = tree[rt].rc = ;
  42. srand(time());
  43. }
  44. inline void update(int rt) {
  45. tree[rt].sz = tree[tree[rt].lc].sz + + tree[tree[rt].rc].sz;
  46. tree[rt].mx = max(tree[tree[rt].lc].mx,max(tree[rt].val,tree[tree[rt].rc].mx));
  47. }
  48.  
  49. void split_val(int rt, int &a, int &b, int val) {
  50. if(rt == ) {a = b = ; return ;}
  51. if(max(tree[rt].val , tree[tree[rt].lc].mx) <= val) {
  52. a = rt;
  53. split_val(tree[rt].rc, tree[a].rc, b, val);
  54. }
  55. else {
  56. b = rt;
  57. split_val(tree[rt].lc, a, tree[b].lc, val);
  58. }
  59. update(rt);
  60. }
  61. void split_sz(int rt, int &a, int &b, int sz) {
  62. if(rt == ) {a = b = ; return ;}
  63. if(tree[tree[rt].lc].sz + > sz) {
  64. b = rt;
  65. split_sz(tree[rt].lc, a, tree[b].lc, sz);
  66. }
  67. else {
  68. a = rt;
  69. split_sz(tree[rt].rc, tree[a].rc, b, sz - - tree[tree[rt].lc].sz);
  70. }
  71. update(rt);
  72. }
  73.  
  74. void merge(int &rt, int a, int b) {
  75. if(a== || b==) {
  76. rt = a+b;
  77. return ;
  78. }
  79. if(tree[a].key < tree[b].key) {
  80. rt = a;
  81. merge(tree[rt].rc, tree[a].rc, b);
  82. }
  83. else {
  84. rt = b;
  85. merge(tree[rt].lc, a, tree[b].lc);
  86. }
  87. update(rt);
  88. }
  89.  
  90. inline int new_node(int val) {
  91. tree[++tot].sz = ;
  92. tree[tot].val = val;
  93. tree[tot].lc = tree[tot].rc = ;
  94. tree[tot].key = rand();
  95. tree[tot].mx = val;
  96. return tot;
  97. }
  98.  
  99. void ins(int &rt, int val) {
  100. int x = , y = , node = new_node(val);
  101. merge(rt, rt, node);
  102. }
  103. void delete_node(int &rt, int val) {
  104. int x = , y = , z = ;
  105. split_val(rt, x, y, val);
  106. split_val(x, x, z, val-);
  107. merge(z, tree[z].lc, tree[z].rc);
  108. merge(x, x, z);
  109. merge(rt, x, y);
  110. }
  111. inline int get_kth(int rt, int k) {
  112. while(tree[tree[rt].lc].sz+ != k) {
  113. if(tree[tree[rt].lc].sz >= k) rt = tree[rt].lc;
  114. else k -= tree[tree[rt].lc].sz+, rt = tree[rt].rc;
  115. }
  116. return tree[rt].val;
  117. }
  118. int get_rnk(int &rt, int val) {
  119. int x = , y = ;
  120. split_val(rt, x, y, val-);
  121. int tmp = tree[x].sz+;
  122. merge(rt, x, y);
  123. return tmp;
  124. }
  125. int get_pre(int &rt, int val) {
  126. int x = , y = ;
  127. split_val(rt, x, y, val-);
  128. int tmp = get_kth(x, tree[x].sz);
  129. merge(rt, x, y);
  130. return tmp;
  131. }
  132. int get_scc(int &rt, int val) {
  133. int x = , y = ;
  134. split_val(rt, x, y, val);
  135. int tmp = get_kth(y, );
  136. merge(rt, x, y);
  137. return tmp;
  138. }
  139. }t;
  140.  
  141. const int maxn = 1e5+;
  142. int n,m;
  143. int a[maxn];
  144. void display(int x) {
  145. if(t.tree[x].lc) display(t.tree[x].lc);
  146. if(t.tree[x].rc) display(t.tree[x].rc);
  147. }
  148. void solve(int le, int mid ,int ri) {
  149. int x, y, z;
  150. t.split_sz(t.rt, x, z, ri);
  151. t.split_sz(x, x, y, mid);
  152.  
  153. int tmp;
  154. int r = ;
  155. while(x && y) {
  156. int p = t.get_kth(x, );
  157. int q = t.get_kth(y, );
  158.  
  159. if(p > q) swap(p, q), swap(x, y);
  160. t.split_val(x, tmp, x, q);
  161. t.merge(r,r, tmp);
  162. }
  163. t.merge(r, r, x);
  164. t.merge(r, r, y);
  165. t.merge(r, r, z);
  166. t.rt = r;
  167. }
  168. int main(){
  169. t.init();
  170. scanf("%d%d", &n, &m);
  171. for(int i=; i<=n; i++) {
  172. scanf("%d", &a[i]);
  173. t.ins(t.rt, a[i]);
  174. }
  175. while(m--){
  176. int op; scanf("%d", &op);
  177. if(op == ) {
  178. int x; scanf("%d", &x);
  179. printf("%d\n", t.get_kth(t.rt, x));
  180. }
  181. else {
  182. int le, mid, ri;
  183. scanf("%d%d%d", &le, &mid, &ri);
  184. solve(le, mid, ri);
  185. }
  186. }
  187. return ;
  188. }
  189.  
  190. /*
  191. 5 10
  192. 3 2 1 5 4
  193. 1 1 2 5
  194.  
  195. */

2019nc#4的更多相关文章

  1. 2019nc#2

    A Eddy Walker 题意 你有n个点(0-n-1),按顺序形成一个环,初始时你在0的位子,你随机顺时针走一步或者逆时针走一步, 一旦你走到一个点后,环上所有点都被经过至少一次后,你就必须停下来 ...

  2. 2019nc#10

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Blackjack 点击查看 背包DP 32/109 补好了 B Coffee Chicken 点击查看 进入讨论 738/2992  通过 ...

  3. 2019nc#9

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A The power of Fibonacci 点击查看 进入讨论 69/227 未通过 B Quadratic equation 点击查看 ...

  4. 2019NC#8

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A All-one Matrices 点击查看 单调栈+前缀和 326/2017  通过 B Beauty Values 点击查看 进入讨论 8 ...

  5. 2019nc#7

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A String 点击查看 进入讨论 566/3539  通过 B Irreducible Polynomial 点击查看 规律 730/229 ...

  6. 2019nc#6

    https://ac.nowcoder.com/acm/contest/886#question 题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Garbage Classificatio ...

  7. 2019nc#5

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A digits 2 点击查看 1017/2384  通过 B generator 1 点击查看 567/3692  通过 C generato ...

  8. 2019nc#3

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Graph Games 点击查看 进入讨论 18/292 未通过 B Crazy Binary String 点击查看 1107/3615 ...

  9. 2019NC#1

    LINK B Integration 题意: 给定$a_1,a_2,...,a_n$, 计算 $$\frac{1}{π}\int_{0}^{\infty}\frac{1}{\prod\limits_{ ...

随机推荐

  1. es6,@import一直报错 Can't resolve。。

    最近在项目中新增了一个按钮组的组件页面,但是在其他页面引入时,一直报错 引入方式:

  2. 【iOS】Error: Error Domain=PBErrorDomain Code=7 "Cannot connect to pasteboard server

    这几天在用 Swift 开发一个简单的键盘扩展,真机调试时遇到了这个问题,详细信息如下: ***[:] Could not save pasteboard named com.apple.UIKit. ...

  3. Android 开发使用自定义字体

    有时候,系统自带的字体并不能满足我们特殊的需求,这时候就需要引用其他的字体了,可以把下载的字体文件放在 assets 目录下. 自定义字体文件不能使用xml代码读取而应该使用java代码: publi ...

  4. RGB颜色 三者都是0为黑色而255是白色 解释

    问题: RGB颜色 都是0为黑色而255是白色 与日常生活的黑色白色差距怎么那么大,(与物理学中的黑色吸收光是否相悖)而且为什么要这样定义呢? 链接:https://www.zhihu.com/que ...

  5. Linux - 查看端口的占用情况、找出并杀死占用进程的方法

    目录 1 lsof查看端口的占用情况 1.1 命令使用示例 1.2 查看某一端口的占用情况 1.3 杀死某个端口的所有进程 2 netstat查看端口占用情况 2.1 命令使用示例 2.2 查看占用某 ...

  6. Okhttp3 网络请求框架与 Gson

    Maven环境 : <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>o ...

  7. iOS的录屏功能

    iOS的录屏功能其实没什么好说的,因为网上的教程很多,但是网上的Demo无一例外几乎都有一个bug,那就是iPad上会出现闪退,这也体现了国内的教程文档的一个特点,就是抄袭,教程几乎千篇一律,bug也 ...

  8. git常用指令整理

    git常用指令一览表 GIT指令 说明 git add . 将全部文件的内容加到Git索引以便执行commit. 这个指令不会检查文件夹中是否有文件被删除. 要注意的是,只有执行" git ...

  9. red hat enterprise Linux 64 bit 配置IP

    在win7 64位操作系统的台式机器上,安装了VMware® Workstation,9.0.1 build-894247.新建一个虚拟机安装linux.具体过程请搜索相关文档.安装的时候选择的网络连 ...

  10. 虚拟机安装CentOS的简短教程

    说明: 为什么要学Linux?因为现在互联网产品普遍使用Linux作为服务器系统. 测试工程师要学Linux吗?要,因为你会需要跟服务器打交道. 什么情况下测试工程师会跟服务器打交道?你可能要去部署测 ...