QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#818368#8050. Random Permutationucup-team3519#WA 197ms4456kbC++171.5kb2024-12-17 19:30:182024-12-17 19:30:24

Judging History

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

  • [2024-12-17 19:30:24]
  • 评测
  • 测评结果:WA
  • 用时:197ms
  • 内存:4456kb
  • [2024-12-17 19:30:18]
  • 提交

answer

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

#define V vector
#define pb push_back
#define all0(x) (x).begin(), (x).end()
#define all1(x) (x).begin() + 1, (x).end()
#define fi first
#define se second

typedef long long LL;
typedef pair<int, int> pi;

const int INF = 2e9 + 10000;

mt19937 mrand(chrono::steady_clock().now().time_since_epoch().count());

void solve() {
    int n;
    cin >> n;
    V<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    int base = n;
    V<int> tab(base * 2 + 1);
    const int T = 20;
    LL ans = 0;
    for (int i = 1; i <= n; i++) {
        int len = T * (n / (abs(a[i] - n / 2) + 1));
        int l = max(1, i - len), r = min(n, i + len);
        int mn = INF, mx = -INF;
        int cur = 0;
        for (int j = i; j >= l; j--) {
            mn = min(mn, cur), mx = max(mx, cur);
            tab[base + cur]++;
            if (j == l) break;
            if (a[j - 1] > a[i]) cur++;
            else cur--;
        }
        cur = 0;
        for (int j = i; j <= r; j++) {
            ans += 1LL * tab[base - cur] * a[i];
            ans += 1LL * tab[base - cur + 1] * a[i];
            if (j == r) break;
            if (a[j + 1] > a[i]) cur++;
            else cur--;
        }
        for (int i = mn; i <= mx; i++) {
            tab[i + base] = 0;
        }
    }
    cout << ans << endl;
}

int main() {

    ios::sync_with_stdio(0), cin.tie(0);
    // int t;
    // cin >> t;
    // while (t--)
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: -100
Wrong Answer
time: 197ms
memory: 4456kb

input:

100000
56449 21738 74917 44834 36187 96576 37204 28451 3444 13029 66039 8955 51445 30706 27229 37159 66052 16691 70389 29935 44984 3648 75082 73600 76621 28345 5298 37940 49412 85260 92029 18185 84398 10233 79227 98312 96649 30680 65206 38879 75397 26951 11294 58085 37297 97167 59252 44104 4058 3796...

output:

85914048753559

result:

wrong answer 1st numbers differ - expected: '250202478701074', found: '85914048753559'