atcoder ABC233
B

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

题意
构造一个n的全排列, 使\(a_i\)在\(b_i\)前面;
题解
非常简单, 建边判环即可, 判环和记录答案都可以用topsort, 不过统计答案的时候要用堆优化, 应该可以写到一个函数里面
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const int M = 5e3 + 10;
const int eps = 1e-6;
template < typename T > inline void read(T &x) {
x = 0; T ff = 1, ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') ff = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x *= ff;
}
int n, m, c[N], du[N], vi[N];
map < int, int > p[N];
vector < int > v[N], a;
inline bool topsort() {
queue < int > q;
for (int i = 1; i <= n; ++i)
if (c[i] == 0) q.push(i);
while (!q.empty()) {
int x = q.front();
q.pop();
for (int i = 0; i < v[x].size(); ++i) {
int y = v[x][i];
--c[y];
if (c[y] == 0) q.push(y);
}
}
for (int i = 1; i <= n; ++i)
if (c[i]) return false;
return true;
}
inline void solve() {
priority_queue < int > q;
for (int i = 1; i <= n; ++i)
if (du[i] == 0) q.push(-i);
while (!q.empty()) {
int x = -q.top();
q.pop();
a.push_back(x);
for (int i = 0; i < v[x].size(); ++i) {
int y = v[x][i];
--du[y];
if (du[y] == 0) q.push(-y);
}
}
for (int i = 0; i < n; ++i) printf("%d ", a[i]);
}
int main() {
read(n), read(m);
for (int i = 1; i <= m; ++i) {
int x, y;
read(x), read(y);
if (p[x][y]) continue;
p[x][y] = true;
v[x].push_back(y);
++du[y];
++c[y];
}
if (!topsort()) puts("-1");
else solve();
return 0;
}
E

