B

题意

给一个字符串, 可以把第一个字母移到最后, 也可以把最后一个字母放第一个, 问字典序最大最小的字符串。

题解

把第一个放最后一个, 相当于把最后一个放第一个执行n-1次, 那么我们不妨只进行第一步操作, 把所有的结果都算出来, 排序即可; 注:提取string的子串方法:a.substr(i, j); 从第i位开始, 长度为j的字符串(开头是0);

D

题意

构造一个n的全排列, 使\(a_i\)在\(b_i\)前面;

题解

非常简单, 建边判环即可, 判环和记录答案都可以用topsort, 不过统计答案的时候要用堆优化, 应该可以写到一个函数里面

代码
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int INF = 0x3f3f3f3f;
  5. const int N = 2e5 + 10;
  6. const int M = 5e3 + 10;
  7. const int eps = 1e-6;
  8. template < typename T > inline void read(T &x) {
  9. x = 0; T ff = 1, ch = getchar();
  10. while (!isdigit(ch)) {
  11. if (ch == '-') ff = -1;
  12. ch = getchar();
  13. }
  14. while (isdigit(ch)) {
  15. x = (x << 1) + (x << 3) + (ch ^ 48);
  16. ch = getchar();
  17. }
  18. x *= ff;
  19. }
  20. int n, m, c[N], du[N], vi[N];
  21. map < int, int > p[N];
  22. vector < int > v[N], a;
  23. inline bool topsort() {
  24. queue < int > q;
  25. for (int i = 1; i <= n; ++i)
  26. if (c[i] == 0) q.push(i);
  27. while (!q.empty()) {
  28. int x = q.front();
  29. q.pop();
  30. for (int i = 0; i < v[x].size(); ++i) {
  31. int y = v[x][i];
  32. --c[y];
  33. if (c[y] == 0) q.push(y);
  34. }
  35. }
  36. for (int i = 1; i <= n; ++i)
  37. if (c[i]) return false;
  38. return true;
  39. }
  40. inline void solve() {
  41. priority_queue < int > q;
  42. for (int i = 1; i <= n; ++i)
  43. if (du[i] == 0) q.push(-i);
  44. while (!q.empty()) {
  45. int x = -q.top();
  46. q.pop();
  47. a.push_back(x);
  48. for (int i = 0; i < v[x].size(); ++i) {
  49. int y = v[x][i];
  50. --du[y];
  51. if (du[y] == 0) q.push(-y);
  52. }
  53. }
  54. for (int i = 0; i < n; ++i) printf("%d ", a[i]);
  55. }
  56. int main() {
  57. read(n), read(m);
  58. for (int i = 1; i <= m; ++i) {
  59. int x, y;
  60. read(x), read(y);
  61. if (p[x][y]) continue;
  62. p[x][y] = true;
  63. v[x].push_back(y);
  64. ++du[y];
  65. ++c[y];
  66. }
  67. if (!topsort()) puts("-1");
  68. else solve();
  69. return 0;
  70. }

E

题意

题目不是很好理解, 有个x*y的网格, 要放入三个面积不小于a, b, c且边长都为整数的矩形, 判断是否成立。

题解

当有两个矩形的时候, 存在一条线, 把两个矩形分开。 当三个矩形的时候, 存在一条线, 分成一边一个矩形,一边两个矩形。 那我们就枚举这个矩形,在枚举x或y,使这条边充分利用, 算出len=\(\lceil\frac{S}{x}\rceil\), 或 len=\(\lceil\frac{S}{y}\rceil\), 从而把边长减去len, 转换成两个矩形的问题, 同上

代码
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int INF = 0x3f3f3f3f;
  5. const int N = 2e5 + 10;
  6. const int M = 5e3 + 10;
  7. const int eps = 1e-6;
  8. template < typename T > inline void read(T &x) {
  9. x = 0; T ff = 1, ch = getchar();
  10. while (!isdigit(ch)) {
  11. if (ch == '-') ff = -1;
  12. ch = getchar();
  13. }
  14. while (isdigit(ch)) {
  15. x = (x << 1) + (x << 3) + (ch ^ 48);
  16. ch = getchar();
  17. }
  18. x *= ff;
  19. }
  20. ll n, m, a, b, c;
  21. inline bool solve2(ll x, ll y, ll u, ll v) {
  22. for (int i = 0; i < 2; ++i) {
  23. ll len = (u + x - 1) / x;
  24. if (len < y && x * (y - len) >= v) return true;
  25. swap(x, y);
  26. }
  27. return false;
  28. }
  29. inline bool solve3(ll x, ll y, ll u, ll v, ll w) {
  30. for (int i = 0; i < 2; ++i) {
  31. for (int j = 0; j < 3; ++j) {
  32. ll len = (u + x - 1) / x;
  33. if (len < y && solve2(x, y - len, v, w)) return true;
  34. swap(u, v);
  35. swap(v, w);
  36. }
  37. swap(x, y);
  38. }
  39. return false;
  40. }
  41. int main() {
  42. read(n), read(m), read(a), read(b), read(c);
  43. puts(solve3(n, m, a, b, c) ? "Yes" : "No");
  44. return 0;
  45. }

