QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#811716#9790. Make Swamp Great AgainI_Love_Sonechka#WA 50ms7932kbC++204.1kb2024-12-12 23:38:412024-12-12 23:38:42

Judging History

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

  • [2024-12-12 23:38:42]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:7932kb
  • [2024-12-12 23:38:41]
  • 提交

answer

#include <complex.h>
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

template<typename T_container, typename T = typename enable_if
    <!is_same<T_container, string>::value, typename
    T_container::value_type>::type>

ostream& operator<<(ostream &os, const T_container &v) {
    os << '{';
    string sep;
    for(const T &x : v) {
        os << sep << x;
        sep = ", ";
    }
    return os << '}';
}


void dbg_out(){cerr<<endl;}
template <typename Head, typename... Tail>void dbg_out(Head H
    , Tail... T){cerr << ' ' << H; dbg_out(T...); }

#define dbg(...) dbg_out(__VA_ARGS__)

// #define TEST_CASES
#define vt vector

const int amax = 1e5 + 1;

void solve() {
    int n;
    cin >> n;
    vt<int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    auto IsGood = [&](vt<int> vals) {
        assert(vals.size() >= 3);
        vt<int> cnt(4, 0);
        for(auto x: vals) {
            cnt[x]++;
        }
        return cnt[2] > 0 and (cnt[1] == 0 || cnt[3] == 0);
    };
    if(n <= 20) {
        for(int i = 0; i < n; ++i) {
            vt<int> b(n);
            int total = 0;
            for(int j = 0; j < n; ++j) {
                if(a[j] < a[i]) {
                    b[j] = 1;
                } else if(a[j] == a[i]) {
                    b[j] = 2;
                } else {
                    b[j] = 3;
                }
                total += b[j] == 2;
            }
            int good = 0;
            for(int j = 0; j < n; ++j) {
                vt<int> vc;
                for(int k = 0; k < 3; ++k) {
                    vc.push_back(b[(j + k) % n]);
                }
                // dbg(j, vc);
                good += IsGood(vc);
            }
            // dbg(b);
            // dbg(a[i], total, good);
            cout << n - total + int(good == 0) << ' ';
        }
        cout << '\n';
        return;
    }
    vt<vt<pair<int, int>>> queries(amax);
    for(int i = 0; i < n; ++i) {
        queries[a[i]].emplace_back(i, 2);
        queries[a[i] + 1].emplace_back(i, 1);
    }
    vt<int> res(amax, 0);
    int total = 0;
    vt<int> b(n);
    for(int j = 0; j < n; ++j) {
        if(a[j] < 1) {
            b[j] = 1;
        } else if(a[j] == 1) {
            b[j] = 2;
        } else {
            b[j] = 3;
        }
        total += b[j] == 2;
    }
    int good = 0;
    for(int j = 0; j < n; ++j) {
        vt<int> vc;
        for(int k = 0; k < 3; ++k) {
            vc.push_back(b[(j + k) % n]);
        }
        good += IsGood(vc);
    }
    res[1] = n - total + int(good == 0);
    for(int value = 2; value < amax; ++value) {
        for(auto x: queries[value]) {
            int pos = x.first, nw = x.second;
            if(nw == 2) {
                ++total;
            } else if(nw == 1) {
                --total;
            }
            for(int s = -1; s <= +1; ++s) {
                vt<int> vc;
                for(int k = 0; k < 3; ++k) {
                    int id = pos + s + k;
                    if(id < 0) {
                        id += n;
                    }
                    if(id >= n) {
                        id -= n;
                    }
                    vc.push_back(b[id]);
                }
                good -= IsGood(vc);
            }
            b[pos] = nw;
            for(int s = -1; s <= +1; ++s) {
                vt<int> vc;
                for(int k = 0; k < 3; ++k) {
                    int id = pos + s + k;
                    if(id < 0) {
                        id += n;
                    }
                    if(id >= n) {
                        id -= n;
                    }
                    vc.push_back(b[id]);
                }
                good += IsGood(vc);
            }
        }
        res[value] = n - total + int(good == 0);
    }
    for(auto x: a) {
        cout << res[x] << ' ';
    }
    cout << '\n';
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
int tt = 1;
#ifdef TEST_CASES
    cin >> tt;
#endif
    while(tt--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
4 7 47 4 77 47

output:

4 6 4 4 5 4 

result:

ok single line: '4 6 4 4 5 4 '

Test #2:

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

input:

6
4 7 47 4 77 47

output:

4 6 4 4 5 4 

result:

ok single line: '4 6 4 4 5 4 '

Test #3:

score: -100
Wrong Answer
time: 50ms
memory: 7932kb

input:

34282
90425 22450 88504 38625 50256 24285 29693 59937 55013 65148 74544 79337 84799 18379 96719 45091 46959 34827 91934 5519 57325 75622 98980 11649 42236 14474 44579 97335 71798 95780 52228 34730 42473 53258 62204 12246 15037 67194 47 41533 22010 29201 65866 68828 26827 16763 76098 73625 5875 92559...

output:

34281 34281 34281 34281 34281 34280 34281 34281 34281 34281 34281 34281 34281 34280 34281 34281 34281 34281 34281 34281 34281 34281 34280 34281 34281 34281 34281 34280 34281 34279 34281 34281 34281 34281 34281 34281 34281 34281 34281 34281 34281 34281 34280 34281 34281 34280 34281 34280 34281 34279 ...

result:

wrong answer 1st lines differ - expected: '34281 34281 34281 34281 34281 ...0 34280 34281 34281 34281 34281', found: '34281 34281 34281 34281 34281 ... 34280 34281 34281 34281 34281 '