QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#779006#6134. Soldier GameyanshanjiahongWA 915ms24492kbC++142.4kb2024-11-24 17:04:302024-11-24 17:04:31

Judging History

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

  • [2024-11-24 17:04:31]
  • 评测
  • 测评结果:WA
  • 用时:915ms
  • 内存:24492kb
  • [2024-11-24 17:04:30]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define repp(i,j,k) for(int i=j;i>=k;i--)
#define ls(x) (x<<1)
#define rs(x) ((x<<1)|1)
#define mp make_pair
#define sec second
#define fir first
#define pii pair<int,int>
#define lowbit(i) i&-i
#define double long double
#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+5,M=1005,S=105,inf=(ll)1e18+7,mo=1e9+7;
const double eps=1e-8;
void read(int &p){
	int x=0,w=1;
	char ch=0;
	while(!isdigit(ch)){
		if(ch=='-')w=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	p=x*w;
}
int TT;
int n,a[N];
int nlim=0;
struct node{
    int le,ri;
    int v[2][2];
    friend node operator+(node x,node y){
        node res;
        res.le=x.le,res.ri=y.ri;
        rep(i,0,1){
            rep(j,0,1){
                int val=inf;
                val=min(val,max(x.v[i][0],y.v[0][j]));
                if(a[x.ri]+a[y.le]>=nlim)val=min(val,max({x.v[i][1],y.v[1][j],a[x.ri]+a[y.le]}));
                res.v[i][j]=val;
            }
        }
        return res;
    }
};
struct seg{
    node t[N*4];
    void pushup(int x){
        t[x]=t[ls(x)]+t[rs(x)];
    }
    void modify(int x,int le,int ri,int p){
        if(le==ri){
            t[x].le=t[x].ri=le;
            t[x].v[1][1]=inf;
            if(a[le]>=nlim)t[x].v[0][0]=a[le];
            else t[x].v[0][0]=inf;
            t[x].v[0][1]=t[x].v[1][0]=0;
            return;
        }
        int mid=(le+ri)>>1;
        if(p<=mid)modify(ls(x),le,mid,p);
        else modify(rs(x),mid+1,ri,p);
        pushup(x);
    }
}T;
struct sit{
    int val,x,y;
    friend bool operator<(sit x,sit y){
        return x.val<y.val;
    }
}s[N];
void solve(){
    read(n);
    rep(i,1,n)
        read(a[i]),s[i]=(sit){a[i],i,0};
    rep(i,1,n-1)
        s[i+n]=(sit){a[i]+a[i+1],i,i+1};
    sort(s+1,s+n*2),nlim=s[1].val;
    rep(i,1,n)
        T.modify(1,1,n,i);
    int ans=T.t[1].v[0][0]-nlim;
    int lap=1;
    rep(i,2,2*n-1){
        if(s[i].val==s[lap].val)continue;
        nlim=s[i].val;
        rep(j,lap,i-1){
            if(s[j].x)T.modify(1,1,n,s[j].x);
            if(s[j].y)T.modify(1,1,n,s[j].y);
        }
        ans=min(ans,T.t[1].v[0][0]-nlim),lap=i;
    }
    printf("%lld\n",ans);
}
signed main(){
    read(TT);
    while(TT--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7972kb

input:

3
5
-1 4 2 1 1
4
1 3 2 4
1
7

output:

1
2
0

result:

ok 3 number(s): "1 2 0"

Test #2:

score: -100
Wrong Answer
time: 915ms
memory: 24492kb

input:

10010
1
1000000000
1
-1000000000
2
1000000000 -1000000000
4
1000000000 1000000000 -1000000000 -1000000000
3
100 -100 100
16
-17 91 -19 66 100 -70 -71 76 -58 99 52 19 25 -67 -63 -32
7
-95 -26 63 -55 -19 77 -100
17
-100 72 -53 -32 8 -100 53 44 -100 -65 -81 -59 100 100 57 -47 1
11
99 10 -100 3 32 2 -26...

output:

0
0
0
2000000000
100
135
103
181
189
84
100
164
176
0
147
135
152
100
200
131
134
0
136
0
72
171
146
15
183
77
176
100
200
135
38
109
119
126
158
189
70
0
38
999867614
188
161
0
116
116
200
0
101
200
50
1
183
139
36
183
107
139
17
178
85993
126
153
168
163
96
100
96
52
126
71
130
79
0
123
188
173
33...

result:

wrong answer 11th numbers differ - expected: '63', found: '100'