F

在看这道题之前, 我们先引入一道题

题目

我们再引入一个题解

题解

题解是链上的做法, 引申到树上即可.(吐槽一波, csp我竟然看错题了)

上题



题目的意思是, 有一个长度为n的括号序列, 有两个操作, 一是交换l, r的括号, 二是求l到r之间是不是完美匹配. 有了上面的铺垫, 我们很显然知道, 一段区间是合法的, 必须满足, a[l - 1] = a[r], 且a[l ~ r - 1] >= a[l - 1] (a[r]), 那我们交换两个不同的括号有什么影响呢, 假如是左边的左括号和右边的右括号交换, 那么a[l ~ r - 1], 全部减去2, 反之同理, 看到这个, 那么我们就知道要用数据结构来维护这个a数组了, 线段树显然可以, 当然需要懒标记.

代码
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //typedef long long ll;
  4. const int INF = 0x3f3f3f3f;
  5. const int N = 2e5 + 10;
  6. const int M = 1e6 + 10;
  7. //const int mod = 1e9 + 7;
  8. //const double eps = 1e-6;
  9. template < typename T > inline void read(T &x) {
  10. x = 0; T ff = 1, ch = getchar();
  11. while (!isdigit(ch)) {
  12. if (ch == '-') ff = -1;
  13. ch = getchar();
  14. }
  15. while (isdigit(ch)) {
  16. x = (x << 1) + (x << 3) + (ch ^ 48);
  17. ch = getchar();
  18. }
  19. x *= ff;
  20. }
  21. char ch[N];
  22. int n, m, a[N];
  23. struct tree {
  24. int l, r;
  25. int dat, lazy;
  26. }t[N << 2];
  27. inline void build(int x, int l, int r) {
  28. t[x].l = l, t[x].r = r;
  29. if (l == r) {
  30. t[x].dat = a[l];
  31. return;
  32. }
  33. int mid = l + r >> 1;
  34. build(x << 1, l, mid);
  35. build(x << 1 | 1, mid + 1, r);
  36. t[x].dat = min(t[x << 1].dat, t[x << 1 | 1].dat);
  37. }
  38. inline void push_down(int x) {
  39. if (t[x].lazy != 0) {
  40. t[x << 1].lazy += t[x].lazy;
  41. t[x << 1 | 1].lazy += t[x].lazy;
  42. t[x << 1].dat += t[x].lazy;
  43. t[x << 1 | 1].dat += t[x].lazy;
  44. // t[x].dat = min(t[x << 1].dat, t[x << 1 | 1].dat);
  45. t[x].lazy = 0;
  46. }
  47. }
  48. inline void change(int x, int L, int R, int c) {
  49. int l = t[x].l, r = t[x].r;
  50. if (L <= l && R >= r) {
  51. t[x].dat += c;
  52. t[x].lazy += c;
  53. return;
  54. }
  55. push_down(x);
  56. int mid = l + r >> 1;
  57. if (mid >= L) change(x << 1, L, R, c);
  58. if (mid < R) change(x << 1 | 1, L, R, c);
  59. t[x].dat = min(t[x << 1].dat, t[x << 1 | 1].dat);
  60. }
  61. inline int query(int x, int L, int R) {
  62. int l = t[x].l, r = t[x].r;
  63. if (l >= L && r <= R) return t[x].dat;
  64. push_down(x);
  65. int ans = INF;
  66. int mid = l + r >> 1;
  67. if (mid >= L) ans = min(ans, query(x << 1, L, R));
  68. if (mid < R) ans = min(ans, query(x << 1 | 1, L, R));
  69. // t[x].dat = (t[x << 1].dat, t[x << 1 | 1].dat);
  70. return ans;
  71. }
  72. int main() {
  73. read(n); read(m);
  74. scanf("%s", ch + 1);
  75. for (int i = 1; i <= n; ++i) {
  76. if (ch[i] == '(') a[i] = a[i - 1] + 1;
  77. else a[i] = a[i - 1] - 1;
  78. }
  79. build(1, 0, n);
  80. for (int i = 1; i <= m; ++i) {
  81. int op, l, r;
  82. read(op), read(l), read(r);
  83. if (op == 1) {
  84. if (ch[l] == ch[r]) continue;
  85. if (ch[l] == '(') change(1, l, r - 1, -2);
  86. else change(1, l, r - 1, 2);
  87. swap(ch[l], ch[r]);
  88. } else {
  89. int x, y, z;
  90. x = query(1, l - 1, l - 1);
  91. y = query(1, l, r);
  92. z = query(1, r, r);
  93. if (x == y && y == z) puts("Yes");
  94. else puts("No");
  95. }
  96. }
  97. return 0;
  98. }

