Codeforces Round #525(Div.2) A-D

A:

题解:

  可以for循环o(n2)的跑,满足题意描述则输出。

  也可以看出性质当n=1时不存在,n大于1时a=n,b=n即可

A. Ehab and another construction problem

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Given an integer xx, find 2 integers aa and bb such that:

  • 1≤a,b≤x1≤a,b≤x
  • bb divides aa (aa is divisible by bb).
  • a⋅b>xa⋅b>x.
  • ab<xab<x.

Input

The only line contains the integer xx (1≤x≤100)(1≤x≤100).

 

Output

You should output two integers aa and bb, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes).

Examples

input

Copy

10

output

Copy

6 3

input

Copy

1

output

Copy

-1
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f3f
const int N=3e5+7;
const long long mod=1e9+7;
char str[N];
int main(){
    int n;
    scanf("%d",&n);
    if(n>=4){
        if(n%2==0) printf("%d 2\n",n);
        else printf("%d 2\n",n-1);
    }
    else {
        if(n==1) printf("-1\n");
        else printf("2 2\n");
    }

    return 0;
}

B:

题解:

先将数组sort排序,之后标记一个tmp记录数组已经减过的值(初始化为0),然后从小到大遍历若a [i]-tmp<=0则continue 否则将tmp+=(a[i]-tmp) 并将该数输出。在遍历过程中若m用完则跳出 没用完则在最后补上相应的0.

B. Ehab and subtraction

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You're given an array aa. You should repeat the following operation kk times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0.

Input

The first line contains integers nn and kk (1≤n,k≤105)(1≤n,k≤105), the length of the array and the number of operations you should perform.

The second line contains nn space-separated integers a1,a2,…,ana1,a2,…,an (1≤ai≤109)(1≤ai≤109), the elements of the array.

Output

Print the minimum non-zero element before each operation in a new line.

Examples

input

Copy

3 5
1 2 3

output

Copy

1
1
1
0
0

input

Copy

4 2
10 3 5 3

output

Copy

3
2

Note

In the first sample:

In the first step: the array is [1,2,3][1,2,3], so the minimum non-zero element is 1.

In the second step: the array is [0,1,2][0,1,2], so the minimum non-zero element is 1.

In the third step: the array is [0,0,1][0,0,1], so the minimum non-zero element is 1.

In the fourth and fifth step: the array is [0,0,0][0,0,0], so we printed 0.

In the second sample:

In the first step: the array is [10,3,5,3][10,3,5,3], so the minimum non-zero element is 3.

In the second step: the array is [7,0,2,0][7,0,2,0], so the minimum non-zero element is 2.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f3f
const long long mod=1e9+7;
long long a[200000];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a+1,a+1+n);
    long long tmp=0;
    for(int i=1;i<=n;i++){
        if(a[i]-tmp<=0) continue;
        printf("%lld\n",a[i]-tmp);
        tmp+=(a[i]-tmp);
        m--;
        if(m==0) return 0;
    }
    while(m--){
        printf("0\n");
    }
    return 0;
}

C:

题解:

构造题,只能进行n+1次操作且只能加或者模,因为x最大1e6,而ai最大1e5.所以可以自然的想到先将所有的数都加到一个大数,然后再逐个取模,因为一个很小的数模上一个很大的数不影响结果,所以可以从头往后进行且不影响之前取模的值。

取模操作为2 i a[i]+MAX-i 这样取模后的值就等于i了

C. Ehab and a 2-operation task

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You're given an array aa of length nn. You can perform the following operations on it:

  • choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (0≤x≤106)(0≤x≤106), and replace ajaj with aj+xaj+x for all (1≤j≤i)(1≤j≤i), which means add xxto all the elements in the prefix ending at ii.
  • choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (1≤x≤106)(1≤x≤106), and replace ajaj with aj%xaj%x for all (1≤j≤i)(1≤j≤i), which means replace every element in the prefix ending at ii with the remainder after dividing it by xx.

Can you make the array strictly increasing in no more than n+1n+1 operations?

Input

The first line contains an integer nn (1≤n≤2000)(1≤n≤2000), the number of elements in the array aa.

The second line contains nn space-separated integers a1a1, a2a2, ……, anan (0≤ai≤105)(0≤ai≤105), the elements of the array aa.

Output

On the first line, print the number of operations you wish to perform. On the next lines, you should print the operations.

To print an adding operation, use the format "11 ii xx"; to print a modding operation, use the format "22 ii xx". If ii or xx don't satisfy the limitations above, or you use more than n+1n+1 operations, you'll get wrong answer verdict.

Examples

input

Copy

3
1 2 3

output

Copy

0

input

Copy

3
7 6 3

output

Copy

2
1 1 1
2 2 4

