靠这把上了蓝

A. Palindromic Supersequence
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

First line contains a string A (1 ≤ |A| ≤ 103) consisting of lowercase Latin letters, where |A| is a length of A.

Output

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.

Examples
input

Copy
aba
output
aba
input

Copy
ab
output
aabaa
Note

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 ;
}
B. Recursive Queries
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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 lr and k. You need to print the number of integers xbetween l and r inclusive, such that g(x) = k.

Input

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 lr and k (1 ≤ l ≤ r ≤ 106, 1 ≤ k ≤ 9).

Output

For each query, print a single line containing the answer for that query.

Examples
input

Copy
4
22 73 9
45 64 6
47 55 7
2 62 4
output
1
4
0
8
input

Copy
4
82 94 6
56 67 4
28 59 9
39 74 4
output
3
1
1
5
Note

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 ;
}
C. Permutation Cycle
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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 ≤ Ng(i) equals either A or B.

Input

The only line contains three integers N, A, B (1 ≤ N ≤ 106, 1 ≤ A, B ≤ N).

Output

If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to N.

Examples
input

Copy
9 2 5
output
6 5 8 3 4 1 9 2 7
input

Copy
3 2 1
output
1 2 3 
Note

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 ;
}
D. Tree
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

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
    1. starts with R.
    2. Every node in the sequence is an ancestor of its predecessor.
    3. Sum of weight of nodes in sequence does not exceed X.
    4. 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.

Input

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

Output the answer to each query of second type in separate line.

Examples
input

Copy
6
1 1 1
2 2 0
2 2 1
1 3 0
2 2 0
2 2 2
output
0
1
1
2
input

Copy
6
1 1 0
2 2 0
2 0 3
1 0 2
2 1 3
2 1 6
output
2
2
3
2
input

Copy
7
1 1 2
1 2 3
2 3 3
1 0 0
1 5 1
2 5 0
2 4 0
output
1
1
2
input

Copy
7
1 1 3
1 2 3
2 3 4
1 2 0
1 5 3
2 5 5
2 7 22
output
1
2
3
Note

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)的更多相关文章

  1. 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 ----------------------------------------------------------我是分 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 【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[ ...

  6. 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) C】 Permutation Cycle

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] p[i] = p[p[i]]一直进行下去 在1..n的排列下肯定会回到原位置的. 即最后会形成若干个环. g[i]显然等于那个环的大 ...

  7. 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) B】Recursive Queries

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写个记忆化搜索. 接近O(n)的复杂度吧 [代码] #include <bits/stdc++.h> using nam ...

  8. 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) A】 Palindromic Supersequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 字符串倒着加到原串右边就好 [代码] #include <bits/stdc++.h> using namespace ...

  9. 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 ...

随机推荐

  1. xcode在代码中查找中文

    总是忘记xcode中查找中文,这次记下来,以后就不会忘记了,哈哈 请看下图: 切换到查找,点击find后面的text,选择Regular Expression,然后输入 1. 查找非ascii的字符 ...

  2. eclipse的垂直选择功能

    快捷键:Alt+Shift+A切换. 光标会变成十字,就可以垂直选择了.

  3. Linux系统常用命令大全

    一.系统信息操作(备注:红色标记为常用命令,以下类推,不再赘述) arch 显示机器的处理器架构(1) uname -m   显示机器的处理器架构(2) uname -r               ...

  4. 【TensorFlow入门完全指南】模型篇·线性回归模型

    首先呢,进行import,对于日常写代码来说,第二行经常写成:import numpy as np,这样会更加简洁.第三行import用于绘图. 定义了学习率.迭代数epoch,以及展示的学习步骤,三 ...

  5. [转]maven项目部署到tomcat

    其实maven项目部署到tomcat的方式很多,我从一开始的打war包到tomcat/webapps目录,到使用tomcat-maven插件,到直接使用servers部署,一路来走过很多弯路. 下面就 ...

  6. python_84_os模块

    'os模块:提供对操作系统进行调用的接口' import os print(os.getcwd())#获取当前脚本工作目录,即当前Python脚本工作的目录路径 os.chdir('C:\\Users ...

  7. js完成打印功能

    最近在做项目要求实现打印功能,我采用js方式来实现 window.print();会弹出打印对话框,打印的是window.docunemt.body.innerHTML中的内容,可以局部打印,也可以全 ...

  8. SAP HANA

    DROP PROCEDURE ""."ZCONCAT_EKKO_EBN"; CREATE PROCEDURE ""."ZCONCA ...

  9. JAVA中文字符串编码--GBK转UTF-8

    转载自:https://www.cnblogs.com/yoyotl/p/5979200.html 一.乱码的原因 gbk的中文编码是一个汉字用[2]个字节表示,例如汉字“内部”的gbk编码16进制的 ...

  10. 反爬虫之搭建IP代理池

    反爬虫之搭建IP代理池 听说你又被封 ip 了,你要学会伪装好自己,这次说说伪装你的头部.可惜加了header请求头,加了cookie 还是被限制爬取了.这时就得祭出IP代理池!!! 下面就是requ ...