QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#579131#9313. Make MaxeweWA 125ms6772kbC++141.6kb2024-09-21 09:29:102024-09-21 09:29:11

Judging History

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

  • [2024-09-21 09:29:11]
  • 评测
  • 测评结果:WA
  • 用时:125ms
  • 内存:6772kb
  • [2024-09-21 09:29:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define fopen                      \
    freopen("in.txt", "r", stdin); \
    freopen("out.txt", "w", stdout);
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) (x & -x)
#define i64 long long
#define pii pair<int, int>
#define de(x) cout << #x << " = " << x << '\n'

const int N = 2e5 + 10, M = 4e5 + 10, mod = 1e9 + 7;
const double eps = 1e-6;

struct node
{
    int mx;
} tr[N << 2];
int a[N];

void build(int x, int l, int r)
{
    tr[x].mx = 0;
    if (l == r)
        return;
    int m = l + r >> 1;
    build(ls(x), l, m);
    build(rs(x), m + 1, r);
}

void modify(int x, int l, int r, int pos, int c)
{
    tr[x].mx = max(tr[x].mx, c);
    if (l == r)
        return;
    int m = l + r >> 1;
    if (pos <= m)
        modify(ls(x), l, m, pos, c);
    else
        modify(rs(x), m + 1, r, pos, c);
}

int qpos(int x, int l, int r, int maxval)
{
    if (l == r)
        return l;
    int m = l + r >> 1, rmax = tr[rs(x)].mx;
    if (rmax >= maxval)
        return qpos(rs(x), m + 1, r, maxval);
    else
        return qpos(ls(x), l, m, maxval);
}

void solve()
{
    int n;
    cin >> n;
    build(1, 1, n);
    i64 ans = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        int mx = tr[1].mx;
        if (mx < a[i])
            ans += i - 1;
        else
            ans += i - 1 - qpos(1, 1, n, a[i]);
        modify(1, 1, n, i, a[i]);
    }
    cout << ans << '\n';
}

signed main()
{
    // fopen;
    int t = 1;
    cin >> t;

    while (t--)
        solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5676kb

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Wrong Answer
time: 125ms
memory: 6772kb

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:

2069924
1909959

result:

wrong answer 1st numbers differ - expected: '4084978', found: '2069924'