QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#95034#6134. Soldier GameRPUAC ✓572ms14728kbC++143.0kb2023-04-08 22:30:262023-04-08 22:30:27

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-08 22:30:27]
  • 评测
  • 测评结果:AC
  • 用时:572ms
  • 内存:14728kb
  • [2023-04-08 22:30:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a;i<=(b);i++)
#define Rof(i,a,b) for(int i=a;i>=(b);i--)
#define FOR(i,a) for(int i=0;i<a;i++)
#define clr(a) memset(a,0,sizeof(a))
#define wln putchar('\n')
#define lwb lower_bound
#define upb upper_bound
#define pb push_back
#define mp make_pair
#define rng(a) a.begin(),a.end()
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned ui;
typedef pair<int,int> pii;
template<class T1,class T2> void chkmin(T1 &x,T2 y){if(y<x)x=y;}
template<class T1,class T2> void chkmax(T1 &x,T2 y){if(y>x)x=y;}
const int BUF_SIZE=1<<20;
char buf[BUF_SIZE],*P1=buf,*P2=buf,obuf[BUF_SIZE],*PO=obuf;
char getc()
{
    if(P1==P2)P2=(P1=buf)+fread(buf,1,BUF_SIZE,stdin);
    return P1==P2?EOF:*P1++;
}
void read(int &x)
{
    char ch=getc(); x=0;
    while(!isdigit(ch))ch=getc();
    while(isdigit(ch))x=x*10+(ch^48),ch=getc();
}
void flushO()
{
    fwrite(obuf,PO-obuf,1,stdout);
    PO=obuf;
}
void putc(char ch)
{
    if(PO==obuf+(BUF_SIZE))flushO();
    *PO++=ch;
}
void prints(char s[]){for(char* ss=s;*ss!='\0';ss++)putc(*ss);}
void write(ll x)
{
    if(x>9)write(x/10);
    putc(x%10^48);
}
const int N=100005,INF=1000000007;
const ll INFll=1ll*INF*INF;
int n,a[N];
struct segtree
{
    struct node{ll v[2][2];}v[N<<2];
    friend node operator +(node a,node b)
    {
        node c;
        For(i,0,1)
            For(j,0,1)
            {
                c.v[i][j]=min(max(a.v[i][0],b.v[0][j]),max(a.v[i][1],b.v[1][j]));
                //printf("%lld %lld %lld %lld %lld\n",c.v[i][j],a.v[i][0],b.v[0][j],a.v[i][1],b.v[1][j]);
            }
        return c;
    }
    void pushup(int id){v[id]=v[id<<1]+v[id<<1|1];}
    void build(int id,int l,int r)
    {
        if(l==r)
        {
            v[id]={a[l],a[l]+a[l+1],-INFll,INFll};
            return;
        }
        int mid=l+r>>1;
        build(id<<1,l,mid);
        build(id<<1|1,mid+1,r);
        pushup(id);
        //printf("(%d,%d):v[%d]={%lld,%lld,%lld,%lld}\n",l,r,id,v[id].v[0][0],v[id].v[0][1],v[id].v[1][0],v[id].v[1][1]);
    }
    void modify(int id,int l,int r,int x,int y)
    {
        if(l==r)
        {
            v[id].v[0][y]=INFll;
            return;
        }
        int mid=l+r>>1;
        if(x<=mid)modify(id<<1,l,mid,x,y);
        else modify(id<<1|1,mid+1,r,x,y);
        pushup(id);
    }
}T;
typedef tuple<int,int,int> piii;
piii o[N<<1];
void Main()
{
    scanf("%d",&n);
    For(i,1,n)scanf("%d",a+i),o[i]={a[i],i,0};
    For(i,1,n-1)o[n+i]={a[i]+a[i+1],i,1};
    sort(o+1,o+n+n);
    T.build(1,1,n);
    ll ans=INFll;
    For(i,1,n*2-1)
    {
        //printf("%lld %d\n",T.v[1].v[0][0],get<0>(o[i]));
        chkmin(ans,T.v[1].v[0][0]-get<0>(o[i]));
        T.modify(1,1,n,get<1>(o[i]),get<2>(o[i]));
    }
    printf("%lld\n",ans);
}
int main()
{
    //freopen("out.txt","w",stdout);
    int t;
    scanf("%d",&t);
    while(t--)Main();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3736kb

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: 0
Accepted
time: 511ms
memory: 14456kb

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
63
164
176
0
147
135
152
36
200
131
134
0
136
0
72
171
146
0
183
77
176
89
200
135
38
109
119
126
158
189
70
0
38
999804364
188
161
0
116
116
200
0
101
200
39
0
183
139
0
183
107
139
0
178
85993
126
153
168
163
96
53
96
52
126
47
130
79
0
123
188
173
33
0
83
1...

result:

ok 10010 numbers

Test #3:

score: 0
Accepted
time: 47ms
memory: 14508kb

input:

1
100000
-999999999 999999999 999999998 -999999998 -999999997 999999997 999999996 -999999996 999999995 -999999995 -999999994 999999994 -999999993 999999993 -999999992 999999992 -999999991 999999991 999999990 -999999990 999999989 -999999989 999999988 -999999988 999999987 -999999987 999999986 -9999999...

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 572ms
memory: 14728kb

input:

10011
1
1000000000
1
-1000000000
2
1000000000 -1000000000
4
1000000000 1000000000 -1000000000 -1000000000
12
48 54 98 -20 -45 56 -100 78 47 23 -100 -21
19
66 41 52 17 -9 -90 -36 90 -26 66 -86 -83 -39 -83 35 78 100 -68 -62
2
-100 -23
17
89 -26 -100 -38 -14 87 32 -100 16 -31 -35 100 73 -61 -100 43 -48...

output:

0
0
0
2000000000
155
168
0
173
137
167
127
25
91
109
176
0
0
173
115
56
66
67
0
1999775909
121
166
128
77
60
146
152
78
172
110
60
200
89
160
200
130
175
79
97
1999891177
122
154
136
164
123
0
175
77
167
76
40
82
79
159
99
141
165
147
158
1999730298
0
179
31
181
192
193
47
91
164
63
65
138
100
168
1...

result:

ok 10011 numbers

Test #5:

score: 0
Accepted
time: 38ms
memory: 14484kb

input:

1
100000
50000 50000 50001 50001 50002 50002 50003 50003 50004 50004 50005 50005 50006 50006 50007 50007 50008 50008 50009 50009 50010 50010 50011 50011 50012 50012 50013 50013 50014 50014 50015 50015 50016 50016 50017 50017 50018 50018 50019 50019 50020 50020 50021 50021 50022 50022 50023 50023 500...

output:

49999

result:

ok 1 number(s): "49999"