当前位置: 首页 > news >正文

AtCoder Beginner Contest 367(ABCDEF题)视频讲解

A - Shout Everyday

Problem Statement

In the Kingdom of AtCoder, residents are required to shout their love for takoyaki at A A A o’clock every day.
Takahashi, who lives in the Kingdom of AtCoder, goes to bed at B B B o’clock and wakes up at C C C o’clock every day (in the 24 24 24-hour clock). He can shout his love for takoyaki when he is awake, but cannot when he is asleep. Determine whether he can shout his love for takoyaki every day. Here, a day has 24 24 24 hours, and his sleeping time is less than 24 24 24 hours.

Constraints

0 ≤ A , B , C < 24 0\leq A,B,C\lt 24 0A,B,C<24
A A A, B B B, and C C C are pairwise different.
All input values are integers.

Input

The input is given from Standard Input in the following format:

A A A B B B C C C

Output

Print Yes if Takahashi can shout his love for takoyaki every day, and No otherwise.

Sample Input 1

21 8 14

Sample Output 1

Yes

Takahashi goes to bed at 8 8 8 o’clock and wakes up at 14 14 14 o’clock every day. He is awake at 21 21 21 o’clock, so he can shout his love for takoyaki every day. Therefore, print Yes.

Sample Input 2

0 21 7

Sample Output 2

No

Takahashi goes to bed at 21 21 21 o’clock and wakes up at 7 7 7 o’clock every day. He is not awake at 0 0 0 o’clock, so he cannot shout his love for takoyaki every day. Therefore, print No.

Sample Input 3

10 7 17

Sample Output 3

No

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long longusing namespace std;typedef pair<int, int> PII;
typedef long long LL;signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);int a, b, c;cin >> a >> b >> c;if (b > c) {if (a >= b && a < 24 || a <= c) cout << "No" << endl;else cout << "Yes" << endl;} else {if (a >= b && a <= c) cout << "No" << endl;else cout << "Yes" << endl;}return 0;
}

B - Cut .0

Problem Statement

A real number X X X is given to the third decimal place.
Print the real number X X X under the following conditions.
The decimal part must not have trailing 0s.
There must not be an unnecessary trailing decimal point.

Constraints

KaTeX parse error: Expected 'EOF', got '&' at position 9: 0 \le X &̲lt; 100
X X X is given to the third decimal place.

Input

The input is given from Standard Input in the following format:

X X X

Output

Output the answer.

Sample Input 1

1.012

Sample Output 1

1.012

1.012 can be printed as it is.

Sample Input 2

12.340

Sample Output 2

12.34

Printing 12.340 without the trailing 0 results in 12.34.

Sample Input 3

99.900

Sample Output 3

99.9

Printing 99.900 without the trailing 0s results in 99.9.

Sample Input 4

0.000

Sample Output 4

0

Printing 0.000 without trailing 0s or an unnecessary decimal point results in 0.

Solution

具体见文末视频。

Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long longusing namespace std;typedef pair<int, int> PII;
typedef long long LL;signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);string s;cin >> s;while (s.size() && s.back() == '0') s.pop_back();if (s.back() == '.') s.pop_back();cout << s << endl;return 0;
}

C - Enumerate Sequences

Problem Statement

Print all integer sequences of length N N N that satisfy the following conditions, in ascending lexicographical order.
The i i i-th element is between 1 1 1 and R i R_i Ri, inclusive.
The sum of all elements is a multiple of K K K.

What is lexicographical order for sequences? A sequence $A = (A_1, \ldots, A_{|A|})$ is lexicographically smaller than $B = (B_1, \ldots, B_{|B|})$ if either 1. or 2. below holds:
  1. $|A|<|B|$ and $(A_{1},\ldots,A_{|A|}) = (B_1,\ldots,B_{|A|})$. There exists an integer $1\leq i\leq \min\{|A|,|B|\}$ such that both of the following are true: $(A_{1},\ldots,A_{i-1}) = (B_1,\ldots,B_{i-1})$ $A_i < B_i$
