QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#577803#9326. GameAfterlife#WA 25ms13860kbC++201.5kb2024-09-20 14:51:212024-09-20 14:51:23

Judging History

This is the latest submission verdict.

  • [2024-09-20 14:51:23]
  • Judged
  • Verdict: WA
  • Time: 25ms
  • Memory: 13860kb
  • [2024-09-20 14:51:21]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N=3e5+1e3+7;

int T,n,a[N],l[N],r[N],c,f[N];

int mg[N][21],g[N],mf[N][21];

int qf(int l,int r)
{
    int k=__lg(r-l+1);
    return min(mf[l][k],mf[r-(1<<k)+1][k]);
}

int qg(int l,int r)
{
    int k=__lg(r-l+1);
    return max(mg[l][k],mg[r-(1<<k)+1][k]);
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>T;
    while(T--)
    {
        cin>>n>>c;
        for(int i=1;i<=n;i++)
            cin>>l[i];
        for(int i=1;i<=n;i++)
            cin>>r[i];
        for(int i=1;i<=n;i++)
            cin>>a[i];
        multiset<int> ms;
        for(int i=n;i>=1;i--)
        {
            f[i]=-1e18;
            int L=i+l[i];
            if(i+r[i]>n)
                f[i]=0;
            if(L<=n)
            {
                if(L-(i+1)<c)
                    f[i]=max(f[i],qf(i+1,L));
                int R=min(i+r[i],n);
                L=i+1+c;
                if(L<=R)
                    f[i]=max(f[i],qg(L,R));
            }
            mf[i][0]=f[i]+a[i];
            for(int j=1;i+(1<<j)-1<=n;j++)
                mf[i][j]=min(mf[i][j-1],mf[i+(1<<(j-1))][j-1]);
            if(i+c<=n)
            {
                int p=i+c;
                mg[p][0]=qf(i,p);
                for(int j=1;p+(1<<j)-1<=n;j++)
                    mg[p][j]=max(mg[p][j-1],mg[p+(1<<(j-1))][j-1]);
            }
        }
        cout<<f[1]<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
6 2
1 1 2 2 1 1
2 1 3 2 1 1
2 3 1 -1 -1 1
4 4
1 1 1 1
2 2 1 1
-1 -3 -2 -4

output:

3
-9

result:

ok 2 number(s): "3 -9"

Test #2:

score: -100
Wrong Answer
time: 25ms
memory: 13792kb

input:

26667
8 0
7 3 3 3 1 1 1 3
7 7 5 4 1 2 2 7
46 31 41 67 61 100 52 36
10 7
8 3 7 4 6 2 4 3 8 1
10 4 8 5 10 5 4 3 9 1
56 26 -6 92 91 82 33 12 -3 54
5 5
2 1 1 1 1
4 3 3 2 1
-10 73 88 10 8
6 5
1 3 5 2 1 1
3 4 6 3 1 1
81 24 99 45 -1 52
9 0
4 7 1 3 1 2 1 2 1
7 7 7 4 5 4 3 2 1
-3 8 80 12 31 71 70 51 14
5 5
3...

output:

388
0
106
75
323
31
99
67
53
70
20
-2
132
72
375
126
190
414
287
29
204
155
-3
96
41
170
136
78
132
207
27
277
76
149
66
101
212
94
69
71
111
134
156
110
145
214
61
155
51
181
92
60
191
20
89
0
78
134
71
115
51
205
116
229
0
124
68
263
250
60
87
160
484
123
101
60
65
193
320
0
167
188
138
203
201
27...

result:

wrong answer 1st numbers differ - expected: '36', found: '388'