QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#91448#6134. Soldier GameMilk_FengWA 466ms11388kbC++112.8kb2023-03-28 21:42:132023-03-28 21:42:16

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-28 21:42:16]
  • Judged
  • Verdict: WA
  • Time: 466ms
  • Memory: 11388kb
  • [2023-03-28 21:42:13]
  • Submitted

answer

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

typedef long long LL;
typedef unsigned long long ULL;
//typedef __int128 LLL;

int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9') c == '-' ? f = -1: 0, c = getchar();
	while(c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
    return x * f;
}

const int MAXN = 100050;

int n, a[MAXN];

struct Range {
    int l, r, sum;
    Range() {  };
    Range(int _l, int _r, int _sum)
        : l(_l), r(_r), sum(_sum) {  }
    bool operator < (const Range& other) const {
        return sum < other.sum;
    }
} stk[MAXN * 2];

struct Tree {
    int cnt, ch[MAXN * 20][2];
    bool a[MAXN * 20][2][2];
    
    void pushup(int p) {
        int lch = ch[p][0], rch = ch[p][1];
        a[p][0][0] = (a[lch][0][0] & a[rch][0][0]) | (a[lch][0][1] & a[rch][1][0]);
        a[p][0][1] = (a[lch][0][0] & a[rch][0][1]) | (a[lch][0][1] & a[rch][1][1]);
        a[p][1][0] = (a[lch][1][0] & a[rch][0][0]) | (a[lch][1][1] & a[rch][1][0]);
        a[p][1][1] = (a[lch][1][0] & a[rch][0][1]) | (a[lch][1][1] & a[rch][1][1]);
    }
    
    void build(int p, int l, int r) {
        if(l == r) {
            a[p][0][0] = a[p][0][1] = a[p][1][1] = false;
            a[p][1][0] = true;
            return ;
        }
        int mid = l + r >> 1;
        build(ch[p][0] = ++cnt, l, mid);
        build(ch[p][1] = ++cnt, mid + 1, r);
        pushup(p);
    }
    
    void chg(int p, int l, int r, int x, int s1, int s2) {
        if(l == r) {
            a[p][s1][s2] ^= true;
            return ;
        }
        int mid = l + r >> 1;
        if(x <= mid) chg(ch[p][0], l, mid, x, s1, s2);
        else chg(ch[p][1], mid + 1, r, x, s1, s2);
        pushup(p);
    }
    
    void build() { build(cnt = 1, 1, n); }
    void chg(Range range) {
        int l = range.l, r = range.r;
        if(l == 0) return ;
        if(l == r) {
            chg(1, 1, n, l, 0, 0);
            if(l > 1) chg(1, 1, n, l - 1, 1, 1);
        }
        else chg(1, 1, n, l, 0, 1);
    }
    bool qry() { return a[1][0][0]; }
} tree;

signed main() {
    
    int t = read();
    while(t--) {
        n = read();
        int top = 0;
        for(int i = 1; i <= n; ++i) {
            a[i] = read();
            stk[++top] = Range(i, i, a[i]);
            if(i >= 2) stk[++top] = {i - 1, i, a[i - 1] + a[i]};
        }
        sort(stk + 1, stk + top + 1);
        
        tree.build();
        int l = 0, r = 0, ans = 0x3f3f3f3f;
        while(r <= top && l <= top) {
            tree.chg(stk[l++]);
            while(r + 1 <= top && !tree.qry()) tree.chg(stk[++r]);
            if(!tree.qry()) break;
            else ans = min(ans, stk[r].sum - stk[l].sum);
        }
        
        printf("%d\n", ans);
    }
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 9804kb

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: 466ms
memory: 11388kb

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
-1294967296
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
...

result:

wrong answer 4th numbers differ - expected: '2000000000', found: '-1294967296'