QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#792150 | #9280. New Randomized Go | bulijiojiodibuliduo# | WA | 3ms | 13792kb | C++17 | 4.2kb | 2024-11-29 01:31:40 | 2024-11-29 01:31:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
template<int MOD, int RT> struct mint {
static const int mod = MOD;
static constexpr mint rt() { return RT; } // primitive root for FFT
int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
mint():v(0) {}
mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
if (v < 0) v += MOD; }
bool operator==(const mint& o) const {
return v == o.v; }
friend bool operator!=(const mint& a, const mint& b) {
return !(a == b); }
friend bool operator<(const mint& a, const mint& b) {
return a.v < b.v; }
mint& operator+=(const mint& o) {
if ((v += o.v) >= MOD) v -= MOD;
return *this; }
mint& operator-=(const mint& o) {
if ((v -= o.v) < 0) v += MOD;
return *this; }
mint& operator*=(const mint& o) {
v = int((ll)v*o.v%MOD); return *this; }
mint& operator/=(const mint& o) { return (*this) *= inv(o); }
friend mint pow(mint a, ll p) {
mint ans = 1; assert(p >= 0);
for (; p; p /= 2, a *= a) if (p&1) ans *= a;
return ans; }
friend mint inv(const mint& a) { assert(a.v != 0);
return pow(a,MOD-2); }
mint operator-() const { return mint(-v); }
mint& operator++() { return *this += 1; }
mint& operator--() { return *this -= 1; }
friend mint operator+(mint a, const mint& b) { return a += b; }
friend mint operator-(mint a, const mint& b) { return a -= b; }
friend mint operator*(mint a, const mint& b) { return a *= b; }
friend mint operator/(mint a, const mint& b) { return a /= b; }
};
const int MOD=1000000007;
using mi = mint<MOD,5>; // 5 is primitive root for both common mods
namespace simp {
vector<mi> fac,ifac,invn;
void check(int x) {
if (fac.empty()) {
fac={mi(1),mi(1)};
ifac={mi(1),mi(1)};
invn={mi(0),mi(1)};
}
while (SZ(fac)<=x) {
int n=SZ(fac),m=SZ(fac)*2;
fac.resize(m);
ifac.resize(m);
invn.resize(m);
for (int i=n;i<m;i++) {
fac[i]=fac[i-1]*mi(i);
invn[i]=mi(MOD-MOD/i)*invn[MOD%i];
ifac[i]=ifac[i-1]*invn[i];
}
}
}
mi gfac(int x) {
assert(x>=0);
check(x); return fac[x];
}
mi ginv(int x) {
assert(x>0);
check(x); return invn[x];
}
mi gifac(int x) {
assert(x>=0);
check(x); return ifac[x];
}
mi binom(int n,int m) {
if (m < 0 || m > n) return mi(0);
return gfac(n)*gifac(m)*gifac(n - m);
}
mi binombf(int n,int m) {
if (m < 0 || m > n) return mi(0);
if (m>n-m) m=n-m;
mi p=1,q=1;
for (int i=1;i<=m;i++) p=p*(n+1-i),q=q*i;
return p/q;
}
}
const int N=2010000;
int n;
ll l,x[N];
mi pw[N];
mi single() {
mi ans=0;
ans+=1;
int r=0;
rep(i,0,n) {
while (x[r]<x[i]+l) r++;
//printf("%d %d\n",i,r);
ans+=pw[r-i-1];
}
//printf("? %d\n",(int)ans);
return ans;
}
int cnt(int l,int r) {
//assert(l>=0&&r<4*::l);
int cc=lower_bound(x,x+2*n,r+1)-lower_bound(x,x+2*n,l);
//rep(i,0,2*n) cc+=x[i]>=l&&x[i]<=r;
//printf("?? %d %d %d\n",l,r,cc);
return cc;
}
mi dbl() {
mi ans=0;
int r=0;
rep(i,0,n) {
while (x[r]<x[i]+l) r++;
assert(r<=i+n-1);
// r .. i+n-1 ->R
ans+=1;
ans+=pw[cnt(x[i+n-1]-l+1,x[r]-1)]-1;
ans+=pw[cnt(x[i+n-1]+1,x[r]+l-1)-(x[i+n]<x[r]+l)]-1;
}
return ans;
}
int main() {
scanf("%d%lld",&n,&l);
pw[0]=1;
rep(i,1,n+1) pw[i]=pw[i-1]*2;
rep(i,0,n) {
scanf("%lld",&x[i]);
x[i]=x[i]*2;
}
sort(x,x+n);
rep(i,0,n) x[i+n]=x[i]+2*l;
rep(i,0,n) if (x[i+n-1]-x[i]<l) {
puts("0");
return 0;
}
mi pr=pw[n]-2*single()+dbl();
pr/=pw[n];
printf("%d\n",(int)pr);
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 12188kb
input:
4 100 0 30 50 80
output:
125000001
result:
ok 1 number(s): "125000001"
Test #2:
score: 0
Accepted
time: 0ms
memory: 12836kb
input:
8 100 1 12 34 45 51 84 88 92
output:
515625004
result:
ok 1 number(s): "515625004"
Test #3:
score: 0
Accepted
time: 0ms
memory: 12080kb
input:
6 123 1 21 41 61 81 101
output:
562500004
result:
ok 1 number(s): "562500004"
Test #4:
score: 0
Accepted
time: 0ms
memory: 12148kb
input:
1 1000 999
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 12328kb
input:
2 999 123 456
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 2ms
memory: 12332kb
input:
3 400 100 200 300
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 2ms
memory: 12764kb
input:
4 500 100 200 300 401
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 0ms
memory: 12096kb
input:
5 600 100 200 300 400 500
output:
125000001
result:
ok 1 number(s): "125000001"
Test #9:
score: 0
Accepted
time: 2ms
memory: 12400kb
input:
5 599 100 200 300 400 500
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 0ms
memory: 13792kb
input:
5 600 100 200 300 400 501
output:
562500004
result:
ok 1 number(s): "562500004"
Test #11:
score: 0
Accepted
time: 3ms
memory: 13620kb
input:
6 311 2 25 87 117 251 269
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 0ms
memory: 13400kb
input:
10 49 0 7 12 13 17 19 22 28 30 38
output:
527343754
result:
ok 1 number(s): "527343754"
Test #13:
score: 0
Accepted
time: 0ms
memory: 11716kb
input:
11 39 0 1 9 15 19 21 23 25 28 37 38
output:
62500001
result:
ok 1 number(s): "62500001"
Test #14:
score: 0
Accepted
time: 3ms
memory: 13436kb
input:
12 39 10 12 15 16 20 23 24 25 26 30 31 38
output:
596679692
result:
ok 1 number(s): "596679692"
Test #15:
score: 0
Accepted
time: 3ms
memory: 12992kb
input:
12 100 25 26 29 33 36 45 46 51 53 63 72 74
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: 0
Accepted
time: 2ms
memory: 11976kb
input:
13 100 0 1 3 4 5 10 15 19 21 36 40 44 48
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 0ms
memory: 13448kb
input:
13 100 50 53 55 61 72 78 79 84 86 89 96 97 98
output:
0
result:
ok 1 number(s): "0"
Test #18:
score: -100
Wrong Answer
time: 0ms
memory: 12988kb
input:
14 100 20 22 24 26 29 35 39 88 91 93 96 97 98 99
output:
378356936
result:
wrong answer 1st numbers differ - expected: '0', found: '378356936'