QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#123722#1438. Ballsckiseki#WA 2ms3524kbC++201.8kb2023-07-13 13:43:452023-07-13 13:43:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-13 13:43:49]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3524kb
  • [2023-07-13 13:43:45]
  • 提交

answer

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

#ifdef CKISEKI
#define all(x) begin(x), end(x)
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
    cerr << "\e[1;32m(" << s << ") = (";
    int cnt = sizeof...(T);
    (..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
    cerr << "\e[1;32m[ " << s << " ] = [";
    while (L != R) cerr << " " << *L++;
    cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

class BIT {
    int n;
    vector<int> a;
    static int lowbit(int x) { return x & (-x); }
    int query(int p) {
        int r = 0;
        while (p) {
            r += a[p];
            p -= lowbit(p);
        }
        return r;
    }
public:
    BIT(int n_) : n(n_), a(n) {}
    void add(int p, int v) {
        while (p < n) {
            a[p] += v;
            p += lowbit(p);
        }
    }
    int query(int l, int r) {
        return query(r) - query(l);
    }
};

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &ai : a)
        cin >> ai;
    map<int, vector<int>> m;
    for (int i = 0; i < n; ++i)
        m[a[i]].push_back(i);

    BIT bit(n + 1);
    for (int i = 1; i <= n; ++i)
        bit.add(i, -1);
    int ans = 0;
    for (const auto &[_, v] : m) {
        bool good = false;
        int pre = 0;
        for (int p : v) {
            bit.add(p + 1, 2);
            if (bit.query(0, p + 1) - pre > 0)
                good = true;
            pre = min(pre, bit.query(0, p));
        }
        ans += good;
        for (int p : v)
            bit.add(p + 1, -2);
    }
    cout << ans << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7
3 1 3 2 1 2 3

output:

2

result:

ok "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3464kb

input:

10
31692384 31692384 31692384 31692384 31692384 31692385 31692384 31692385 31692385 31692385

output:

2

result:

ok "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3424kb

input:

10
41086958 41086959 41086959 41086958 41086958 41086959 41086959 41086959 41086958 41086959

output:

2

result:

ok "2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3400kb

input:

10
30400813 30400814 30400814 30400813 30400814 30400813 30400813 30400813 30400814 30400814

output:

2

result:

ok "2"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3396kb

input:

10
41086958 41086958 41086958 41086960 41086960 41086959 41086959 41086959 41086958 41086958

output:

3

result:

ok "3"

Test #6:

score: 0
Accepted
time: 1ms
memory: 3464kb

input:

10
30400813 30400815 30400815 30400813 30400814 30400815 30400815 30400813 30400813 30400814

output:

2

result:

ok "2"

Test #7:

score: 0
Accepted
time: 2ms
memory: 3400kb

input:

10
40894490 40894491 40894490 40894490 40894491 40894490 40894490 40894490 40894489 40894490

output:

1

result:

ok "1"

Test #8:

score: 0
Accepted
time: 1ms
memory: 3452kb

input:

10
30400813 30400814 30400814 30400813 30400816 30400813 30400815 30400813 30400816 30400816

output:

3

result:

ok "3"

Test #9:

score: 0
Accepted
time: 1ms
memory: 3500kb

input:

10
40894491 40894491 40894489 40894491 40894490 40894491 40894492 40894490 40894489 40894489

output:

2

result:

ok "2"

Test #10:

score: 0
Accepted
time: 1ms
memory: 3440kb

input:

10
39188263 39188263 39188266 39188263 39188265 39188266 39188264 39188265 39188266 39188263

output:

1

result:

ok "1"

Test #11:

score: 0
Accepted
time: 1ms
memory: 3484kb

input:

1000
44826252 44826252 44826251 44826252 44826252 44826252 44826251 44826251 44826252 44826251 44826251 44826251 44826252 44826251 44826251 44826251 44826251 44826251 44826252 44826251 44826251 44826251 44826252 44826251 44826252 44826252 44826251 44826251 44826252 44826251 44826251 44826252 4482625...

output:

2

result:

ok "2"

Test #12:

score: 0
Accepted
time: 1ms
memory: 3436kb

input:

1000
33210937 33210936 33210937 33210937 33210936 33210936 33210937 33210937 33210936 33210937 33210937 33210936 33210937 33210937 33210937 33210937 33210936 33210937 33210937 33210937 33210936 33210937 33210937 33210936 33210937 33210937 33210937 33210936 33210937 33210936 33210937 33210936 3321093...

