QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201179#7339. A Really Odd SequencekjhhjkiAC ✓1077ms50416kbC++20790b2023-10-05 12:56:502023-10-05 12:56:50

Judging History

This is the latest submission verdict.

  • [2023-10-05 12:56:50]
  • Judged
  • Verdict: AC
  • Time: 1077ms
  • Memory: 50416kb
  • [2023-10-05 12:56:50]
  • Submitted

answer

#include <bits/stdc++.h>
#define MAXN 100005
#define For(I,A,B) for(int I = (A), endi = (B); I <= endi; ++I)
#define foR(I,A,B) for(int I = (A), endi = (B); I >= endi; --I)
#define ForE(I,A) for(int I = head[A]; I; I = e[I].nxt)
using namespace std;
typedef long long _ll;
typedef unsigned int ui;

int T,n,x;
_ll sum,ans;
void solve()
{
    cin >> n; set<_ll> s[2]; s[0].insert(0); ans = -0x7ffffffffffll; sum = 0;
    For(i,1,n)
    {
        cin >> x;
        sum += x; s[i&1].insert(sum);
        int p = !(i&1);
        if(s[p].empty()) continue;
        ans = max(ans,sum - *s[p].begin());
    }
    cout << ans << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> T;
    while(T--) solve();
    return 0;
}

詳細信息

Test #1:

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

input:

1
4
8 -7 9 1

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 1077ms
memory: 50416kb

input:

59056
10
0 1 1 0 1 0 1 1 1 0
10
-1 -1 -1 1 0 0 1 0 0 1
10
1 0 0 1 1 1 -1 -1 0 1
10
-1 1 -1 1 0 1 1 0 -1 1
10
1 0 0 1 -1 0 -1 -1 -1 1
10
1 1 1 0 0 -1 -1 1 0 0
10
-1 1 0 0 1 -1 -1 0 -1 -1
10
1 -1 0 0 0 -1 -1 -1 -1 -1
10
0 0 0 1 1 0 0 1 -1 1
10
0 -1 0 0 1 0 1 1 1 0
10
0 0 0 0 1 -1 1 -1 -1 -1
10
-1 0 1 ...

output:

6
3
3
3
1
3
1
1
3
4
1
2
3
6
1
1
4
2
1
1
4
1
3
2
3
1
5
1
1
2
3
1
1
2
2
3
0
5
1
1
2
1
1
2
3
2
1
2
1
3
1
2
3
2
3
2
3
2
5
1
3
2
2
2
2
1
1
2
2
3
2
1
3
1
2
1
1
2
2
1
2
1
1
3
1
3
1
1
2
1
2
2
3
2
1
2
1
1
3
3
1
1
2
1
1
3
1
2
2
1
1
1
3
3
2
1
3
2
3
2
2
4
2
1
2
4
3
5
2
2
4
1
1
2
1
1
2
2
5
3
3
0
2
2
2
1
1
2
1
2
...

result:

ok 59056 numbers