QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576498#9313. Make MaxRosmontis_LWA 173ms18920kbC++201.8kb2024-09-19 20:40:052024-09-19 20:40:06

Judging History

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

  • [2024-09-19 20:40:06]
  • 评测
  • 测评结果:WA
  • 用时:173ms
  • 内存:18920kb
  • [2024-09-19 20:40:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
//#define int long long
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
typedef tuple<ll, ll, ll> TLL;
int lowbit(int x) {return x & (- x);};
const int N = 200010, mod = 998244353;
const int Mod = 1e9 + 7, INF = 0x3f3f3f3f;

void solve(){
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    for(int i = 1; i <= n; i ++) cin >> a[i];
    priority_queue<PLL, vector<PLL>, greater<PLL>> q;
    vector<ll> val(n + 1), siz(n + 1);
    vector<ll> pre(n + 1), nxt(n + 1);
    vector<int> vis(n + 1);
    for(int i = 1; i <= n; i ++){
        pre[i] = i - 1;
        nxt[i] = i + 1;
        siz[i] = 1;
        val[i] = a[i];
        q.push({a[i], i});
    }
    ll ans = 0;
    auto merge =[&](ll x, ll y, ll lei) -> void{
        ll cha = val[y] - val[x];
        ans += cha * siz[x];
        siz[x] += siz[y];
        val[x] = val[y];
        if(lei == 1){
            pre[x] = pre[y];
        }
        else{
            nxt[x] = nxt[y];
        }
        q.push({val[x], x});
        vis[y] = 1;
    };
    while(q.size() >= 2){
        auto [v1, i] = q.top();
        q.pop();
        if(vis[i]) continue;
        ll pp = pre[i], nn = nxt[i];
        if(pp == 0 && nn == n + 1) break;
        if(pp == 0){
            merge(i, nn, 2);
        }
        else if(nn == n + 1){
            merge(i, pp, 1);
        }
        else{
            ll vl1 = val[pp], vl2 = val[nn];
            if(vl1 <= vl2) merge(i, pp, 1);
            else merge(i, nn, 2);
        }
    }
    cout << ans << '\n';
}

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

详细

Test #1:

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

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: 173ms
memory: 18920kb

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:

131857953346888
127050459973724

result:

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