QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#571273#9313. Make MaxConsWWA 63ms11612kbC++202.6kb2024-09-17 21:38:212024-09-17 21:38:21

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-17 21:38:21]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:11612kb
  • [2024-09-17 21:38:21]
  • 提交

answer

#include<bits/stdc++.h>

#define i64 long long
#define ll long long

using namespace std;

typedef pair<i64, i64> pii;

const i64 MOD = 998244353;

inline i64 lowbit(i64 x) { return x & (-x); }

inline i64 highbit(i64 x) {
    i64 cnt = 0;
    do {
        if (x == 1) return 1LL << cnt;
        else ++cnt;
    } while (x >>= 1);
}

inline i64 factory(i64 x) {
    i64 cnt = 1;
    while (x != 1) {
        cnt *= x--;
        cnt %= MOD;
    }
    return cnt;
}//阶乘(含模运算)

inline i64 gcd(i64 a, i64 b) {
    while (b ^= a ^= b ^= a %= b);
    return a;
}//最小公约数

inline bool isPrime(i64 x) {
    for (int i = 2; i <= sqrt(x); ++i) {
        if (x % i == 0) return false;
    }
    if (x != 1) return true;
    else return false;
}

inline bool cmp(pii a, pii b) {
    return a.first > b.first;
}

inline i64 query(i64 a, i64 b) {
    i64 tmp;
    cout << "? " << a << " " << b << endl;
    cout.flush();
    cin >> tmp;
    return tmp;
}

inline i64 to_i64(string s) {
    stringstream ss(s);
    i64 tmp;
    ss >> tmp;
    return tmp;
}//字符串转long long

inline i64 LIS(i64 arr[], i64 n) {
    i64 dp[n], len = 0;
    dp[0] = arr[0];
    for (int i = 1; i < n; ++i) {
        if (arr[i] > dp[len]) dp[++len] = arr[i];
        else *(lower_bound(dp, dp + len, arr[i])) = arr[i];
    }
    return len + 1;
}

struct st{
    i64 num;
    i64 idx;
};

bool cmpp(st a,st b){
    return a.num > b.num;
}

void solve() {
    i64 n;
    cin>>n;
    i64 a[n];
    st sta[n];
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        sta[i].num = a[i];
        sta[i].idx = i;
    }
    sort(sta,sta+n, cmpp);


    i64 fa[n];
    stack<i64> stk;
    for (int i = 0; i < n; ++i) {
        while (!stk.empty()&&a[i]>a[stk.top()]) {
            fa[stk.top()] = i;
            stk.pop();
        }
        stk.push(i);
    }
    while (!stk.empty()) {
        fa[stk.top()] = -1;
        stk.pop();
    }

    for (int i = n - 1; i >= 0; --i) {
        while (!stk.empty()&&a[i]>a[stk.top()]) {
            fa[i] = max(fa[i], stk.top());
            stk.pop();
        }
        stk.push(i);
    }

    i64 ans[n],anss = 0;
    memset(ans,0,sizeof ans);
    for (int i = n - 1; i >= 0; --i) {
        if (fa[sta[i].idx]!=-1) ans[i] = ans[fa[sta[i].idx]] + 1;
    }

    for (int i = 0; i < n; ++i) anss += ans[i];
    cout<<anss<<endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

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: 63ms
memory: 11612kb

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:

340595
328123

result:

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