QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619618 | #7689. Flipping Cards | ty09# | WA | 0ms | 3612kb | C++17 | 2.0kb | 2024-10-07 14:48:52 | 2024-10-07 14:48:53 |
Judging History
answer
// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(nullptr),cout.tie(nullptr)
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define T() int ____t;cin>>____t;while(____t--)
using namespace std;
constexpr int N=2e6+10,mod=1e9+7;
#define int ll
template <typename T> // 选用int || long long
struct Mid_set
{
multiset<T, greater<T>> st1; //小于中位数的数的集合
multiset<T> st2; //大于等于中位数的集合
// st2.size() ≥ st1.size();
ll sum1 = 0, sum2 = 0;
void split()
{
while (st1.size() < st2.size())
{
T now = *st2.begin();
sum2 -= now;
sum1 += now;
st1.insert(now);
st2.erase(st2.begin());
}
while (st1.size() > st2.size())
{
T now = *st1.begin();
st2.insert(now);
sum1 -= now;
sum2 += now;
st1.erase(st1.begin());
}
}
void insert(T x)
{
st2.insert(x);
sum2 += x;
split();
}
void erase(T x)
{
if (st1.count(x))
{
st1.erase(st1.lower_bound(x));
sum1 -= x;
}
else
{
st2.erase(st2.lower_bound(x));
sum2 -= x;
}
split();
}
bool empty()
{
return st2.empty();
}
T query()//返回中位数
{
return *st2.begin();//有奇数个数
}
ll become_mid() // 通过±1,将所有数变相同所需最少操作数
{
T mid = query();
int s1 = st1.size(), s2 = st2.size();
ll ans = 1ll * s1 * mid - sum1 + sum2 - 1ll * s2 * mid;
return ans;
}
};
void solve(){
int n;
cin>>n;
vector<int>a(n+1),b(n+1);
Mid_set<int>p;
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
p.insert(a[i]);
}
int med=p.query();
int l=1,r=1;
int ans=med;
for(int i=1;i<=n;i++){
p.insert(b[i]);
p.erase(a[i]);
int now=p.query();
ans=max(ans,now);
r=i;
if(now<med){
for(int j=l;j<=r;j++){
p.insert(a[j]);
p.erase(b[j]);
}
l=i+1;
}
}
cout<<ans<<endl;
}
signed main()
{
ios;
// T()
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
input:
5 3 6 5 2 4 7 6 4 2 8
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3580kb
input:
99 749159996 323524232 125448341 365892333 481980673 143665393 394405973 44741918 687549448 513811513 287088118 385131171 11865696 666468353 449920567 373650719 671547289 116780561 41003675 671513243 351534153 507850962 374160874 985661954 222519431 600582098 987220654 704142246 856147059 37783620 1...
output:
512721865
result:
wrong answer 1st numbers differ - expected: '528957505', found: '512721865'