QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666357#9313. Make MaxSaptak3315WA 457ms17196kbC++202.1kb2024-10-22 17:58:172024-10-22 17:58:28

Judging History

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

  • [2024-10-22 17:58:28]
  • 评测
  • 测评结果:WA
  • 用时:457ms
  • 内存:17196kb
  • [2024-10-22 17:58:17]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tc=1,tc1=1;
    cin>>tc;
    up:
    while(tc--){
      ll n;
      cin>>n;
      vector<ll>a(n+5);
      for(ll i=1;i<=n;i++){
        cin>>a[i];
      }
      ll c=0,lst=a[1];
      set<array<ll,3>>st;
      for(ll i=1;i<=n;i++){
        if(a[i]==lst){
          c++;
        }
        else {
          st.insert({lst,i-c,i-1});
          c=1,lst=a[i];
        }
      }
      st.insert({lst,n-c+1,n});
      ll ans=0;
      while(1){
        if(st.size()==1){
          break;
        }
        auto v=*st.begin();
        st.erase(v);
        ll val=v[0],sta=v[1],en=v[2],mn=1e18;
        ans+=(v[2]-v[1]+1);
        //cout<<val<<" "<<sta<<" "<<en<<' ';
        if(sta!=1){
          mn=a[sta-1];
        }
        if(en!=n){
          mn=min(mn,a[en+1]);
        }
        for(ll i=sta;i<=en;i++){
          a[i]=mn;
        }
        if(a[sta-1]==a[en+1]){
          ll fr=0,ba=n+1;
          for(ll i=sta-2;i>=1;i--){
            if(a[i]!=a[i+1]){
              fr=i;
              break;
            }
          }
          for(ll i=en+2;i<=n;i++){
            if(a[i]!=a[i-1]){
              ba=i;
              break;
            }
          }
          st.erase({mn,fr+1,sta-1});
          st.erase({mn,en+1,ba-1});
          st.insert({mn,fr+1,ba-1});
          cout<<ans<<"\n";
          continue;
        }
        if(mn==a[sta-1]){
          ll lst=0;
          for(ll i=sta-2;i>=1;i--){
            if(a[i]!=a[i+1]){
              lst=i;
              break;
            }
          }
          st.erase({mn,lst+1,sta-1});
          st.insert({mn,lst+1,en});
        }
        else {
          ll lst=n+1;
          for(ll i=en+2;i<=n;i++){
            if(a[i]!=a[i-1]){
              lst=i;
              break;
            }
          }
          st.erase({mn,en+1,lst-1});
          st.insert({mn,sta,lst-1});
        }
        //cout<<ans<<"\n";
      }
      cout<<ans<<'\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 457ms
memory: 17196kb

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:

4084978
4130372

result:

ok 2 number(s): "4084978 4130372"

Test #3:

score: -100
Wrong Answer
time: 432ms
memory: 17172kb

input:

2
195768
3086 1582 7854 5577 5243 2734 8054 4805 5686 7065 5555 2410 6240 7589 2889 3745 8094 9147 9438 1252 5497 5786 6655 4437 3933 2579 5722 9512 3117 1742 5362 2068 1853 4069 9231 1126 3991 420 2571 5517 3063 7279 8085 6111 5503 5980 50 6003 244 9684 6343 6517 1598 5223 5520 982 3932 1093 1149 7...

output:

625
7420
17692
25527
38997
43298
56598
57364
58433
134533
147045
175853
197555
204942
225427
226611
230043
230672
265402
274415
274903
296481
306733
313279
314604
330256
333804
367493
378706
384060
387440
391021
399420
401371
430650
444354
455644
471334
474381
493166
497025
535654
537325
543777
5447...

result:

wrong answer 1st numbers differ - expected: '3061429', found: '625'