QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573666 | #9313. Make Max | cjl000 | WA | 793ms | 45572kb | C++23 | 3.4kb | 2024-09-18 19:36:26 | 2024-09-18 19:36:27 |
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;
//cout << l << " " << r << endl;
if (l == 1)
{
if (r == n)
{
cout << ans << endl;
return;
}
int cnt = a[r + 1];
if (cnt == a[l])
continue;
auto tt = mp[cnt].lower_bound({ r + 1,r + 1 });
ans += r - l + 1;
a[l] = a[r + 1];
a[r] = 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];
if (cnt == a[l])
continue;
auto tt = prev(mp[cnt].lower_bound({ l,l }));
ans += r - l + 1;
a[r] = a[l] = (*tt).first;
mp[cnt].insert({ (*tt).first, r });
mp[cnt].erase(tt);
continue;
}
int cnt1 = a[l - 1], cnt2 = a[r + 1];
// cout << 1 << endl;
if (cnt1 <= cnt2)
{
int cnt = cnt1;
if (cnt == a[l])
continue;
ans += r - l + 1;
auto tt = prev(mp[cnt].lower_bound({ l,l }));
a[l] = a[r] = cnt;
mp[cnt].insert({ (*tt).first, r });
mp[cnt].erase(tt);
}
else
{
int cnt = cnt2;
if (cnt == a[l])continue;
ans += r - l + 1;
auto tt = mp[cnt].lower_bound({ r + 1,r + 1 });
a[l] = a[r + 1];
a[l] = a[r] = cnt;
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: 1ms
memory: 3872kb
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: 793ms
memory: 45572kb
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: 436ms
memory: 18700kb
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:
2224100 2226603
result:
wrong answer 1st numbers differ - expected: '3061429', found: '2224100'