output:

2

result:

ok "2"

Test #13:

score: 0
Accepted
time: 1ms
memory: 3460kb

input:

1000
33210937 33210937 33210938 33210937 33210938 33210938 33210937 33210937 33210938 33210936 33210936 33210937 33210938 33210937 33210938 33210937 33210936 33210936 33210936 33210936 33210937 33210936 33210938 33210937 33210937 33210937 33210938 33210938 33210937 33210937 33210936 33210937 3321093...

output:

3

result:

ok "3"

Test #14:

score: 0
Accepted
time: 0ms
memory: 3424kb

input:

1000
43614712 43614712 43614713 43614713 43614712 43614714 43614713 43614714 43614712 43614713 43614712 43614714 43614714 43614713 43614714 43614712 43614713 43614714 43614713 43614713 43614712 43614712 43614713 43614714 43614713 43614713 43614713 43614712 43614713 43614713 43614712 43614712 4361471...

output:

3

result:

ok "3"

Test #15:

score: 0
Accepted
time: 1ms
memory: 3524kb

input:

1000
43614715 43614714 43614715 43614713 43614712 43614714 43614714 43614714 43614713 43614713 43614713 43614715 43614713 43614714 43614712 43614712 43614714 43614712 43614715 43614712 43614712 43614712 43614715 43614713 43614715 43614712 43614712 43614713 43614714 43614713 43614715 43614713 4361471...

output:

4

result:

ok "4"

Test #16:

score: 0
Accepted
time: 1ms
memory: 3428kb

input:

1000
32028369 32028367 32028366 32028369 32028366 32028367 32028368 32028369 32028369 32028367 32028366 32028369 32028369 32028368 32028367 32028367 32028367 32028368 32028368 32028369 32028369 32028367 32028369 32028367 32028369 32028368 32028368 32028367 32028369 32028367 32028368 32028369 3202836...

output:

4

result:

ok "4"

Test #17:

score: 0
Accepted
time: 0ms
memory: 3480kb

input:

1000
32028367 32028367 32028368 32028370 32028367 32028369 32028366 32028370 32028368 32028367 32028367 32028367 32028370 32028370 32028369 32028368 32028370 32028366 32028367 32028367 32028369 32028368 32028368 32028368 32028370 32028368 32028366 32028370 32028367 32028368 32028367 32028367 3202836...

output:

5

result:

ok "5"

Test #18:

score: 0
Accepted
time: 0ms
memory: 3416kb

input:

1000
43412245 43412244 43412247 43412247 43412244 43412245 43412246 43412246 43412247 43412247 43412243 43412246 43412246 43412243 43412247 43412244 43412245 43412247 43412244 43412244 43412244 43412246 43412243 43412247 43412247 43412246 43412247 43412245 43412247 43412246 43412244 43412246 4341224...

output:

5

result:

ok "5"

Test #19:

score: 0
Accepted
time: 1ms
memory: 3416kb

input:

1000
21928129 21928124 21928122 21928130 21928125 21928125 21928126 21928129 21928130 21928123 21928125 21928129 21928122 21928126 21928129 21928130 21928129 21928122 21928130 21928123 21928130 21928131 21928130 21928128 21928129 21928131 21928129 21928128 21928123 21928125 21928124 21928124 2192812...

output:

10

result:

ok "10"

Test #20:

score: 0
Accepted
time: 1ms
memory: 3484kb

input:

1000
31312709 31312713 31312715 31312714 31312715 31312714 31312713 31312707 31312711 31312710 31312707 31312713 31312714 31312711 31312714 31312713 31312712 31312713 31312714 31312712 31312713 31312706 31312712 31312706 31312713 31312715 31312710 31312706 31312707 31312710 31312713 31312713 3131270...

output:

10

result:

ok "10"

Test #21:

score: -100
Wrong Answer
time: 0ms
memory: 3416kb

input:

1000
68015864 68015872 68015859 68015861 68015866 68015845 68015851 68015872 68015836 68015856 68015871 68015851 68015839 68015866 68015871 68015837 68015870 68015846 68015861 68015863 68015853 68015848 68015838 68015842 68015859 68015835 68015833 68015848 68015872 68015846 68015869 68015869 6801585...

output:

24

result:

wrong answer 1st words differ - expected: '23', found: '24'