## Constraints

All input values are integers.
1 ≤ N ≤ 8 1 \le N \le 8 1N8
2 ≤ K ≤ 10 2 \le K \le 10 2K10
1 ≤ R i ≤ 5 1 \le R_i \le 5 1Ri5

Input

The input is given from Standard Input in the following format:

N N N K K K
R 1 R_1 R1 R 2 R_2 R2 … \dots R N R_N RN

Output

Print the answer in the following format, where X X X is the number of sequences to print, the i i i-th of which is A i = ( A i , 1 , A i , 2 , … , A i , N ) A_i=(A_{i,1},A_{i,2},\dots,A_{i,N}) Ai=(Ai,1,Ai,2,,Ai,N):

A 1 , 1 A_{1,1} A1,1 A 1 , 2 A_{1,2} A1,2 … \dots A 1 , N A_{1,N} A1,N
A 2 , 1 A_{2,1} A2,1 A 2 , 2 A_{2,2} A2,2 … \dots A 2 , N A_{2,N} A2,N
⋮ \vdots
A X , 1 A_{X,1} AX,1 A X , 2 A_{X,2} AX,2 … \dots A X , N A_{X,N} AX,N

Sample Input 1

3 2
2 1 3

Sample Output 1

1 1 2
2 1 1
2 1 3

There are three sequences to be printed, which are ( 1 , 1 , 2 ) , ( 2 , 1 , 1 ) , ( 2 , 1 , 3 ) (1,1,2),(2,1,1),(2,1,3) (1,1,2),(2,1,1),(2,1,3) in lexicographical order.

Sample Input 2

1 2
1

Sample Output 2

There may be no sequences to print.

In this case, the output can be empty.

Sample Input 3

5 5
2 3 2 3 2

Sample Output 3

1 1 1 1 1
1 2 2 3 2
1 3 1 3 2
1 3 2 2 2
1 3 2 3 1
2 1 2 3 2
2 2 1 3 2
2 2 2 2 2
2 2 2 3 1
2 3 1 2 2
2 3 1 3 1
2 3 2 1 2
2 3 2 2 1

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long longusing namespace std;typedef pair<int, int> PII;
typedef long long LL;int n, k;
int r[10], a[10];void dfs(int u) {if (u > n) {int tot = 0;for (int i = 1; i <= n; i ++)tot += a[i];if (tot % k == 0) {for (int i = 1; i <= n; i ++) cout << a[i] << " ";cout << endl;}return;}for (int i = 1; i <= r[u]; i ++)a[u] = i, dfs(u + 1);
}signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);cin >> n >> k;for (int i = 1; i <= n; i ++)cin >> r[i];dfs(1);return 0;
}

D - Pedometer

Problem Statement

There are N N N rest areas around a lake.

The rest areas are numbered 1 1 1, 2 2 2, …, N N N in clockwise order.

It takes A i A_i Ai steps to walk clockwise from rest area i i i to rest area i + 1 i+1 i+1 (where rest area N + 1 N+1 N+1 refers to rest area 1 1 1).

The minimum number of steps required to walk clockwise from rest area s s s to rest area t t t ( s ≠ t s \neq t s=t) is a multiple of M M M.

Find the number of possible pairs ( s , t ) (s,t) (s,t).

Constraints

All input values are integers
2 ≤ N ≤ 2 × 1 0 5 2 \le N \le 2 \times 10^5 2N2×105
1 ≤ A i ≤ 1 0 9 1 \le A_i \le 10^9 1Ai109
1 ≤ M ≤ 1 0 6 1 \le M \le 10^6 1M106

Input

The input is given from Standard Input in the following format:

N N N M M M
A 1 A_1 A1 A 2 A_2 A2 … \dots A N A_N AN

Output

Print the answer as an integer.

Sample Input 1

4 3
2 1 4 3

Sample Output 1

4