atcoder ABC233的更多相关文章

  1. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

  2. AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识

    链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...

  3. AtCoder Regular Contest 082

    我都出了F了……结果并没有出E……atcoder让我差4分上橙是啥意思啊…… C - Together 题意:把每个数加1或减1或不变求最大众数. #include<cstdio> #in ...

  4. AtCoder Regular Contest 069 D

    D - Menagerie Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Snuke, w ...

  5. AtCoder Regular Contest 076

    在湖蓝跟衡水大佬们打的第二场atcoder,不知不觉一星期都过去了. 任意门 C - Reconciled? 题意:n只猫,m只狗排队,猫与猫之间,狗与狗之间是不同的,同种动物不能相邻排,问有多少种方 ...

  6. AtCoder Grand Contest 016

    在雅礼和衡水的dalao们打了一场atcoder 然而窝好菜啊…… A - Shrinking 题意:定义一次操作为将长度为n的字符串变成长度n-1的字符串,且变化后第i个字母为变化前第i 或 i+1 ...

  7. AtCoder Beginner Contest 069【A,水,B,水,C,数学,D,暴力】

    A - K-City Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement In K-city, ...

  8. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle

    https://beta.atcoder.jp/contests/abc075/tasks/abc075_d 题意: 给出坐标平面上n个点的坐标,要求找到一个面积最小的矩形使得这个矩形的边界加上内部的 ...

  9. AtCoder Beginner Contest 073

    D - joisino's travel Time Limit: 2 sec / Memory Limit: 256 MB Score : 400400 points Problem Statemen ...

随机推荐

  1. php图片处理库

    <?php namespace app\common\library; /** * include 'imagick.class.php'; $image = new lib_image_ima ...

  2. PHP中比较数组的时候发生了什么?

    首先还是从代码来看,我们通过比较运算符号来对两个数组进行比较: var_dump([1, 2] == [2, 1]); // false var_dump([1, 2, 3] > [3, 2, ...

  3. Java基础系列(21)- dowhile循环

    do-while循环 对于while语句而言,如果不满足条件,则不能进入循环.但有时候我们需要即使不满足条件,也至少执行一次 do-while循环和while循环相似,不同的是,do-while循环至 ...

  4. 修改MAC系统下默认PHP版本(解决自带版本和环境版本冲突)

    https://www.jianshu.com/p/d080d06557be 更改环境变量来修改默认的php版本 新建一个.bas_profile文件并编辑 vim ~/.bash_profile 然 ...

  5. python 文件夹扫描

    扫描指定文件夹下的文件.或者匹配指定后缀和前缀的函数. 假设要扫描指定文件夹下的文件,包含子文件夹,调用scan_files("/export/home/test/") 假设要扫描 ...

  6. 关于cgroup的几个核心名词及其关系

    子​​​系​​​统​​​(subsystem) 所谓子系统可以理解为操作系统里的各种资源(组件),如CPU,内存,磁盘,网卡(带宽) 层​​​级(Hierarchies) 所谓层级就是子系统的集合,又 ...

  7. YbtOJ#493-最大分数【斜率优化dp,分治】

    正题 题目链接:http://www.ybtoj.com.cn/contest/117/problem/1 题目大意 \(n\)个数的一个序列,给其中的一些数打上标记. 一个标记方案的贡献为\(s_1 ...

  8. 踩坑经验总结之go web开源库第一次编译构建

    前言:记录一个go新手第一次构建复杂开源库的经历.go虽然是新手,但是编程上还是有多年的经验,除了c/c++,用过IDEA能进行简单的java编程.甚至scala编程.所以最开始还是有点信心的.所以也 ...

  9. redis无法连接

     Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: DENIED Redi ...

  10. AI 事件驱动场景 Serverless 实践

    作者 | 李鹏(元毅) 来源 | Serverless 公众号 一.事件驱动框架:Knative Eventing 事件驱动是指事件在持续事务管理过程中,进行决策的一种策略.可以通过调动可用资源执行相 ...