ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined)
靠这把上了蓝
2 seconds
256 megabytes
standard input
standard output
You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest".
A palindrome is a string that reads the same forward or backward.
The length of string B should be at most 104. It is guaranteed that there always exists such string.
You do not need to find the shortest answer, the only restriction is that the length of string B should not exceed 104.
First line contains a string A (1 ≤ |A| ≤ 103) consisting of lowercase Latin letters, where |A| is a length of A.
Output single line containing B consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string B should not exceed 104. If there are many possible B, print any of them.
aba
aba
ab
aabaa
In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome.
输出一个字符串是输入串的子串,并且是回文串,不要求最短
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+;
int main()
{
ios::sync_with_stdio(false);
string s;
cin>>s;
cout<<s;
reverse(s.begin(),s.end());
cout<<s;
return ;
}
2 seconds
256 megabytes
standard input
standard output
Let us define two functions f and g on positive integer numbers.
You need to process Q queries. In each query, you will be given three integers l, r and k. You need to print the number of integers xbetween l and r inclusive, such that g(x) = k.
The first line of the input contains an integer Q (1 ≤ Q ≤ 2 × 105) representing the number of queries.
Q lines follow, each of which contains 3 integers l, r and k (1 ≤ l ≤ r ≤ 106, 1 ≤ k ≤ 9).
For each query, print a single line containing the answer for that query.
4
22 73 9
45 64 6
47 55 7
2 62 4
1
4
0
8
4
82 94 6
56 67 4
28 59 9
39 74 4
3
1
1
5
In the first example:
- g(33) = 9 as g(33) = g(3 × 3) = g(9) = 9
- g(47) = g(48) = g(60) = g(61) = 6
- There are no such integers between 47 and 55.
- g(4) = g(14) = g(22) = g(27) = g(39) = g(40) = g(41) = g(58) = 4
他本来是递归函数,我们需要先预处理就可以了
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+;
int a[N][];
int main()
{
ios::sync_with_stdio(false);
for(int i=;i<=1e6;i++)
{
int t=i;
while(t>=)
{
int s=;
while(t)
{
if(t%)s*=t%;
t/=;
}
t=s;
}
for(int j=;j<;j++)
a[i][j]=a[i-][j]+(t==j);
}
int T;
cin>>T;
while(T--)
{
int l,r,k;
cin>>l>>r>>k;
cout<<a[r][k]-a[l-][k]<<"\n";
} return ;
}
2 seconds
256 megabytes
standard input
standard output
For a permutation P[1... N] of integers from 1 to N, function f is defined as follows:
Let g(i) be the minimum positive integer j such that f(i, j) = i. We can show such j always exists.
For given N, A, B, find a permutation P of integers from 1 to N such that for 1 ≤ i ≤ N, g(i) equals either A or B.
The only line contains three integers N, A, B (1 ≤ N ≤ 106, 1 ≤ A, B ≤ N).
If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to N.
9 2 5
6 5 8 3 4 1 9 2 7
3 2 1
1 2 3
In the first example, g(1) = g(6) = g(7) = g(9) = 2 and g(2) = g(3) = g(4) = g(5) = g(8) = 5
In the second example, g(1) = g(2) = g(3) = 1
递归版的轮换,一组等于a,一组等于b即可
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b,f=,fa,fb;
cin>>n>>a>>b;
if(b>a)swap(a,b);
for(int i=; i<=n&&f; i+=a)
if((n-i)%b==)
fa=i/a,fb=(n-i)/b,f=;
if(f)
cout<<-;
else
{
int i=;
for(; i<=fa*a; i+=a)
{
cout<<i+a-<<" ";
for(int j=i; j<i+a-; j++)
cout<<j<<" ";
}
for(; i<=n; i+=b)
{
cout<<i+b-<<" ";
for(int j=i; j<i+b-; j++)
cout<<j<<" ";
}
}
return ;
}
2 seconds
512 megabytes
standard input
standard output
You are given a node of the tree with index 1 and with weight 0. Let cnt be the number of nodes in the tree at any instant (initially, cnt is set to 1). Support Q queries of following two types:
Add a new node (index cnt + 1) with weight W and add edge between node R and this node.
Output the maximum length of sequence of nodes which
- starts with R.
- Every node in the sequence is an ancestor of its predecessor.
- Sum of weight of nodes in sequence does not exceed X.
- For some nodes i, j that are consecutive in the sequence if i is an ancestor of j then w[i] ≥ w[j] and there should not exist a node k on simple path from i to j such that w[k] ≥ w[j]
The tree is rooted at node 1 at any instant.
Note that the queries are given in a modified way.
First line containing the number of queries Q (1 ≤ Q ≤ 400000).
Let last be the answer for previous query of type 2 (initially last equals 0).
Each of the next Q lines contains a query of following form:
- 1 p q (1 ≤ p, q ≤ 1018): This is query of first type where
and
. It is guaranteed that 1 ≤ R ≤ cnt and 0 ≤ W ≤ 109.
- 2 p q (1 ≤ p, q ≤ 1018): This is query of second type where
and
. It is guaranteed that 1 ≤ R ≤ cntand 0 ≤ X ≤ 1015.
denotes bitwise XOR of a and b.
It is guaranteed that at least one query of type 2 exists.
Output the answer to each query of second type in separate line.
6
1 1 1
2 2 0
2 2 1
1 3 0
2 2 0
2 2 2
0
1
1
2
6
1 1 0
2 2 0
2 0 3
1 0 2
2 1 3
2 1 6
2
2
3
2
7
1 1 2
1 2 3
2 3 3
1 0 0
1 5 1
2 5 0
2 4 0
1
1
2
7
1 1 3
1 2 3
2 3 4
1 2 0
1 5 3
2 5 5
2 7 22
1
2
3
In the first example,
last = 0
- Query 1: 1 1 1, Node 2 with weight 1 is added to node 1.
- Query 2: 2 2 0, No sequence of nodes starting at 2 has weight less than or equal to 0. last = 0
- Query 3: 2 2 1, Answer is 1 as sequence will be {2}. last = 1
- Query 4: 1 2 1, Node 3 with weight 1 is added to node 2.
- Query 5: 2 3 1, Answer is 1 as sequence will be {3}. Node 2 cannot be added as sum of weights cannot be greater than 1. last = 1
- Query 6: 2 3 3, Answer is 2 as sequence will be {3, 2}. last = 2
对于一棵树,你有2种操作
ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined)的更多相关文章
- Codeforces 932 A.Palindromic Supersequence (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))
占坑,明天写,想把D补出来一起写.2/20/2018 11:17:00 PM ----------------------------------------------------------我是分 ...
- ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) A
2018-02-19 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 mega ...
- Codeforces 932 C.Permutation Cycle-数学 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))
C. Permutation Cycle time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces 932 B.Recursive Queries-前缀和 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))
B. Recursive Queries time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) D】Tree
[链接] 我是链接,点我呀:) [题意] 让你在树上找一个序列. 这个序列中a[1]=R 然后a[2],a[3]..a[d]它们满足a[2]是a[1]的祖先,a[3]是a[2]的祖先... 且w[a[ ...
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) C】 Permutation Cycle
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] p[i] = p[p[i]]一直进行下去 在1..n的排列下肯定会回到原位置的. 即最后会形成若干个环. g[i]显然等于那个环的大 ...
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) B】Recursive Queries
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写个记忆化搜索. 接近O(n)的复杂度吧 [代码] #include <bits/stdc++.h> using nam ...
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) A】 Palindromic Supersequence
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 字符串倒着加到原串右边就好 [代码] #include <bits/stdc++.h> using namespace ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀
A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- Android--View事件传递
Android--View事件传递 View事件传递首先要明白以下要素: 事件就是MotionEvent.该对象包含了传递的事件中的所有信息 事件的来源是Window(即PhoneWindow),包含 ...
- T-SQL查询高级—SQL Server索引中的碎片和填充因子
写在前面:本篇文章需要你对索引和SQL中数据的存储方式有一定了解.标题中高级两个字仅仅是因为本篇文章需要我的T-SQL进阶系列文章的一些内容作为基础. 简介 在SQL Server中,存储数据 ...
- python基础教程总结3—字典
1.字典 1.1 字典类型与序列类型的区别: 存取和访问数据的方式不同. 序列类型只用数字类型的键(从序列的开始按数值顺序索引): 映射类型可以用其他对象类型作键(如:数字.字符串.元祖,一般用字符串 ...
- 使用nodejs和Java访问远程服务器的服务
既然这篇文章用的是nodejs和Java访问远程服务器的服务,那么咱们先用另一门编程语言,SAP的ABAP(我日常工作使用得最多的编程语言)来开发一个服务吧. 这是我用ABAP编程语言实现服务的类:Z ...
- [论文理解] Connectionist Text Proposal Network
Connectionist Text Proposal Network 简介 CTPN是通过VGG16后在特征图上采用3*3窗口进行滑窗,采用与RPN类似的anchor机制,固定width而只预测an ...
- 1968: C/C++经典程序训练6---歌德巴赫猜想的证明
1968: C/C++经典程序训练6---歌德巴赫猜想的证明 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 1165 Solved: 499[Submi ...
- Problem C: 查找最大元素
Problem C: 查找最大元素 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 786 Solved: 377[Submit][Status][Web ...
- Python 求两个文本文件以行为单位的交集 并集 差集
Python 求两个文本文件以行为单位的交集 并集 差集,来代码: s1 = set(open('a.txt','r').readlines()) s2 = set(open('b.txt','r') ...
- Java中的集合Collection接口
/* 集合:集合是存储对象数据的集合容器.集合比数组的优势: 1. 集合可以存储任意类型的对象数据,数组只能存储同一种数据类型 的数据. 2. 集合的长度是会发生变化的,数组的长度是固定的.----- ...
- 汉明码(Hamming Code)原理及实现
汉明码实现原理 汉明码(Hamming Code)是广泛用于内存和磁盘纠错的编码.汉明码不仅可以用来检测转移数据时发生的错误,还可以用来修正错误.(要注意的是,汉明码只能发现和修正一位错误,对于两位或 ...