# Clarke and baton

Accepts: 14

Submissions: 79
Time Limit: 12000/6000 MS (Java/Others)

Memory Limit: 524288/524288 K (Java/Others)

克拉克是一名人格分裂患者。某一天，克拉克fork出了n个自己，序号从1到n。

第一行一个整数T(1 \le T \le 10)，表示数据的组数。

a[i]按照以下规则生成:

long long seed;
int rand(int l, int r) {
static long long mo=1e9+7, g=78125;
return l+((seed*=g)%=mo)%(r-l+1);
}

int sum=rand(q, 10000000);
for(int i=1; i<=n; i++) {
a[i]=rand(0, sum/(n-i+1));
sum-=a[i];
}
a[rand(1, n)]+=sum;

每组数据输出一行一个数，这个数ans是这样得到的。

1
3 2 1

20303
Hint
首先a[1]=20701, a[2]=31075, a[3]=26351

#pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
using namespace std;

typedef long long ll;
const int maxn = 1e7 + 1;
const int mod = 1e9 + 7;
const int G = 78125;

ll n, q, seed;
int a[10000002];
int nu[10000002];
int rand(int lll, int r)
{
static ll mo = 1e9 + 7, g = 78125;
return lll + ((seed *= g) %= mo) % (r - lll + 1);
}

int main()
{
//freopen("i.txt","r",stdin);
//freopen("o.txt","w",stdout);

int t, sum, mt, rest, res, num, cnt;
ll ans;
scanf("%d", &t);

while (t--)
{
scanf("%lld%lld%lld", &n, &q, &seed);

mt = 0;
sum = rand(q, 10000000);

for (int i = 1; i <= n; i++)
{
a[i] = rand(0, sum / (n - i + 1));
sum -= a[i];
mt = max(mt, a[i]);
}
int tmp = rand(1, n);
a[tmp] += sum;
mt = max(mt, a[tmp]);

memset(nu, 0, sizeof(nu));
for (int i = 1;i<=n; i++)
{
nu[a[i]]++;
}
num = 0;
cnt = 0;
for (int i = mt;; i--)
{
if (cnt >= q)
{
rest = q - (cnt - num);
res = i + 1;
break;
}
if (i >= 0)
{
num += nu[i];
}
cnt += num;
}
ans = 0;
for (int i = 1; i <= n; i++)
{
if (a[i] < res)
{
ans ^= (a[i] + i);
}
else
{
if (rest > 0)
{
rest--;
ans ^= (res - 1 + i);
}
else
{
ans ^= (res + i);
}
}
}
printf("%lld\n", ans);
}

//system("pause");
return 0;
}


#### hdu 5565 Clarke and baton

2016-01-28 18:57:46

#### hdu(5565)——Clarke and baton

2015-11-19 16:35:00

#### HDU 5565 Clarke and baton

2015-11-29 23:02:03

#### hdu 5565 Clarke and baton（水）

2015-11-16 18:14:06

#### HDU 5565 - Clarke and baton (思维)

2015-11-15 12:18:47

#### hdu 5467 Clarke and hunger games (lct)

2015-10-03 20:46:40

#### HDU 5628 Clarke and math（Dirchlet卷积+快速幂）

2016-09-19 10:58:11

#### HDU5626 Clarke and points

2016-02-14 14:16:48

#### 【HDU5628】Clarke and math-狄利克雷卷积+快速幂

2017-06-17 21:07:51

#### CLARKE变换

2014-09-05 16:03:12

## 不良信息举报

HDU 5565：Clarke and baton