QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#380703#8050. Random PermutationpopeWA 2650ms7840kbC++201.9kb2024-04-07 08:54:342024-04-07 08:54:35

Judging History

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

  • [2024-04-07 08:54:35]
  • 评测
  • 测评结果:WA
  • 用时:2650ms
  • 内存:7840kb
  • [2024-04-07 08:54:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); i++)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define trav(a, x) for (auto& a: x)
#define f first
#define s second
#define pb push_back
const char nl = '\n';

#ifdef DBG
void dbg_out() { cerr << nl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
    cerr << ' ' << H;
    dbg_out(T...);
}
#define dbg(...) dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int n;
    cin >> n;
    vector<int> a(n);
    srand(40);
    for(int i = 0; i<n; i++){
        cin >> a[i];
    }
    vector<int> sums(3*n);
    int shift = n;
    ll ans = 0LL;
    for(int i = 0; i<n; i++){
        int val = max(n/2-a[i],a[i]-n/2);
        val = max(val,1);
        int wid = (int)min((ll)n,4LL*(ll)n*(ll)n/val/val);
        // int wid = (int)min((ll)n,5LL*(ll)n*(ll)n/val/val);
        wid = max(wid,500);
        int sum = 0;
        int l = max(0,i-wid);
        int r = min(n-1,i+wid);
        ll cur = 0LL;
        for(int j = i; j>=l; j--){
            if(j < i){
                sum += ((a[j]>a[i])?1:-1);
            }
            sums[sum+shift]++;
        }
        sum = 0;
        for(int j = i; j<=r; j++){
            if(j>i){
                sum += ((a[j]>a[i])?1:-1);
            }
            cur += sums[shift-sum];
            cur += sums[shift-sum+1];
        }
        sum = 0;
        for(int j = i; j>=l; j--){
            if(j < i){
                sum += ((a[j]>a[i])?1:-1);
            }
            sums[sum+shift] = 0;
        }
        ans += cur*a[i];
    }
    cout << ans << endl;

}


详细

Test #1:

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

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: 0
Accepted
time: 551ms
memory: 4800kb

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:

250202478701074

result:

ok 1 number(s): "250202478701074"

Test #3:

score: 0
Accepted
time: 1473ms
memory: 6196kb

input:

200000
70900 189146 39056 135530 191967 133789 108558 81993 132081 113826 54456 127761 27836 64897 87159 105191 109446 81230 75525 90396 75756 50200 43091 151358 100791 193998 157161 119352 176873 120724 134471 155040 138534 182263 161855 4577 124893 199710 60764 146460 75314 43696 129155 64816 1390...

output:

1998651699409551

result:

ok 1 number(s): "1998651699409551"

Test #4:

score: -100
Wrong Answer
time: 2650ms
memory: 7840kb

input:

300000
291335 150122 292004 129126 26666 242892 124454 146198 257953 17400 245611 108131 68345 266915 44851 146376 110324 211968 251982 127849 152791 204625 213884 144643 137727 113838 115018 225220 169217 151 284989 29747 37230 110534 124886 224954 253706 175150 103605 289983 165895 113248 32809 28...

output:

6755672770862171

result:

wrong answer 1st numbers differ - expected: '6755672893227829', found: '6755672770862171'