QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#818361#8050. Random Permutationucup-team3519#WA 721ms4484kbC++171.5kb2024-12-17 19:26:562024-12-17 19:27:03

Judging History

This is the latest submission verdict.

  • [2024-12-17 19:27:03]
  • Judged
  • Verdict: WA
  • Time: 721ms
  • Memory: 4484kb
  • [2024-12-17 19:26:56]
  • Submitted

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 = 7;
    LL ans = 0;
    for (int i = 1; i <= n; i++) {
        int len = T * (sqrt(a[i]) + 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();
}

詳細信息

Test #1:

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

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: -100
Wrong Answer
time: 721ms
memory: 4484kb

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:

10749530959462

result:

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