QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573209#6434. Paimon Sortingji_114514WA 1ms8032kbC++201.1kb2024-09-18 17:44:582024-09-18 17:44:59

Judging History

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

  • [2024-09-18 17:44:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8032kb
  • [2024-09-18 17:44:58]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) (x&(-x))
using namespace std;

const int N = 1e6 + 10;
int a[N], n, s[N];
ll f[N];

void add(int x, int t) {

    while (x <= n) {
        s[x] += t;
        x += lowbit(x);
    }
}

int query(int x) {
    int res = 0;
    while (x) {
        res += s[x];
        x -= lowbit(x);
    }
    return res;
}

void solve()
{
    cin >> n;
    vector<int>v(1, 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i], f[i] = 0;
    }
    ll res = 0, t = 0;
    add(a[1], 1);
    for (int i = 2; i <= n; i++) {
        if (a[i] > a[v.back()]) {
            res += 2;
            f[i] = res;
            add(a[i], 1);
            v.push_back(i);
        }
        else {
            res += query(n) - query(a[i]);
            //cout << i << ' ' << query(n)  << "#\n";
            f[i] = res;
        }

    }
    for (int i = 1; i <= n; i++)cout << f[i] << ' ';
    cout << '\n';
}
int main()
{
    srand(time(0));
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t; cin >> t;
    while (t--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 8032kb

input:

3
5
2 3 2 1 5
3
1 2 3
1
1

output:

0 2 3 5 7 
0 2 4 
0 

result:

wrong answer 1st lines differ - expected: '0 2 3 5 7', found: '0 2 3 5 7 '