QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#354349#6437. Paimon's TreePorNPtreeWA 0ms3892kbC++141.1kb2024-03-15 10:41:112024-03-15 10:41:12

Judging History

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

  • [2024-03-15 10:41:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3892kb
  • [2024-03-15 10:41:11]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int n, vis[N], s[N];

void modify(int x)
{
    for (; x <= n; x += x & -x) {
        ++s[x];
    }
    return;
}

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

signed main()
{
    int T;
    scanf("%d", &T);
    while (T--) {
        int z = 0, a1;
        scanf("%d", &n);
        long long A = 0;
        for (int i = 1; i <= n; ++i) {
            vis[i] = s[i] = 0;
        }
        for (int i = 1, x; i <= n; ++i) {
            scanf("%d", &x);
            if (i == 1) {
                a1 = x;
            }
            if (!vis[x]) {
                modify(x);
                vis[x] = 1;
            }
            if (i > 1 && x == a1) {
                ++z;
            } else if (x > a1) {
                A += z + 1;
                z = 0;
                swap(a1, x);
            }
            A += query(n) - query(x);
            printf("%lld%c", A, " \n"[i == n]);
        }
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3892kb

input:

2
5
1 7 3 5 4
1 3
2 3
3 4
4 5
4 6
1
1000000000
1 2

output:

0 1 1 1 2
-2

result:

wrong answer 1st numbers differ - expected: '16', found: '0'