QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639172#8050. Random PermutationIllusionaryWhiteTraveler#WA 1128ms9028kbC++201.6kb2024-10-13 18:10:422024-10-13 18:10:43

Judging History

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

  • [2024-10-13 18:10:43]
  • 评测
  • 测评结果:WA
  • 用时:1128ms
  • 内存:9028kb
  • [2024-10-13 18:10:42]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAX_N = 300000 + 5;
const int K = 10;
const int B = 1000;

int N, a[MAX_N], pos[MAX_N];

ll solve(int mid, int lim) {
    int l = max(1, mid - lim);
    int r = min(N, mid + lim);
    static int cntl[MAX_N << 1], cntr[MAX_N << 1];
    int minv = N + 1, maxv = -N - 1;
    for (int i = mid, j = 0; i >= l; i --) {
        if (a[i] < a[mid]) j --;
        else if (a[i] > a[mid]) j ++;
        cntl[j + MAX_N] ++;
        minv = min(minv, j);
        maxv = max(maxv, j);
    }
    for (int i = mid, j = 0; i <= r; i ++) {
        if (a[i] < a[mid]) j --;
        else if (a[i] > a[mid]) j ++;
        cntr[j + MAX_N] ++;
    }
    ll ans = 0;
    for (int i = minv; i <= maxv; i ++) {
        ans += 1ll * cntl[i + MAX_N] * (cntr[MAX_N - i] + cntr[MAX_N - i + 1]);
    }
    for (int i = mid, j = 0; i >= l; i --) {
        if (a[i] < a[mid]) j --;
        else if (a[i] > a[mid]) j ++;
        cntl[j + MAX_N] = 0;
    }
    for (int i = mid, j = 0; i <= r; i ++) {
        if (a[i] < a[mid]) j --;
        else if (a[i] > a[mid]) j ++;
        cntr[j + MAX_N] = 0;
    }
    return ans * a[mid];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    cin >> N;
    for (int i = 1; i <= N; i ++) {
        cin >> a[i];
        pos[a[i]] = i;
    }
    ll ans = 0;
    for (int i = 1; i <= N; i ++) {
        int x = abs(N / 2 - i) + 1;
        int lim = N / i * K + B;
        ans += solve(pos[i], lim);
    }
    cout << ans << '\n';
    cerr << "time : " << clock() << endl;
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: -100
Wrong Answer
time: 1128ms
memory: 9028kb

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:

6967398618375

result:

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