The minimum number of steps to walk clockwise from rest area 1 1 1 to rest area 2 2 2 is 2 2 2, which is not a multiple of 3 3 3.
The minimum number of steps to walk clockwise from rest area 1 1 1 to rest area 3 3 3 is 3 3 3, which is a multiple of 3 3 3.
The minimum number of steps to walk clockwise from rest area 1 1 1 to rest area 4 4 4 is 7 7 7, which is not a multiple of 3 3 3.
The minimum number of steps to walk clockwise from rest area 2 2 2 to rest area 3 3 3 is 1 1 1, which is not a multiple of 3 3 3.
The minimum number of steps to walk clockwise from rest area 2 2 2 to rest area 4 4 4 is 5 5 5, which is not a multiple of 3 3 3.
The minimum number of steps to walk clockwise from rest area 2 2 2 to rest area 1 1 1 is 8 8 8, which is not a multiple of 3 3 3.
The minimum number of steps to walk clockwise from rest area 3 3 3 to rest area 4 4 4 is 4 4 4, which is not a multiple of 3 3 3.
The minimum number of steps to walk clockwise from rest area 3 3 3 to rest area 1 1 1 is 7 7 7, which is not a multiple of 3 3 3.
The minimum number of steps to walk clockwise from rest area 3 3 3 to rest area 2 2 2 is 9 9 9, which is a multiple of 3 3 3.
The minimum number of steps to walk clockwise from rest area 4 4 4 to rest area 1 1 1 is 3 3 3, which is a multiple of 3 3 3.
The minimum number of steps to walk clockwise from rest area 4 4 4 to rest area 2 2 2 is 5 5 5, which is not a multiple of 3 3 3.
The minimum number of steps to walk clockwise from rest area 4 4 4 to rest area 3 3 3 is 6 6 6, which is a multiple of 3 3 3.
Therefore, there are four possible pairs ( s , t ) (s,t) (s,t).

Sample Input 2

2 1000000
1 1

Sample Output 2

0

Sample Input 3

9 5
9 9 8 2 4 4 3 5 3

Sample Output 3

11

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long longusing namespace std;typedef pair<int, int> PII;
typedef long long LL;const int N = 2e5 + 10;int n, m;
int a[N * 2];signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);cin >> n >> m;for (int i = 1; i <= n; i ++)cin >> a[i], a[i + n] = a[i];for (int i = 1; i <= 2 * n; i ++) (a[i] += a[i - 1]) %= m;unordered_map<int, int> cnt;int res = 0;for (int i = 2; i <= n; i ++) cnt[a[i]] ++;for (int i = n + 1; i <= 2 * n; i ++) {res += cnt[a[i]], cnt[a[i]] ++;if (i > n) cnt[a[i - n + 1]] --;}cout << res << endl;return 0;
}

E - Permute K times

Problem Statement

You are given a sequence X X X of length N N N where each element is between 1 1 1 and N N N, inclusive, and a sequence A A A of length N N N.

Print the result of performing the following operation K K K times on A A A.
Replace A A A with B B B such that B i = A X i B_i = A_{X_i} Bi=AXi.

Constraints

All input values are integers.
1 ≤ N ≤ 2 × 1 0 5 1 \le N \le 2 \times 10^5 1N2×105
0 ≤ K ≤ 1 0 18 0 \le K \le 10^{18} 0K1018
1 ≤ X i ≤ N 1 \le X_i \le N 1XiN
1 ≤ A i ≤ 2 × 1 0 5 1 \le A_i \le 2 \times 10^5 1Ai2×105

Input

The input is given from Standard Input in the following format:

N N N K K K
X 1 X_1 X1 X 2 X_2 X2 … \dots X N X_N XN
A 1 A_1 A1 A 2 A_2 A2 … \dots A N A_N AN

Output

Let A ′ A' A be the sequence A A A after the operations. Print it in the following format:

A 1 ′ A'_1 A1 A 2 ′ A'_2 A2 … \dots A N ′ A'_N AN

Sample Input 1

7 3
5 2 6 3 1 4 6
1 2 3 5 7 9 11

