Codeforces Round #805 (Div. 3) (A,B,C)

A. Round Down the Price

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

At the store, the salespeople want to make all prices round.

In this problem, a number that is a power of 1010 is called a round number. For example, the numbers 100=1100=1, 101=10101=10, 102=100102=100 are round numbers, but 2020, 110110 and 256256 are not round numbers.

So, if an item is worth mm bourles (the value of the item is not greater than 109109), the sellers want to change its value to the nearest round number that is not greater than mm. They ask you: by how many bourles should you decrease the value of the item to make it worth exactly 10k10k bourles, where the value of kk — is the maximum possible (kk — any non-negative integer).

For example, let the item have a value of 178178-bourles. Then the new price of the item will be 100100, and the answer will be 178−100=78178−100=78.

Input

The first line of input data contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases .

Each test case is a string containing a single integer mm (1≤m≤1091≤m≤109) — the price of the item.

Output

For each test case, output on a separate line a single integer dd (0≤d<m0≤d<m) such that if you reduce the cost of the item by dd bourles, the cost of the item will be the maximal possible round number. More formally: m−d=10km−d=10k, where kk — the maximum possible non-negative integer.

Example

input

Copy

7
1
2
178
20
999999999
9000
987654321

output

Copy

0
1
78
10
899999999
8000
887654321

Note

In the example:

  • 1−0=1001−0=100,
  • 2−1=1002−1=100,
  • 178−78=102178−78=102,
  • 20−10=10120−10=101,
  • 999999999−899999999=108999999999−899999999=108,
  • 9000−8000=1039000−8000=103,
  • 987654321−887654321=108987654321−887654321=108.

Note that in each test case, we get the maximum possible round number.

#include<bits/stdc++.h>
using namespace std;
int t,m;
int wieshu(int n)
{
	int sum=0;
	while(n)
	{
		sum++;
		n/=10;
	}
	return sum;
}
int main()
{
	cout<<int('a');
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&m);
		int ans=pow(10,wieshu(m)-1);
		printf("%d\n",m-ans);
	}
	return 0;
}

 

B. Polycarp Writes a String from Memory

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp has a poor memory. Each day he can remember no more than 33 of different letters.

Polycarp wants to write a non-empty string of ss consisting of lowercase Latin letters, taking minimum number of days. In how many days will he be able to do it?

Polycarp initially has an empty string and can only add characters to the end of that string.

For example, if Polycarp wants to write the string lollipops, he will do it in 22 days:

  • on the first day Polycarp will memorize the letters l, o, i and write lolli;
  • On the second day Polycarp will remember the letters p, o, s, add pops to the resulting line and get the line lollipops.

If Polycarp wants to write the string stringology, he will do it in 44 days:

  • in the first day will be written part str;
  • on day two will be written part ing;
  • on the third day, part of olog will be written;
  • on the fourth day, part of y will be written.

For a given string ss, print the minimum number of days it will take Polycarp to write it.

Input

The first line of input data contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.

Each test case consists of a non-empty string ss consisting of lowercase Latin letters (the length of the string ss does not exceed 2⋅1052⋅105) — the string Polycarp wants to construct.

It is guaranteed that the sum of string lengths ss over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, print a single number — minimum number of days it will take Polycarp to write the string ss from memory.

Example

input

Copy

6
lollipops
stringology
abracadabra
codeforces
test
f

output

Copy

2
4
3
4
1
1

#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int f[256];
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		cin>>s;
		string a="";
		memset(f,0,sizeof f);
		int jishu=0;
		int flag=0;
		int ans=0;
		for(int i=0;i<s.length();i++)
		{
			int xiabiao=int(s[i]);
			if(f[xiabiao]==1)
			{
				a+=s[i];
			}
			else
			{
				jishu++;
				if(jishu>3)
				{
					memset(f,0,sizeof f);
					ans++,jishu=1;
				}
				f[xiabiao]=1;
				a+=s[i];
			}
		}
		if(jishu!=0) ans++;
		//ans-=flag;
		cout<<ans<<endl;
	}
	return 0;
}

 

C. Train and Queries

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Along the railroad there are stations indexed from 11 to 109109. An express train always travels along a route consisting of nn stations with indices u1,u2,…,unu1,u2,…,un, where (1≤ui≤1091≤ui≤109). The train travels along the route from left to right. It starts at station u1u1, then stops at station u2u2, then at u3u3, and so on. Station unun — the terminus.

It is possible that the train will visit the same station more than once. That is, there may be duplicates among the values u1,u2,…,unu1,u2,…,un.

You are given kk queries, each containing two different integers ajaj and bjbj (1≤aj,bj≤1091≤aj,bj≤109). For each query, determine whether it is possible to travel by train from the station with index ajaj to the station with index bjbj.

For example, let the train route consist of 66 of stations with indices [3,7,1,5,1,43,7,1,5,1,4] and give 33 of the following queries:

  • a1=3a1=3, b1=5b1=5

    It is possible to travel from station 33 to station 55 by taking a section of the route consisting of stations [3,7,1,53,7,1,5]. Answer: YES.

  • a2=1a2=1, b2=7b2=7

    You cannot travel from station 11 to station 77 because the train cannot travel in the opposite direction. Answer: NO.

  • a3=3a3=3, b3=10b3=10

    It is not possible to travel from station 33 to station 1010 because station 1010 is not part of the train's route. Answer: NO.

Input

The first line of the input contains an integer tt (1≤t≤1041≤t≤104) —the number of test cases in the test.

The descriptions of the test cases follow.

The first line of each test case is empty.

The second line of each test case contains two integers: nn and kk (1≤n≤2⋅105,1≤k≤2⋅1051≤n≤2⋅105,1≤k≤2⋅105) —the number of stations the train route consists of and the number of queries.

The third line of each test case contains exactly nn integers u1,u2,…,unu1,u2,…,un (1≤ui≤1091≤ui≤109). The values u1,u2,…,unu1,u2,…,un are not necessarily different.

The following kk lines contain two different integers ajaj and bjbj (1≤aj,bj≤1091≤aj,bj≤109) describing the query with index jj.

It is guaranteed that the sum of nn values over all test cases in the test does not exceed 2⋅1052⋅105. Similarly, it is guaranteed that the sum of kk values over all test cases in the test also does not exceed 2⋅1052⋅105

Output

For each test case, output on a separate line:

  • YES, if you can travel by train from the station with index ajaj to the station with index bjbj
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

Example

input

Copy

3

6 3
3 7 1 5 1 4
3 5
1 7
3 10

3 3
1 2 1
2 1
1 2
4 5

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

output

Copy

YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES

Note

The first test case is explained in the problem statement.

 

 

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N];
int t,n,k,x,y;
map<int,int>mp;
struct Node
{
	int l,r;
}f[N];
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		mp.clear();
		int cnt=0;
		memset(f,0,sizeof f);
		scanf("%d%d",&n,&k);
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			if(mp[a[i]]==0)
			{
				cnt++;
				mp[a[i]]=cnt;
				f[mp[a[i]]].l=f[mp[a[i]]].r=i;
			}
			else
			{
				if(i<f[mp[a[i]]].l) f[mp[a[i]]].l=i;
				if(i>f[mp[a[i]]].r) f[mp[a[i]]].r=i;
			}
		}
		while(k--)
		{
			scanf("%d%d",&x,&y);
			if((f[mp[x]].l==0)||f[mp[y]].l==0)
				printf("NO\n");
			else if(f[mp[y]].r<f[mp[x]].l)
				printf("NO\n");
			else
				printf("YES\n");
		}
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值