QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#778975#6134. Soldier GameyanshanjiahongWA 949ms24464kbC++142.3kb2024-11-24 16:57:392024-11-24 16:57:45

Judging History

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

  • [2024-11-24 16:57:45]
  • 评测
  • 测评结果:WA
  • 用时:949ms
  • 内存:24464kb
  • [2024-11-24 16:57:39]
  • 提交

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),nlim=0;
    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);
    rep(i,1,n)
        T.modify(1,1,n,i);
    int ans=inf;
    rep(i,1,2*n-1){
        nlim=s[i].val;
        if(s[i].val!=s[i-1].val)ans=min(ans,T.t[1].v[0][0]-nlim);
        nlim++;
        if(s[i].x)T.modify(1,1,n,s[i].x);
        if(s[i].y)T.modify(1,1,n,s[i].y);
    }
    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: 7900kb

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: 949ms
memory: 24464kb

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
1000000000000000007
0
2000000000
100
137
132
181
999999999999999898
84
100
164
176
0
147
135
152
100
200
131
134
0
136
0
72
999999999999999854
146
15
183
77
176
999999999999999918
200
135
38
109
119
126
158
999999999999999874
70
1000000000000000007
38
999999999000140095
188
161
0
99999999999999993...

result:

wrong answer 2nd numbers differ - expected: '0', found: '1000000000000000007'