Sample Output 1

7 2 3 5 1 9 3

In this input, X = ( 5 , 2 , 6 , 3 , 1 , 4 , 6 ) X=(5,2,6,3,1,4,6) X=(5,2,6,3,1,4,6) and the initial sequence is A = ( 1 , 2 , 3 , 5 , 7 , 9 , 11 ) A=(1,2,3,5,7,9,11) A=(1,2,3,5,7,9,11).
After one operation, the sequence is ( 7 , 2 , 9 , 3 , 1 , 5 , 9 ) (7,2,9,3,1,5,9) (7,2,9,3,1,5,9).
After two operations, the sequence is ( 1 , 2 , 5 , 9 , 7 , 3 , 5 ) (1,2,5,9,7,3,5) (1,2,5,9,7,3,5).
After three operations, the sequence is ( 7 , 2 , 3 , 5 , 1 , 9 , 3 ) (7,2,3,5,1,9,3) (7,2,3,5,1,9,3).

Sample Input 2

4 0
3 4 1 2
4 3 2 1

Sample Output 2

4 3 2 1

There may be cases where no operations are performed.

Sample Input 3

9 1000000000000000000
3 7 8 5 9 3 7 4 2
9 9 8 2 4 4 3 5 3

Sample Output 3

3 3 3 3 3 3 3 3 3

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long longusing namespace std;typedef pair<int, int> PII;
typedef long long LL;const int N = 2e5 + 10;int n, k;
int to[N][62], a[N];signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);cin >> n >> k;for (int i = 1; i <= n; i ++)cin >> to[i][0];for (int i = 1; i <= n; i ++)cin >> a[i];for (int j = 1; j < 62; j ++)for (int i = 1; i <= n; i ++)to[i][j] = to[to[i][j - 1]][j - 1];for (int i = 1; i <= n; i ++) {int p = i;for (int j = 61; j >= 0; j --)if (k >> j & 1) p = to[p][j];cout << a[p] << " ";}cout<< endl;return 0;
}

F - Rearrange Query

Problem Statement

You are given sequences of positive integers of length N N N: A = ( A 1 , A 2 , … , A N ) A=(A_1,A_2,\ldots,A_N) A=(A1,A2,,AN) and B = ( B 1 , B 2 , … , B N ) B=(B_1,B_2,\ldots,B_N) B=(B1,B2,,BN).
You are given Q Q Q queries to process in order. The i i i-th query is explained below.
You are given positive integers l i , r i , L i , R i l_i,r_i,L_i,R_i li,ri,Li,Ri. Print Yes if it is possible to rearrange the subsequence ( A l i , A l i + 1 , … , A r i ) (A_{l_i},A_{l_i+1},\ldots,A_{r_i}) (Ali,Ali+1,,Ari) to match the subsequence ( B L i , B L i + 1 , … , B R i ) (B_{L_i},B_{L_i+1},\ldots,B_{R_i}) (BLi,BLi+1,,BRi), and No otherwise.

Constraints

$ 1\leq N,Q\leq 2\times 10^5$
$ 1\leq A_i,B_i\leq N$
$ 1\leq l_i \leq r_i\leq N$
$ 1\leq L_i \leq R_i\leq N$
All input values are integers.

Input

The input is given from Standard Input in the following format:

N N N Q Q Q
A 1 A_1 A1 A 2 A_2 A2 … \ldots A N A_N AN
B 1 B_1 B1 B 2 B_2 B2 … \ldots B N B_N BN
l 1 l_1 l1 r 1 r_1 r1 L 1 L_1 L1 R 1 R_1 R1
l 2 l_2 l2 r 2 r_2 r2 L 2 L_2 L2 R 2 R_2 R2
⋮ \vdots
l Q l_Q lQ r Q r_Q rQ L Q L_Q LQ R Q R_Q RQ

Output

Print Q Q Q lines. The i i i-th line should contain the answer to the i i i-th query.

Sample Input 1

