QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#544938#9220. Bus AnalysisXY_ElevenTL 426ms255988kbC++238.0kb2024-09-02 21:08:322024-09-02 21:08:32

Judging History

你现在查看的是最新测评结果

  • [2024-09-02 21:08:32]
  • 评测
  • 测评结果:TL
  • 用时:426ms
  • 内存:255988kb
  • [2024-09-02 21:08:32]
  • 提交

answer

#include <bits/stdc++.h>
// #include <windows.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int> 
#define pli pair<LL,int> 
#define vct vector 
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
// cLL mod=998244353,G=404;
cLL mod=1000000007ll;
// cLL mod[2]={1686688681ll,1888686661ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }
void main_init()
{

}
cint N=1020,D1=20,D2=75,inf=1.1e9;
int n;
int a[N],nxt[N],nxt2[N];
#define ht gp_hash_table
struct Node
{
    LL x,y;
    friend Node operator + (Node w1,int w2)
    {
        w1.y=(w1.y+w1.x*w2)%mod;
        return w1;
    }
    friend void operator += (Node &w1,Node w2)
    {
        w1.x+=w2.x; if(w1.x>=mod) w1.x-=mod;
        w1.y+=w2.y; if(w1.y>=mod) w1.y-=mod;
    }
    friend void operator -= (Node &w1,Node w2)
    {
        w1.x-=w2.x; if(w1.x<0ll) w1.x+=mod;
        w1.y-=w2.y; if(w1.y<0ll) w1.y+=mod;
    }
};
ht<int,ht<int,ht<int,Node>>> dp[N],sum1[N],sum2[N];
Node get(ht<int,ht<int,ht<int,Node>>> &d,int k1,int k2,int k3)
{
    if(d.find(k1)==d.end()||d[k1].find(k2)==d[k1].end()||d[k1][k2].find(k3)==d[k1][k2].end()) return {0ll,0ll};
    return d[k1][k2][k3];
}
void main_solve()
{
    inint(n); For(i,1,n) inint(a[i]);
    // n=1000; For(i,1,n) a[i]=i*3;
    a[n+1]=inf;
    for(int i=1,j=1;i<=n;i++)
    {
        while(j<n&&a[j+1]-a[i]<D1) j++;
        nxt[i]=j;
    }
    for(int i=1,j=1;i<=n;i++)
    {
        while(j<n&&a[j+1]-a[i]<D2) j++;
        nxt2[i]=j;
    }
    a[0]=-D2-1;
    dp[0][0][0][0]={1ll,0ll};
    For(i,0,n)
    {
        for(auto [k1,sum12]:sum1[i]) for(auto [k2,sum13]:sum12) for(auto [k3,w]:sum13)
            dp[i][k1][k2][k3]+=w;
        for(auto [k1,sum22]:sum2[i]) for(auto [k2,sum23]:sum22) for(auto [k3,w]:sum23)
            dp[i][k1][k2][k3]+=w;
        for(auto [k1,dp2]:dp[i]) for(auto [k2,dp3]:dp2) for(auto [k3,w]:dp3)
        {
            vct <int> h; h.pb(i),h.pb(nxt[k1]),h.pb(nxt2[k1]),h.pb(nxt2[k2]),h.pb(nxt2[k3]),h.pb(n);
            sort(all(h)); h.erase(unique(all(h)),h.end());
            int len=sz(h);
            // printf("[%d,%d]\n",i+1,n);
            For_(j_,0,len-1)
            {
                int l=h[j_]+1,r=h[j_+1]+1;
                exc(r<=i+1);
                int t=min(
                ((a[l]-a[k1]<D1)?-1:0)+1,
                ((a[l]-a[k3]<D2)?-3:((a[l]-a[k2]<D2)?-2:((a[l]-a[k1]<D2)?-1:0)))+3
                );
                // printf("> [%d,%d]\n",l,r-1);
                int k1_=(a[l]-a[k1]>=D2?0:k1),k2_=(a[l]-a[k2]>=D2?0:k2),k3_=(a[l]-a[k3]>=D2?0:k3);
                // For_(j,l,r)
                // {
                //     // printf("%d(%d,%d,%d) %d->%d\n",i,k1,k2,k3,x,x2);
                //     // assert(x2>=0);
                //     if(!t) dp[j][k1_][k2_][k3_]+=w;
                //     else dp[j][j][k1_][k2_]+=(w+t);
                // }
                if(!t)
                {
                    sum1[l][k1_][k2_][k3_]+=w;
                    sum1[r][k1_][k2_][k3_]-=w;
                }
                else
                {
                    sum2[l][l][k1_][k2_]+=(w+t);
                    sum2[r][r][k1_][k2_]-=(w+t);
                }
            }
            /*For(j,i+1,n)
            {
                int t=min(
                ((a[j]-a[k1]<D1)?-1:0)+1,
                ((a[j]-a[k3]<D2)?-3:((a[j]-a[k2]<D2)?-2:((a[j]-a[k1]<D2)?-1:0)))+3
                );
                // printf("%d(%d,%d,%d) %d->%d\n",i,k1,k2,k3,x,x2);
                // assert(x2>=0);
                if(!t) dp[j][a[j]-a[k1]>=D2?0:k1][a[j]-a[k2]>=D2?0:k2][a[j]-a[k3]>=D2?0:k3]+=w;
                else dp[j][j][a[j]-a[k1]>=D2?0:k1][a[j]-a[k2]>=D2?0:k2]+=(w+t);
            }*/
        }
        for(auto [k1,sum12]:sum1[i]) for(auto [k2,sum13]:sum12) for(auto [k3,w]:sum13)
            if(w.x||w.y) sum1[i+1][k1][k2][k3]+=w;
        for(auto [k1,sum22]:sum2[i]) for(auto [k2,sum23]:sum22) for(auto [k3,w]:sum23)
            if(w.x||w.y) sum2[i+1][k1+1][k2][k3]+=w;
    }
    LL ans=0ll;
    For(i,0,n) for(auto [k1,dp2]:dp[i]) for(auto [k2,dp3]:dp2) for(auto [k3,w]:dp3)
    {
        // printf("%d;%d,%d,%d : %lld,%lld\n",w.x,w.y);
        add(ans,w.y);
    }
    outll(ans*2ll%mod);
}
int main()
{
    // ios::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // srand(time(NULL));
    main_init();
    // int _; inint(_); For(__,1,_) // T>1 ?
        // printf("\n------------\n\n"),
        main_solve();
    return 0;
}
/*
D:\OI\code\untitled3.cpp:113:60: error:
no matching function for call to
'get(__gnu_pbds::gp_hash_table<int, __gnu_pbds::gp_hash_table<int, __gnu_pbds::gp_hash_table<int, Node> > >&, std::tuple_element<0, std::pair<const int, __gnu_pbds::gp_hash_table<int, __gnu_pbds::gp_hash_table<int, Node> > > >::type&, std::tuple_element<0, std::pair<const int, __gnu_pbds::gp_hash_table<int, Node> > >::type&, std::tuple_element<0, std::pair<const int, Node> >::type&)'
                 sum1[i][k1][k2][k3]+=get(sum1[i-1],k1,k2,k3);
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7084kb

input:

3
1 8 20

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: 0
Accepted
time: 2ms
memory: 7144kb

input:

5
25 45 65 85 1000000000

output:

156

result:

ok 1 number(s): "156"

Test #3:

score: 0
Accepted
time: 426ms
memory: 255988kb

input:

1000
2 7 9 12 14 17 18 21 22 28 29 33 34 35 37 38 44 45 46 50 58 59 63 66 71 72 75 76 77 78 80 81 83 84 87 92 100 101 107 108 109 112 114 116 118 123 124 131 142 143 144 145 148 150 151 152 153 155 157 158 165 167 168 169 171 176 182 185 190 192 198 202 204 205 212 213 223 224 225 226 229 231 240 24...

output:

932594593

result:

ok 1 number(s): "932594593"

Test #4:

score: 0
Accepted
time: 181ms
memory: 100852kb

input:

200
1 2 4 9 10 11 12 15 16 17 18 19 22 24 27 28 33 36 37 39 43 44 45 47 48 49 50 51 52 56 60 61 62 63 68 70 71 72 73 74 78 80 81 84 86 92 93 98 99 100 102 105 107 108 110 111 114 115 116 122 123 125 129 132 133 135 137 138 139 141 142 143 144 149 150 151 152 153 154 155 159 160 165 171 172 174 176 1...

output:

422301620

result:

ok 1 number(s): "422301620"

Test #5:

score: 0
Accepted
time: 18ms
memory: 17992kb

input:

1000
999975020 999975030 999975050 999975056 999975085 999975118 999975207 999975213 999975240 999975307 999975332 999975344 999975356 999975384 999975405 999975468 999975499 999975558 999975559 999975571 999975631 999975664 999975680 999975689 999975731 999975738 999975765 999975831 999975838 99997...

output:

335758758

result:

ok 1 number(s): "335758758"

Test #6:

score: 0
Accepted
time: 0ms
memory: 7216kb

input:

3
1 8 20

output:

14

result:

ok 1 number(s): "14"

Test #7:

score: 0
Accepted
time: 0ms
memory: 12200kb

input:

1000
214 216 381 497 539 645 772 927 1211 1238 1239 1298 1403 1426 1437 1504 1515 1648 1800 1816 1946 2008 2038 2066 2144 2173 2236 2253 2291 2574 2632 2643 2658 2671 2689 2886 2910 2948 3002 3033 3039 3057 3077 3188 3240 3322 3331 3449 3467 3578 3730 3796 3897 3973 4152 4160 4199 4331 4386 4429 465...

output:

877690181

result:

ok 1 number(s): "877690181"

Test #8:

score: 0
Accepted
time: 2ms
memory: 7140kb

input:

1
963837006

output:

2

result:

ok 1 number(s): "2"

Test #9:

score: 0
Accepted
time: 9ms
memory: 12748kb

input:

999
17 234 337 379 449 607 646 703 716 878 887 898 901 942 964 1075 1198 1356 1432 1546 1547 1619 1668 1769 1818 1826 1881 1900 1960 2017 2088 2266 2273 2339 2376 2377 2396 2399 2438 2461 2484 2567 2620 2661 2680 2791 2881 3040 3081 3082 3094 3102 3205 3218 3225 3227 3239 3250 3331 3393 3425 3530 35...

output:

651884156

result:

ok 1 number(s): "651884156"

Test #10:

score: -100
Time Limit Exceeded

input:

1000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...

output:


result: