QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#792151 | #9280. New Randomized Go | bulijiojiodibuliduo# | WA | 3ms | 17468kb | C++17 | 4.1kb | 2024-11-29 01:34:20 | 2024-11-29 01:34:21 |
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=3010000;
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) {
int cc=lower_bound(x,x+3*n,r+1)-lower_bound(x,x+3*n,l);
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+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);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 16372kb
input:
4 100 0 30 50 80
output:
125000001
result:
ok 1 number(s): "125000001"
Test #2:
score: 0
Accepted
time: 0ms
memory: 17460kb
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: 2ms
memory: 17340kb
input:
6 123 1 21 41 61 81 101
output:
562500004
result:
ok 1 number(s): "562500004"
Test #4:
score: 0
Accepted
time: 3ms
memory: 17208kb
input:
1 1000 999
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 2ms
memory: 17200kb
input:
2 999 123 456
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 0ms
memory: 17116kb
input:
3 400 100 200 300
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 2ms
memory: 16048kb
input:
4 500 100 200 300 401
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 2ms
memory: 15652kb
input:
5 600 100 200 300 400 500
output:
125000001
result:
ok 1 number(s): "125000001"
Test #9:
score: 0
Accepted
time: 2ms
memory: 16660kb
input:
5 599 100 200 300 400 500
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 0ms
memory: 17396kb
input:
5 600 100 200 300 400 501
output:
562500004
result:
ok 1 number(s): "562500004"
Test #11:
score: 0
Accepted
time: 2ms
memory: 16688kb
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: 16948kb
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: 2ms
memory: 17468kb
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: 2ms
memory: 16664kb
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: 0ms
memory: 17324kb
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: 0ms
memory: 15956kb
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: 2ms
memory: 16012kb
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: 0
Accepted
time: 2ms
memory: 17180kb
input:
14 100 20 22 24 26 29 35 39 88 91 93 96 97 98 99
output:
0
result:
ok 1 number(s): "0"
Test #19:
score: 0
Accepted
time: 0ms
memory: 16792kb
input:
10 100000 83731 12 47801 73162 33421 683 68402 26623 30898 89670
output:
640625005
result:
ok 1 number(s): "640625005"
Test #20:
score: 0
Accepted
time: 0ms
memory: 17412kb
input:
11 100000 47884 60925 32913 21 40497 66832 47729 25573 14377 46665 48395
output:
982421882
result:
ok 1 number(s): "982421882"
Test #21:
score: 0
Accepted
time: 0ms
memory: 15812kb
input:
12 100000 99253 99620 99843 99325 99446 99599 99331 99100 99219 99725 99605 99969
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 0ms
memory: 16860kb
input:
12 100000 36870 28725 62550 55973 55233 42504 27024 51420 71272 25000 30760 53628
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 2ms
memory: 16088kb
input:
13 100000 36464 14518 35422 804 30649 0 34318 20786 31607 38386 6204 37309 823
output:
0
result:
ok 1 number(s): "0"
Test #24:
score: 0
Accepted
time: 2ms
memory: 16144kb
input:
13 100000 81842 59901 98543 84145 94775 75783 90529 66356 92049 50000 81399 76436 53816
output:
0
result:
ok 1 number(s): "0"
Test #25:
score: 0
Accepted
time: 0ms
memory: 15824kb
input:
14 100000 29275 86103 27224 34970 39991 20000 20737 36082 94417 99598 97862 23565 24511 88214
output:
0
result:
ok 1 number(s): "0"
Test #26:
score: -100
Wrong Answer
time: 2ms
memory: 16240kb
input:
10 1000000000 139226232 668475559 922085044 220091782 123456 818628396 44036125 553403492 812857650 839136426
output:
210187658
result:
wrong answer 1st numbers differ - expected: '839843756', found: '210187658'