Note

In the first sample, the array is already increasing so we don't need any operations.

In the second sample:

In the first step: the array becomes [8,6,3][8,6,3].

In the second step: the array becomes [0,2,3][0,2,3].

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f3f
const long long mod=1e9+7;
int a[3000];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    printf("%d\n",n+1);
    printf("1 %d 500000\n",n);
    for(int i=1;i<=n;i++){
        printf("2 %d %d\n",i,a[i]+500000-i);
    }
    return 0;
}

D:

题解:

从题目给的62次查询可以想到遍历这30位数,每个位进行2次查询来确定关系。

之后我们可以想到当1-i的大小确定的时候 对于第i位的判断只要进行最多2次即可。

首先我们将i+1至n的位做清0处理(即xor其本身)

在已知该1-i的大小若对该位两数都对1xor如果大小改变则a b在该位上有且只有一个为1且无需另加操作即可判断。

但此时我们需要更新1-(i-1)的大小关系。

若关系相等则必定都为1或者必定都为0,且1-i的大小关系必定与1-(i-1)的关系一样。

这样刚好两次就可以判断出一个位上的数

题面:

D. Ehab and another another xor problem

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

This is an interactive problem!

Ehab plays a game with Laggy. Ehab has 2 hidden integers (a,b)(a,b). Laggy can ask a pair of integers (c,d)(c,d) and Ehab will reply with:

  • 1 if a⊕c>b⊕da⊕c>b⊕d.
  • 0 if a⊕c=b⊕da⊕c=b⊕d.
  • -1 if a⊕c<b⊕da⊕c<b⊕d.

Operation a⊕ba⊕b is the bitwise-xor operation of two numbers aa and bb.

Laggy should guess (a,b)(a,b) with at most 62 questions. You'll play this game. You're Laggy and the interactor is Ehab.

It's guaranteed that 0≤a,b<2300≤a,b<230.

Input

See the interaction section.

Output

To print the answer, print "! a b" (without quotes). Don't forget to flush the output after printing the answer.

Interaction

To ask a question, print "? c d" (without quotes). Both cc and dd must be non-negative integers less than 230230. Don't forget to flush the output after printing any question.

After each question, you should read the answer as mentioned in the legend. If the interactor replies with -2, that means you asked more than 62 queries and your program should terminate.

To flush the output, you can use:-

  • fflush(stdout) in C++.
  • System.out.flush() in Java.
  • stdout.flush() in Python.
  • flush(output) in Pascal.
  • See the documentation for other languages.

Hacking:

To hack someone, print the 2 space-separated integers aa and bb (0≤a,b<230)(0≤a,b<230).

Example

input

Copy

1
-1
0

output

Copy

? 2 1
? 1 2
? 2 0
! 3 1

Note

In the sample:

The hidden numbers are a=3a=3 and b=1b=1.

In the first query: 3⊕2=13⊕2=1 and 1⊕1=01⊕1=0, so the answer is 1.

In the second query: 3⊕1=23⊕1=2 and 1⊕2=31⊕2=3, so the answer is -1.

In the third query: 3⊕2=13⊕2=1 and 1⊕0=11⊕0=1, so the answer is 0.

Then, we printed the answer.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f3f
const long long mod=1e9+7;
int que[100];
int main(){
    int n;
    int tot=0;
    int mark,ti;
    int a=0,b=0;
    printf("? 0 0\n");
    fflush(stdout);
    scanf("%d",&n);
    mark=n;
    if(mark==0){
        for(int i=29;i>=0;i--){
            printf("? %d %d\n",(1<<i),0);
            fflush(stdout);
            scanf("%d",&n);
            if(n==-1) {
                a+=(1<<i);
                b+=(1<<i);
            }
        }
    }
    else {
        for(int i=29;i>=0;i--){
            printf("? %d %d\n",a+(1<<i),b+(1<<i));
            fflush(stdout);
            scanf("%d",&n);
            if(n==0){
                printf("? %d %d\n",a+(1<<i),b);
                fflush(stdout);
                scanf("%d",&n);
                if(n==-1) {
                    a+=(1<<i);
                    b+=(1<<i);
                }
            }
            else {
                if(mark!=n){
                    if(n==1) b+=(1<<i);
                    else a+=(1<<i);
                    printf("? %d %d\n",a,b);
                    fflush(stdout);
                    scanf("%d",&n);
                    mark=n;
                }
                else {
                    printf("? %d %d\n",a+(1<<i),b);
                    fflush(stdout);
                    scanf("%d",&n);
                    if(n==-1) {
                        b+=(1<<i);
                        a+=(1<<i);
                    }
                }
            }
        }
    }
    printf("! %d %d\n",a,b);
    fflush(stdout);
    return 0;
}

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值