QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573563 | #9313. Make Max | cjl000 | RE | 0ms | 3572kb | C++23 | 3.0kb | 2024-09-18 19:14:17 | 2024-09-18 19:14:18 |
Judging History
answer
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<math.h>
#include<string.h>
#include<deque>
#include<string>
#include<queue>
#include<cstring>
#include<string>
#include<numeric>
#include<bitset>
#include<array>
#include<stack>
using namespace std;
#define lowbit(x) x & ( -x )
#define endl '\n'
#define itn long long
#define int long long
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define ull unsigned long long
#define bug cout<<"bug"<<endl;
//const int p = 131;
const ull hx = 13331;
int dx[6] = { 0,1,0,-1 };
int dy[6] = { 1,0,-1,0 };
const int N = 10004;
int a[200005];
void tt()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int now = a[1];
map<int, set<pair<int, int>>>mp;
set<int>st;
int l = 1;
for (int i = 2; i <= n; i++)
{
if (a[i] != now)
{
st.insert(a[i - 1]);
mp[a[i - 1]].insert({ l,i - 1 });
l = i, now = a[i];
}
}
st.insert(a[n]);
mp[a[n]].insert({ l,n });
int ans = 0;
for (auto i : st)
{
for (auto t : mp[i])
{
int l = t.first, r = t.second;
if (l == 1)
{
if (r == n)
{
cout << ans << endl;
return;
}
int cnt = a[r + 1];
auto tt = mp[cnt].lower_bound({ r + 1,r + 1 });
ans += r - l + 1;
a[l] = a[r + 1];
mp[cnt].insert({ l,(*tt).second });
mp[cnt].erase(tt);
continue;
}
if (r == n)
{
if (l == 1)
{
cout << ans << endl;
return;
}
int cnt = a[l - 1];
auto tt = prev(mp[cnt].lower_bound({ l,l }));
ans += r - l + 1;
mp[cnt].insert({ (*tt).first, r });
mp[cnt].erase(tt);
continue;
}
int cnt1 = a[l - 1], cnt2 = a[r + 1];
ans += r - l + 1;
if (cnt1 < cnt2)
{
int cnt = cnt1;
auto tt = prev(mp[cnt].lower_bound({ l,l }));
ans += r - l + 1;
mp[cnt].insert({ (*tt).first, r });
mp[cnt].erase(tt);
}
else
{
int cnt = a[r] + 1;
auto tt = mp[cnt].lower_bound({ r + 1,r + 1 });
ans += r - l + 1;
a[l] = a[r + 1];
mp[cnt].insert({ l,(*tt).second });
mp[cnt].erase(tt);
}
}
}
cout << ans << endl;
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
tt();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
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
Runtime Error
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...