题意
题目不是很好理解, 有个x*y的网格, 要放入三个面积不小于a, b, c且边长都为整数的矩形, 判断是否成立。
题解
当有两个矩形的时候, 存在一条线, 把两个矩形分开。 当三个矩形的时候, 存在一条线, 分成一边一个矩形,一边两个矩形。 那我们就枚举这个矩形,在枚举x或y,使这条边充分利用, 算出len=\(\lceil\frac{S}{x}\rceil\), 或 len=\(\lceil\frac{S}{y}\rceil\), 从而把边长减去len, 转换成两个矩形的问题, 同上
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const int M = 5e3 + 10;
const int eps = 1e-6;
template < typename T > inline void read(T &x) {
x = 0; T ff = 1, ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') ff = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x *= ff;
}
ll n, m, a, b, c;
inline bool solve2(ll x, ll y, ll u, ll v) {
for (int i = 0; i < 2; ++i) {
ll len = (u + x - 1) / x;
if (len < y && x * (y - len) >= v) return true;
swap(x, y);
}
return false;
}
inline bool solve3(ll x, ll y, ll u, ll v, ll w) {
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 3; ++j) {
ll len = (u + x - 1) / x;
if (len < y && solve2(x, y - len, v, w)) return true;
swap(u, v);
swap(v, w);
}
swap(x, y);
}
return false;
}
int main() {
read(n), read(m), read(a), read(b), read(c);
puts(solve3(n, m, a, b, c) ? "Yes" : "No");
return 0;
}
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数组了, 线段树显然可以, 当然需要懒标记.
代码
#include <bits/stdc++.h>
using namespace std;
//typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const int M = 1e6 + 10;
//const int mod = 1e9 + 7;
//const double eps = 1e-6;
template < typename T > inline void read(T &x) {
x = 0; T ff = 1, ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') ff = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x *= ff;
}
char ch[N];
int n, m, a[N];
struct tree {
int l, r;
int dat, lazy;
}t[N << 2];
inline void build(int x, int l, int r) {
t[x].l = l, t[x].r = r;
if (l == r) {
t[x].dat = a[l];
return;
}
int mid = l + r >> 1;
build(x << 1, l, mid);
build(x << 1 | 1, mid + 1, r);
t[x].dat = min(t[x << 1].dat, t[x << 1 | 1].dat);
}
inline void push_down(int x) {
if (t[x].lazy != 0) {
t[x << 1].lazy += t[x].lazy;
t[x << 1 | 1].lazy += t[x].lazy;
t[x << 1].dat += t[x].lazy;
t[x << 1 | 1].dat += t[x].lazy;
// t[x].dat = min(t[x << 1].dat, t[x << 1 | 1].dat);
t[x].lazy = 0;
}
}
inline void change(int x, int L, int R, int c) {
int l = t[x].l, r = t[x].r;
if (L <= l && R >= r) {
t[x].dat += c;
t[x].lazy += c;
return;
}
push_down(x);
int mid = l + r >> 1;
if (mid >= L) change(x << 1, L, R, c);
if (mid < R) change(x << 1 | 1, L, R, c);
t[x].dat = min(t[x << 1].dat, t[x << 1 | 1].dat);
}
inline int query(int x, int L, int R) {
int l = t[x].l, r = t[x].r;
if (l >= L && r <= R) return t[x].dat;
push_down(x);
int ans = INF;
int mid = l + r >> 1;
if (mid >= L) ans = min(ans, query(x << 1, L, R));
if (mid < R) ans = min(ans, query(x << 1 | 1, L, R));
// t[x].dat = (t[x << 1].dat, t[x << 1 | 1].dat);
return ans;
}
int main() {
read(n); read(m);
scanf("%s", ch + 1);
for (int i = 1; i <= n; ++i) {
if (ch[i] == '(') a[i] = a[i - 1] + 1;
else a[i] = a[i - 1] - 1;
}
build(1, 0, n);
for (int i = 1; i <= m; ++i) {
int op, l, r;
read(op), read(l), read(r);
if (op == 1) {
if (ch[l] == ch[r]) continue;
if (ch[l] == '(') change(1, l, r - 1, -2);
else change(1, l, r - 1, 2);
swap(ch[l], ch[r]);
} else {
int x, y, z;
x = query(1, l - 1, l - 1);
y = query(1, l, r);
z = query(1, r, r);
if (x == y && y == z) puts("Yes");
else puts("No");
}
}
return 0;
}
atcoder ABC233的更多相关文章
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识
链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...
- AtCoder Regular Contest 082
我都出了F了……结果并没有出E……atcoder让我差4分上橙是啥意思啊…… C - Together 题意:把每个数加1或减1或不变求最大众数. #include<cstdio> #in ...
- AtCoder Regular Contest 069 D
D - Menagerie Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Snuke, w ...
- AtCoder Regular Contest 076
在湖蓝跟衡水大佬们打的第二场atcoder,不知不觉一星期都过去了. 任意门 C - Reconciled? 题意:n只猫,m只狗排队,猫与猫之间,狗与狗之间是不同的,同种动物不能相邻排,问有多少种方 ...
- AtCoder Grand Contest 016
在雅礼和衡水的dalao们打了一场atcoder 然而窝好菜啊…… A - Shrinking 题意:定义一次操作为将长度为n的字符串变成长度n-1的字符串,且变化后第i个字母为变化前第i 或 i+1 ...
- 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, ...
- AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle
https://beta.atcoder.jp/contests/abc075/tasks/abc075_d 题意: 给出坐标平面上n个点的坐标,要求找到一个面积最小的矩形使得这个矩形的边界加上内部的 ...
- AtCoder Beginner Contest 073
D - joisino's travel Time Limit: 2 sec / Memory Limit: 256 MB Score : 400400 points Problem Statemen ...
随机推荐
- axios与vue-resource
在Vue项目中前后端交互时,早期Vue使用Vue-resource实现异步请求.从Vue2.0之后就不再对vue-resource进行更新,Vue官方推荐使用axios. vue-resource V ...
- PHP设计模式之访问者模式
访问者,就像我们去别人家访问,或者别人来我们家看望我们一样.我们每个人都像是一个实体,而来访的人都会一一的和我们打招呼.毕竟,我们中华民族是非常讲究礼数和好客的民族.访问者是GoF23个设计模式中最复 ...
- PHP脚本设置及获取进程名
今天来学习的是两个非常简单的函数,一个可以用来设置我们执行脚本时运行的进程名.而另一个就是简单的获取当前运行的进程名.这两个函数对于大量的脚本运行代码有很大的作用,比如我们需要 kill 掉某个进程时 ...
- ecshop刷新页面出现power by ecshop和链接的解决办法
当小伙伴在使用echop模板进行修改的时候,如果你删掉底部自带版权后,再调试程序刷新界面的时候,时不时就会冒出一个power by ecshop,而且是带有链接的,很不舒服,所以需要去掉,下面是最简单 ...
- Django边学边记—视图
一. url (一)配置 在项目/settings.py中通过ROOT_URLCONF指定url配置 ROOT_URLCONF = 'XXXX.urls' 打开 项目/urls.py 配置 (二)语法 ...
- redis 设置密码 laravel框架配置redis
* 参考资料 redis文档 http://www.redis.cn/documentation.html, http://redisdoc.com/index.html r ...
- YbtOJ-大收藏家【分层图,最大流】
正题 题目链接:https://www.ybtoj.com.cn/contest/117/problem/2 题目大意 \(n\)个人,每人有\(a_i\)个属于自己的物品.\(m\)次交换依次进行, ...
- 实现线程按顺序输出ABC
线程按顺序输出ABC 实现描述:建立三个线程A.B.C,分别按照顺序输出十次ABC 首先建立一个方法,按照条件进行输出 class PrintABC{ private int index=0; pub ...
- Java-多态(上)
什么是多态 同一方法可以根据发送对象的不同而采取多种不同的行为方式 一个对象实际类型是确定的 但指向其引用类型却有很多 注意事项 多态是方法的多态 属性没有多态 父类和子类 有联系 类型转换异常 Cl ...
- 9.亿级流量电商系统JVM模型参数预估方案
1. 需求分析 大促在即,拥有亿级流量的电商平台开发了一个订单系统,我们应该如何来预估其并发量?如何根据并发量来合理配置JVM参数呢? 假设,现在有一个场景,一个电商平台,比如京东,需要承担每天上亿的 ...