5 4
1 2 3 2 4
2 3 1 4 2
1 3 1 3
1 2 3 5
1 4 2 5
1 5 1 5

Sample Output 1

Yes
No
No
Yes

For the 1st query, it is possible to rearrange ( 1 , 2 , 3 ) (1,2,3) (1,2,3) to match ( 2 , 3 , 1 ) (2,3,1) (2,3,1). Hence, we print Yes.
For the 2nd query, it is impossible to rearrange ( 1 , 2 ) (1,2) (1,2) in any way to match ( 1 , 4 , 2 ) (1,4,2) (1,4,2). Hence, we print No.
For the 3rd query, it is impossible to rearrange ( 1 , 2 , 3 , 2 ) (1,2,3,2) (1,2,3,2) in any way to match ( 3 , 1 , 4 , 2 ) (3,1,4,2) (3,1,4,2). Hence, we print No.
For the 4th query, it is possible to rearrange ( 1 , 2 , 3 , 2 , 4 ) (1,2,3,2,4) (1,2,3,2,4) to match ( 2 , 3 , 1 , 4 , 2 ) (2,3,1,4,2) (2,3,1,4,2). Hence, we print Yes.

Sample Input 2

4 4
4 4 4 4
4 4 4 4
1 2 2 3
3 3 1 1
1 3 1 4
1 4 2 3

Sample Output 2

Yes
Yes
No
No

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>using namespace std;typedef unsigned long long ull;
const int N = 2e5 + 10;int n, q, len;
int a[N], b[N], len1[N], len2[N];
pair<ull, ull> res1[N], res2[N];
ull hsh1, hsh2;
struct Query {int id, l, r;bool operator< (const Query &tmp)const {if (l / len == tmp.l / len) return r < tmp.r;return l / len < tmp.l / len;}
}qry1[N], qry2[N];ull h(ull x) {return (ull)x * x * x * 1237123 + 19260817;
}
ull f(int x) {ull cur = h(x & ((1ll << 31) - 1)) + h(x >> 31);return cur;
}
ull h2(ull x) {return (ull)x * x * 1145141 + 998244353;
}
ull f2(int x) {ull cur = h2(x & ((1ll << 27) - 1)) + h2(x >> 27);return cur;
}
void add1(int po) {int x = a[po];hsh1 += f(x), hsh2 += f2(x);
}
void del1(int po) {int x = a[po];hsh1 -= f(x), hsh2 -= f2(x);
}
void add2(int po) {int x = b[po];hsh1 += f(x), hsh2 += f2(x);
}
void del2(int po) {int x = b[po];hsh1 -= f(x), hsh2 -= f2(x);
}int main() {cin >> n >> q;for (int i = 1; i <= n; i ++)cin >> a[i];for (int i = 1; i <= n; i ++)cin >> b[i];len = max(sqrt((double)n * n / q), 1.0);for (int i = 1; i <= q; i ++) {int l1, r1, l2, r2;cin >> l1 >> r1 >> l2 >> r2;qry1[i] = {i, l1, r1}, qry2[i] = {i, l2, r2};len1[i] = r1 - l1 + 1, len2[i] = r2 - l2 + 1;}sort(qry1 + 1, qry1 + 1 + q);sort(qry2 + 1, qry2 + 1 + q);for (int i = 1, l = 1, r = 0; i <= q; i ++) {int lo = qry1[i].l, ro = qry1[i].r, id = qry1[i].id;while (l > lo) add1( -- l);while (l < lo) del1(l ++);while (r > ro) del1(r --);while (r < ro) add1( ++ r);res1[id] = make_pair(hsh1, hsh2);}hsh1 = hsh2 = 0;for (int i = 1, l = 1, r = 0; i <= q; i ++) {int lo = qry2[i].l, ro = qry2[i].r, id = qry2[i].id;while (l > lo) add2( -- l);while (l < lo) del2(l ++);while (r > ro) del2(r --);while (r < ro) add2( ++ r);res2[id] = make_pair(hsh1, hsh2);}for (int i = 1; i <= q; i ++) {if (res1[i] == res2[i] && len1[i] == len2[i]) cout << "Yes" << endl;else cout << "No" << endl;}
}

