https://codeforces.com/contest/1114/problem/E
题意:有长为1e6的打乱排序的等差数列[1,1e9],可以询问有没有大于x的数,第i个数是多少,最多问60次,求数列
先问出最大的(30次),在问其他的(大概问30个),问出来的值和最大的相减,求所有差的gcd,应该?得到的就是公差吧?
什么?怕被hack掉?那就加一个随机,加上随机保你AC!注意,随机的1.范围一定要够大,最好覆盖全部2.取值要几乎等可能性,题目给的数列长度为1e6,我之前尝试直接用rand()(范围约为3e5),rand()*rand()+rand(),都不行,最后改成了rand()*100+rand(),才过
如果想要0~2^15(3e4)以内的,就用rand();
如果想要0~2^30以内(1e9)以内的,就用(rand()<<15)^rand()
一定要往大的选,不能往小的选
//Problem:
//Date:
//Skill:
//Bug:
/Definations/
//循环控制
#define CLR(a) memset((a),0,sizeof(a))
#define RE(i,n) for(int i=0;i<int(n);i++)
#define RE2(i,n) for(int i=1;i<=int(n);i++)
#define FOR(x,vec) for(vector<int>::iterator it=vec.begin();it!=vec.end();++it) { int &x(*it);
//输入输出
#define INC(c) do{scanf("%c",&c);}while(isspace(c))
#define ON cout<<endl
#define PII pair<int,int>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
Options//
typedef long long ll;
#define stdcpph
#define CPP_IO
#ifdef stdcpph
#include<bits/stdc++.h>
#else
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
#ifdef CPP_IO
#include<iostream>
#include<iomanip>
#include<string>
#else
#include<stdio.h>
#endif
#endif
Basic Functions//
template<typename INint>
inline void IN(INint &x)
{
x = 0; int f = 1; char c; cin.get(c);
while (c<'0' || c>'9') { if (c == '-')f = -1; cin.get(c); }
while (c >= '0'&&c <= '9') { x = x * 10 + c - '0'; cin.get(c); }
x *= f;
}
template<typename INint>
inline void OUT(INint x)
{
if (x > 9)OUT(x / 10);
cout.put(x % 10 + '0');
}
Added Functions//
//How to think:
//先认真读题,把题目逻辑化,读清全部条件,再做,不然,哼哼
//写题的时候遇到的一些”莫名“的错误大部分是自己的代码写错了一个变量
//1.分治 2.容斥 3.化多元为单元
//4.dp 分阶段,后阶段受前阶段的影响
//5.凡是有很大的指数的,都可以先用log算一下
//6.预处理,作用非常大,很快
//
//1.Do you use cout/cin? Do not use!
//2.what's the maximum Int data? Is it beyond I32d?
//3.Ever Mod after neccesary caEdlculation?
//4.Ever Cleaned the array before using?
const int maxn = int(100);
ll gcd(ll a, ll b)
{
if (b)return gcd(b, a%b);
else return a;
}
int ran(int a, int b)
{
return ((rand()*1000)+rand()) % (b - a + 1) + a;
}
Code/
int main()
{
//freopen("C:\\Users\\VULCAN\\Desktop\\data.in", "r", stdin);
int T(1), times(0);
#ifdef CPP_IO// CPP_IO
//std::ios::sync_with_stdio(false);
//cin.tie(0); cout.tie(0);
//cin >> T;
#else
//IN(T);
#endif
/
while (++times, T--)
{
ll n; cin >> n;
ll le(-1), ri(1e9 + 4);
ll t(0);
while (ri != le + 1)
{
ll mid = (le + ri) >> 1;
cout << "> " <<mid << endl;
cout.flush();
bool bigger; cin >> bigger;
if (bigger)le = mid;
else ri = mid;
++t;
}
ll R = ri;
ll g;
srand(ll(time(0)));
for (ll i = 1; i + t <= 60; ++i)
{
cout << "? " << (ran(1,n)) << endl;
cout.flush();
ll a; cin >> a;
if (i == 1)g = (R - a);
if (i != 1)g = gcd(g, R - a);
}
cout << "! " << R-g*(n-1) << ' ' << g << endl;
cout.flush();
}
/
return 0;
}