QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#578255 | #9313. Make Max | Chief_Ning | TL | 0ms | 3544kb | C++14 | 2.4kb | 2024-09-20 17:46:02 | 2024-09-20 17:46:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define endl "\n"
#define pq priority_queue<int>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define debug1(x) cout<<x<<endl;
#define debug2(a,b) cout<<a<<" "<<b<<endl;
const int INF = 0x3f3f3f3f;//无穷大
const int inf = 0xc0c0c0c0;//无穷小
const int MOD = 1;
const int N = 1;
/*
________ ___ ___ ___ _______ ________ ________ ___ ________ ________
|\ ____\|\ \|\ \|\ \|\ ___ \ |\ _____\\ ___ \|\ \|\ ___ \|\ ____\
\ \ \___|\ \ \\\ \ \ \ \ __/|\ \ \__/\ \ \\ \ \ \ \ \ \\ \ \ \ \___|
\ \ \ \ \ __ \ \ \ \ \_|/_\ \ __\\ \ \\ \ \ \ \ \ \\ \ \ \ \ ___
\ \ \____\ \ \ \ \ \ \ \ \_|\ \ \ \_| \ \ \\ \ \ \ \ \ \\ \ \ \ \|\ \
\ \_______\ \__\ \__\ \__\ \_______\ \__\ \ \__\\ \__\ \__\ \__\\ \__\ \_______\
\|_______|\|__|\|__|\|__|\|_______|\|__| \|__| \|__|\|__|\|__| \|__|\|_______|
*/
void ChiefNing()
{
int n;
cin>>n;
vector<int> v(n);
set<int> s;
int Max_Cnt=0;
for(int i=0;i<n;i++){
cin>>v[i];
s.insert(v[i]);
}
map<int,int> mp,mpp;
int now=1;
for(auto a:s){
mp[a]=now++;
}
now--;
for(int i=0;i<n;i++){
v[i]=mp[v[i]];//离散化
mpp[v[i]]++;
}
int ans=0;
queue<tuple<int,int,int>> qp;
for(int i=0;i<n;i++){
if(v[i]==1){
qp.push({1,i-1,i+1});
}
if(v[i]==now)Max_Cnt++;
}
int kn=1;
while(Max_Cnt!=n){
auto [i,l,r]=qp.front();
qp.pop();
int L=INF,R=INF;
int kk=2;
if(l!=-1&&v[l]!=kn){
L=v[l];
kk--;
}
if(r!=n&&v[r]!=kn){
R=v[r];
kk--;
}
int Min=min(L,R);
if(Min==i||kk==2){
qp.push({i,l,r});
continue;
}//1 1 1 2 2 2 2
ans++;
v[l+1]=Min;
if(Min==now)Max_Cnt++;
if(qp.empty()){
kn++;
for(int ii=0;ii<n;ii++){
if(v[ii]==kn)qp.push({kn,ii-1,ii+1});
}
}
}
cout<<ans<<endl;
}
signed main(void)
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int _;
cin>>_;
while(_--)
ChiefNing();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
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
Time Limit Exceeded
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...