视频题解

AtCoder Beginner Contest 367(A ~ F 题讲解)


最后祝大家早日在这里插入图片描述

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 将iso格式的镜像文件转化成云平台能安装的镜像格式(raw/vhd/QCOW2/VMDK )亲测--图文详解
  • 优化Maven镜像配置:使用阿里云加速依赖下载
  • 【密码学】密钥管理:②密钥分配
  • 从零开始学习SLAM(五):极几何与极约束
  • 消息系统类型
  • <数据集>航拍牧场牛羊识别数据集<目标检测>
  • Python 字符串转对象
  • 【C语言】static和extern的作用
  • Kubernetes 清理资源常用的 Kubernetes 清理命
  • SAP 预扣税配置步骤文档【Withholding Tax]
  • VMware虚拟机nat无法联通主机
  • 【爬虫】 使用AI编写B站爬虫代码
  • 汽车IVI中控OS Linux driver开发实操(二十五):GPIO设备驱动的上手编写
  • JavaScript语法基础之事件基础(鼠标、表单、页面事件等)
  • 3D场景标注标签信息,three.js CSS 2D渲染器CSS2DRenderer、CSS 3D渲染器CSS3DRenderer(结合react)
  • 【挥舞JS】JS实现继承,封装一个extends方法
  • 【腾讯Bugly干货分享】从0到1打造直播 App
  • CoolViewPager:即刻刷新,自定义边缘效果颜色,双向自动循环,内置垂直切换效果,想要的都在这里...
  • GDB 调试 Mysql 实战(三)优先队列排序算法中的行记录长度统计是怎么来的(上)...
  • HTTP 简介
  • Java 实战开发之spring、logback配置及chrome开发神器(六)
  • Joomla 2.x, 3.x useful code cheatsheet
  • puppeteer stop redirect 的正确姿势及 net::ERR_FAILED 的解决
  • Selenium实战教程系列(二)---元素定位
  • Terraform入门 - 3. 变更基础设施
  • 短视频宝贝=慢?阿里巴巴工程师这样秒开短视频
  • 官方解决所有 npm 全局安装权限问题
  • 区块链将重新定义世界
  • 如何编写一个可升级的智能合约
  • 三栏布局总结
  • 数据可视化之 Sankey 桑基图的实现
  • 微服务框架lagom
  • 深度学习之轻量级神经网络在TWS蓝牙音频处理器上的部署
  • 积累各种好的链接
  • ​configparser --- 配置文件解析器​
  • ​如何在iOS手机上查看应用日志
  • ‌移动管家手机智能控制汽车系统
  • # 达梦数据库知识点
  • #我与虚拟机的故事#连载20:周志明虚拟机第 3 版:到底值不值得买?
  • #预处理和函数的对比以及条件编译
  • $.ajax,axios,fetch三种ajax请求的区别
  • %3cli%3e连接html页面,html+canvas实现屏幕截取
  • (1)SpringCloud 整合Python
  • (1)常见O(n^2)排序算法解析
  • (10)工业界推荐系统-小红书推荐场景及内部实践【排序模型的特征】
  • (2015)JS ES6 必知的十个 特性
  • (2022 CVPR) Unbiased Teacher v2
  • (C语言)球球大作战
  • (NSDate) 时间 (time )比较
  • (PWM呼吸灯)合泰开发板HT66F2390-----点灯大师
  • (vue)el-checkbox 实现展示区分 label 和 value(展示值与选中获取值需不同)
  • (翻译)Entity Framework技巧系列之七 - Tip 26 – 28
  • (附源码)springboot建达集团公司平台 毕业设计 141538
  • (全部习题答案)研究生英语读写教程基础级教师用书PDF|| 研究生英语读写教程提高级教师用书PDF
  • (推荐)叮当——中文语音对话机器人