QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#71771 | #2020. 微信步数 | He_Ren | 85 | 608ms | 279128kb | C++14 | 3.4kb | 2023-01-12 01:05:27 | 2023-01-12 01:05:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 5e5 + 5;
const int MAXM = 10 + 5;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
inline void add_mod(int &a,int b){ a+=b; if(a>=mod) a-=mod;}
inline int mod_add(int a,int b){ return a+b>=mod? a+b-mod: a+b;}
inline ll pw(ll a,ll b)
{
ll res = 1;
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod; b>>=1;
}
return res;
}
inline vector<int> mul(const vector<int> &A,const vector<int> &B)
{
if(!A.size() || !B.size()) return {};
vector<int> res((int)A.size() + (int)B.size() - 1);
for(int i=0; i<(int)A.size(); ++i)
for(int j=0; j<(int)B.size(); ++j)
res[i+j] = (res[i+j] + (ll)A[i] * B[j]) %mod;
return res;
}
inline int calc_poly(const vector<int> &A,int x)
{
int res = 0;
for(int i=0, cur=1; i<(int)A.size(); ++i)
res = (res + (ll)A[i] * cur) %mod,
cur = (ll)cur * x %mod;
return res;
}
inline int interpolation(const vector<int> &ys,ll x)
{
x %= mod;
int n = (int)ys.size(), res = 0;
for(int i=0; i<n; ++i)
{
int cur = 1;
for(int j=0; j<n; ++j)
if(j != i) cur = (ll)cur * (i-j) %mod;
cur = pw(cur, mod-2) * ys[i] %mod;
for(int j=0; j<n; ++j)
if(j != i) cur = (ll)cur * (x-j) %mod;
res = (res + cur) %mod;
}
add_mod(res, mod);
return res;
}
int a[MAXM];
int c[MAXN * 3], d[MAXN * 3];
int mn[MAXN * 3][MAXM], mx[MAXN * 3][MAXM];
int len[MAXN * 3][MAXM];
int main(void)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1; i<=m; ++i) scanf("%d",&a[i]);
for(int i=1; i<=n; ++i) scanf("%d%d",&c[i],&d[i]);
ll lim = linf;
for(int i=1; i<=n; ++i)
c[i+n] = c[i+2*n] = c[i],
d[i+n] = d[i+2*n] = d[i];
vector<int> cx(m+1);
for(int i=1; i<=3*n; ++i)
{
cx[c[i]] += d[i];
for(int j=1; j<=m; ++j)
{
mn[i][j] = min(mn[i-1][j], cx[j]);
mx[i][j] = max(mx[i-1][j], cx[j]);
len[i][j] = a[j] - (mx[i][j] - mn[i][j] + 1) + 1;
if(len[i][j] <= 0) lim = min(lim, (ll)i);
}
}
auto getsiz = [&] (int i,ll k)
{
ll cmn = k / (3*n) * cx[i] + mn[k % (3*n)][i];
ll cmx = k / (3*n) * cx[i] + mx[k % (3*n)][i];
cmn = min(cmn, (ll)mn[n][i]);
cmx = max(cmx, (ll)mx[n][i]);
return cmx - cmn + 1;
};
if(lim == linf)
{
for(int i=1; i<=m; ++i) if(cx[i])
{
ll l = 3 * n, r = (ll)a[i] * n + 5;
if(getsiz(i, r) <= a[i]) continue;
while(l<r)
{
ll mid = (l+r)>>1;
if(getsiz(i, mid) <= a[i]) l = mid+1;
else r = mid;
}
lim = min(lim, l);
}
}
if(lim == linf)
{
printf("-1");
return 0;
}
int ans = 0;
for(int i=1; i<=n; ++i) if(i <= lim)
{
auto get = [&] (int a0,int a1)
{
add_mod(a0 %= mod, mod); add_mod(a1 %= mod, mod);
int _k = mod_add(a1 - a0, mod);
return vector<int>{a0, _k};
};
ll t = (lim - i) / n + 1;
int fir = 1;
for(int j=1; j<=m; ++j)
fir = (ll)fir * len[i][j] %mod;
add_mod(ans, fir);
if(t == 1) continue;
vector<int> p = {1};
for(int j=1; j<=m; ++j)
p = mul(p, get(len[i+n][j], len[i+2*n][j]));
int sum = 0;
vector<int> ys(m+2);
for(int j=0; j<m+2; ++j)
{
add_mod(sum, calc_poly(p, j));
ys[j] = sum;
}
add_mod(ans, interpolation(ys, t - 2));
}
int tot = 1;
for(int i=1; i<=m; ++i) tot = (ll)tot * a[i] %mod;
ans = (ans + tot) %mod;
printf("%d",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 2ms
memory: 3740kb
input:
5 5 2 2 1 3 3 1 1 2 -1 1 1 5 -1 5 1
output:
63
result:
ok 1 number(s): "63"
Test #2:
score: 5
Accepted
time: 2ms
memory: 3668kb
input:
5 5 2 2 2 3 2 5 -1 5 1 2 1 2 1 5 1
output:
108
result:
ok 1 number(s): "108"
Test #3:
score: 5
Accepted
time: 2ms
memory: 3736kb
input:
5 5 3 3 1 3 2 4 1 4 -1 1 -1 3 -1 2 1
output:
150
result:
ok 1 number(s): "150"
Test #4:
score: 5
Accepted
time: 2ms
memory: 3652kb
input:
100 3 8 7 6 1 1 1 -1 3 1 3 -1 3 1 3 -1 3 1 3 -1 1 1 1 -1 1 1 1 -1 2 1 2 -1 1 1 1 -1 2 1 2 -1 3 1 3 -1 3 1 3 -1 3 1 3 -1 2 1 2 -1 3 1 3 -1 3 1 3 -1 1 1 1 -1 1 1 1 -1 3 1 3 -1 3 1 3 -1 1 1 1 -1 1 1 1 -1 2 1 2 -1 1 1 1 -1 2 1 2 -1 2 1 2 -1 2 1 2 -1 3 1 3 -1 1 1 1 -1 3 1 3 -1 3 1 3 -1 3 1 3 -1 3 1 3 -1 ...
output:
-1
result:
ok 1 number(s): "-1"
Test #5:
score: 5
Accepted
time: 2ms
memory: 3684kb
input:
100 3 6 7 5 1 1 2 1 3 1 2 -1 2 -1 3 -1 3 -1 2 -1 3 1 2 -1 2 -1 2 1 1 -1 1 1 2 -1 2 -1 2 1 3 -1 3 -1 1 -1 2 1 3 -1 3 -1 1 -1 3 1 3 1 1 1 3 -1 1 1 1 1 1 -1 1 1 3 1 2 -1 2 1 2 1 1 -1 2 1 1 -1 2 1 3 -1 2 -1 1 -1 3 1 1 -1 2 1 2 -1 1 -1 2 1 2 -1 3 -1 1 1 3 -1 1 1 1 -1 3 1 1 1 2 1 3 1 2 1 2 1 2 -1 2 1 3 1 ...
output:
1445
result:
ok 1 number(s): "1445"
Test #6:
score: 5
Accepted
time: 1ms
memory: 3688kb
input:
100 3 5 7 6 3 1 1 1 2 -1 2 -1 2 1 2 1 1 1 1 -1 2 1 2 -1 3 1 2 1 3 -1 2 -1 1 1 1 -1 1 -1 3 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 3 -1 3 1 3 1 3 1 2 1 3 1 3 -1 3 -1 3 1 2 1 1 -1 1 1 1 1 3 -1 1 -1 3 -1 3 -1 2 1 2 1 3 -1 2 -1 2 -1 3 -1 1 1 1 -1 1 -1 3 1 2 -1 2 1 3 -1 1 -1 2 1 2 -1 1 -1 1 -1 2 1 3 -1 1 1 3 1...
output:
1823
result:
ok 1 number(s): "1823"
Test #7:
score: 5
Accepted
time: 73ms
memory: 58872kb
input:
100000 1 84020 1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 1 1 -1 1 1 1 -1 1 1 1 1 1 1 1 -1 1 -1 1 1 1 1 1 -1 1 1 1 -1 1 -1 1 1 1 1 1 -1 1 1 1 1 1 1 1 -1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 1 1 -1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 -1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 1 1 1 1...
output:
333173136
result:
ok 1 number(s): "333173136"
Test #8:
score: 5
Accepted
time: 70ms
memory: 58716kb
input:
100000 1 74078 1 -1 1 1 1 1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 -1 1 -1 1 -1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 1 1 -1 1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 1 1 1 -1 1 -1 1 1 ...
output:
453472675
result:
ok 1 number(s): "453472675"
Test #9:
score: 5
Accepted
time: 85ms
memory: 58716kb
input:
100000 2 788727 548098 1 -1 2 1 2 -1 2 1 1 -1 1 1 2 -1 2 -1 1 -1 2 1 2 -1 2 1 2 -1 1 -1 2 -1 2 1 1 -1 2 1 1 -1 1 -1 1 1 1 -1 1 -1 2 -1 1 1 1 -1 2 1 2 1 1 -1 1 1 1 -1 1 1 2 -1 2 -1 1 -1 2 -1 2 1 2 -1 2 -1 2 -1 1 -1 2 -1 2 1 2 1 1 1 1 1 2 1 1 -1 2 -1 2 1 1 -1 1 -1 1 -1 2 -1 1 1 1 -1 1 1 2 1 2 1 1 1 1 ...
output:
433871022
result:
ok 1 number(s): "433871022"
Test #10:
score: 5
Accepted
time: 91ms
memory: 58720kb
input:
100000 2 851838 526074 1 1 1 1 1 1 1 -1 2 -1 2 -1 1 1 2 1 2 1 2 1 2 1 1 1 1 -1 2 1 1 1 2 1 1 -1 2 -1 1 -1 2 1 2 1 2 -1 1 -1 2 -1 2 -1 2 -1 1 -1 2 -1 2 1 2 -1 2 1 2 -1 2 -1 2 1 2 1 2 -1 2 -1 1 -1 2 -1 1 -1 1 -1 1 -1 2 1 1 -1 1 1 2 -1 2 -1 1 1 2 1 2 -1 2 1 1 -1 2 -1 1 1 2 1 2 -1 1 -1 1 -1 1 1 2 -1 2 1...
output:
635878930
result:
ok 1 number(s): "635878930"
Test #11:
score: 5
Accepted
time: 86ms
memory: 58720kb
input:
100000 2 936902 869936 1 -1 1 -1 1 -1 2 -1 2 1 1 -1 2 1 2 1 2 -1 1 1 2 -1 2 -1 1 -1 2 -1 1 -1 1 -1 1 -1 2 -1 2 1 2 1 2 -1 2 -1 2 1 1 1 1 -1 1 -1 2 -1 1 -1 2 -1 1 -1 2 -1 1 -1 2 1 2 -1 1 -1 2 1 2 1 1 1 1 -1 1 1 2 -1 2 1 2 -1 2 -1 1 -1 2 1 1 1 1 1 1 1 1 -1 2 1 2 1 1 -1 1 -1 2 -1 2 -1 2 1 1 1 2 -1 1 -1...
output:
442317474
result:
ok 1 number(s): "442317474"
Test #12:
score: 5
Accepted
time: 92ms
memory: 58836kb
input:
100000 2 696105 696736 2 1 1 -1 1 -1 1 1 1 1 1 -1 1 -1 2 1 2 -1 2 -1 1 -1 1 1 1 -1 2 1 2 -1 1 1 2 -1 1 -1 1 -1 1 1 1 -1 2 -1 1 1 2 1 1 1 1 -1 1 1 1 -1 2 1 1 -1 2 1 1 1 1 1 2 -1 1 -1 2 1 1 1 1 -1 2 1 1 -1 2 1 2 1 1 -1 1 -1 1 -1 2 1 2 1 2 1 1 -1 1 1 2 1 2 -1 2 -1 2 -1 2 -1 2 -1 2 1 1 1 2 1 2 -1 1 -1 1...
output:
564885404
result:
ok 1 number(s): "564885404"
Test #13:
score: 5
Accepted
time: 75ms
memory: 278988kb
input:
500000 10 755576 503368 607237 931815 889701 742191 594456 676526 704905 569952 9 1 9 -1 8 1 8 -1 4 1 4 -1 7 1 7 -1 3 1 3 -1 1 1 1 -1 6 1 6 -1 1 1 1 -1 10 1 10 -1 2 1 2 -1 1 1 1 -1 2 1 2 -1 5 1 5 -1 4 1 4 -1 3 1 3 -1 7 1 7 -1 3 1 3 -1 4 1 4 -1 6 1 6 -1 7 1 7 -1 4 1 4 -1 1 1 1 -1 2 1 2 -1 5 1 5 -1 6 ...
output:
-1
result:
ok 1 number(s): "-1"
Test #14:
score: 0
Time Limit Exceeded
input:
500000 10 843479 559917 806296 766435 965493 781368 889933 632099 689781 934269 3 1 10 1 3 1 3 -1 6 1 7 -1 8 1 9 1 4 1 2 -1 5 1 2 -1 5 1 8 -1 4 -1 10 -1 8 -1 7 -1 1 -1 3 -1 5 1 6 1 3 -1 6 -1 3 1 10 -1 5 1 4 1 2 1 10 -1 5 -1 4 1 5 -1 4 -1 5 -1 4 1 3 -1 8 1 5 1 3 -1 1 -1 5 1 2 -1 8 1 5 1 9 -1 4 -1 10 ...
output:
result:
Test #15:
score: 0
Time Limit Exceeded
input:
500000 10 564550 662731 907937 653446 887637 552698 501487 502890 574491 689451 8 -1 2 1 2 -1 10 -1 5 -1 10 1 9 1 8 1 6 1 6 1 2 -1 2 -1 9 -1 1 -1 9 -1 7 -1 8 1 9 -1 9 1 9 -1 6 1 10 1 1 -1 8 -1 10 -1 10 1 7 1 4 1 6 1 1 -1 2 -1 2 1 5 -1 2 -1 7 1 5 -1 8 -1 5 1 7 -1 2 -1 3 1 9 1 3 -1 7 1 8 1 5 -1 1 1 6 ...
output:
result:
Test #16:
score: 0
Time Limit Exceeded
input:
500000 10 918488 957499 964399 900665 976079 674192 501308 980114 958902 545155 6 1 1 -1 1 1 9 1 1 1 5 -1 4 1 1 -1 9 -1 6 1 1 -1 6 1 10 1 5 -1 8 1 10 1 2 1 7 1 5 -1 6 -1 10 -1 1 -1 4 -1 6 -1 4 1 10 -1 10 -1 6 -1 4 -1 7 -1 4 1 6 1 6 -1 10 1 9 1 4 -1 4 1 3 -1 7 -1 1 -1 5 1 8 1 10 1 2 1 2 -1 2 1 3 1 6 ...
output:
result:
Test #17:
score: 5
Accepted
time: 608ms
memory: 279052kb
input:
500000 3 826619243 796070724 841056572 3 1 2 1 3 -1 1 -1 2 1 2 -1 1 -1 1 1 1 -1 3 1 1 -1 2 -1 3 -1 3 1 1 -1 1 1 3 -1 2 1 2 1 3 -1 2 1 2 1 1 -1 1 1 1 1 1 -1 2 1 3 -1 2 -1 2 1 3 1 1 1 1 -1 3 1 2 -1 1 -1 2 1 2 1 2 -1 3 -1 1 -1 1 -1 2 -1 3 -1 1 -1 3 -1 2 1 2 -1 3 1 1 -1 1 1 1 1 1 1 1 1 3 -1 1 1 3 1 2 1 ...
output:
953829771
result:
ok 1 number(s): "953829771"
Test #18:
score: 5
Accepted
time: 578ms
memory: 278984kb
input:
500000 3 956491428 866109891 631435277 2 1 1 -1 1 -1 3 -1 3 1 2 -1 2 1 1 -1 2 1 2 -1 1 -1 2 1 2 1 2 -1 1 1 3 1 3 -1 1 -1 1 1 1 1 3 -1 2 -1 1 1 1 1 2 -1 2 1 2 -1 2 -1 2 1 3 1 1 -1 2 -1 1 -1 2 1 3 1 1 1 3 -1 1 -1 2 -1 3 1 2 1 3 1 3 1 2 1 3 -1 1 -1 3 -1 2 1 1 1 2 1 3 -1 3 1 1 -1 3 -1 1 1 2 -1 2 -1 2 1 ...
output:
286394049
result:
ok 1 number(s): "286394049"
Test #19:
score: 5
Accepted
time: 586ms
memory: 278972kb
input:
500000 3 816766322 779617142 794227651 3 1 2 1 1 1 3 -1 2 1 2 -1 1 1 1 1 1 1 3 -1 1 -1 2 1 3 1 1 -1 1 -1 1 1 3 1 3 1 1 -1 3 -1 2 1 1 -1 2 1 3 1 1 1 2 -1 3 -1 2 -1 1 -1 3 -1 1 1 3 -1 3 1 1 -1 3 1 2 -1 2 -1 1 -1 3 1 3 1 2 -1 3 1 3 -1 1 1 1 -1 3 1 1 1 2 1 2 1 1 1 2 1 1 -1 2 1 2 -1 2 1 3 -1 3 1 1 1 3 -1...
output:
950925221
result:
ok 1 number(s): "950925221"
Test #20:
score: 5
Accepted
time: 577ms
memory: 279128kb
input:
500000 3 600925621 781710332 540983402 1 -1 1 1 2 1 3 1 1 1 1 1 3 1 3 1 2 -1 3 -1 3 1 1 -1 1 1 2 -1 1 -1 1 -1 3 -1 2 1 1 1 1 -1 1 -1 1 1 3 -1 2 -1 2 -1 3 1 1 1 1 -1 3 1 2 1 1 -1 2 1 1 -1 3 -1 3 -1 2 -1 3 -1 2 1 3 -1 1 1 2 1 2 1 3 -1 2 1 1 1 1 1 3 1 2 -1 1 1 3 1 2 -1 3 -1 3 1 2 -1 3 -1 1 1 1 1 1 -1 3...
output:
370329204
result:
ok 1 number(s): "370329204"