QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578219#9313. Make MaxTolretWA 694ms31980kbC++201.7kb2024-09-20 17:27:562024-09-20 17:27:56

Judging History

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

  • [2024-09-20 17:27:56]
  • 评测
  • 测评结果:WA
  • 用时:694ms
  • 内存:31980kb
  • [2024-09-20 17:27:56]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int maxn=1e6+5;
const int inf=1e18;
int tt=1;
int n,a[maxn];
void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    set<array<int,3>>p,pp;
    for(int i=1;i<=n;i++)
    {
        p.insert({a[i],i,i});
        pp.insert({i,i,a[i]});
    }
    int ans=0;
    while((int)p.size()>1)
    {
        auto p1=p.begin();
        array<int,3>pp1=*p1;
        auto q1=pp.find({pp1[1],pp1[2],pp1[0]});
        array<int,3> qq1=*q1;
        if(q1==pp.begin())
        {
            auto  q2=q1;++q2;
            array<int,3>qq2=*q2;
            auto p2=p.find({qq2[2],qq2[0],qq2[1]});
            array<int,3>pp2=*p2;
            p.erase(p1);p.erase(p2);
            pp.erase(q1);pp.erase(q2);
            if(pp1[0]!=pp2[0])
            ans+=pp1[2]-pp1[1]+1;
            p.insert({pp2[0],pp1[1],pp2[2]});
            pp.insert({pp1[1],pp2[2],pp2[0]});
        }
        else
        {
            auto  q2=q1;--q2;
            array<int,3>qq2=*q2;
            auto p2=p.find({qq2[2],qq2[0],qq2[1]});
            array<int,3>pp2=*p2;
            p.erase(p1);p.erase(p2);
            pp.erase(q1);pp.erase(q2);
            if(pp1[0]!=pp2[0])
                ans+=pp1[2]-pp1[1]+1;
            p.insert({pp2[0],pp1[1],pp2[2]});
            pp.insert({pp1[1],pp2[2],pp2[0]});
        }
    }
    cout<<ans<<'\n';
}
signed main()
{
	ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout<<fixed<<setprecision(10);
    cin>>tt;
    for(int i=1;i<=tt;i++)
    solve();
}

詳細信息

Test #1:

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

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: 694ms
memory: 31980kb

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:

-1655295
-1864644

result:

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