提出 #75858474


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define pb push_back

template<class T> inline bool chmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template<class T> inline bool chmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int MOD = 1e9 + 7;

void solve() {
    
    int x;cin>>x;
    priority_queue<ll> small;
    priority_queue<ll,vector<ll> ,greater<ll>> big;
    small.push(x);

    int q;cin>>q;
    while(q--){
        ll a,b;cin>>a>>b;

        if(a<=small.top()){
            small.push(a);
        }else{
            big.push(a);
        }

        if(b<=small.top()){
            small.push(b);
        }else{
            big.push(b);
        }

        while(small.size()>big.size()+1){
            big.push(small.top());
            small.pop();
        }
        while(small.size()<big.size()+1){
            small.push(big.top());
            big.pop();
        }
        cout<<small.top()<<'\n';
    }

    
    
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int tt = 1;
    //cin >> tt;

    while (tt--) {
        solve();
    }

    return 0;
}

提出情報

提出日時
問題 D - Chalkboard Median
ユーザ lavi3
言語 C++23 (GCC 15.2.0)
得点 400
コード長 1333 Byte
結果 AC
実行時間 54 ms
メモリ 6776 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 25
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3492 KiB
00_sample_01.txt AC 1 ms 3560 KiB
00_sample_02.txt AC 1 ms 3440 KiB
01_random_00.txt AC 41 ms 6776 KiB
01_random_01.txt AC 23 ms 6588 KiB
01_random_02.txt AC 38 ms 6700 KiB
01_random_03.txt AC 39 ms 6708 KiB
01_random_04.txt AC 39 ms 6648 KiB
01_random_05.txt AC 36 ms 6568 KiB
01_random_06.txt AC 28 ms 6644 KiB
01_random_07.txt AC 41 ms 6568 KiB
01_random_08.txt AC 23 ms 5192 KiB
01_random_09.txt AC 40 ms 6512 KiB
01_random_10.txt AC 18 ms 4916 KiB
01_random_11.txt AC 40 ms 6644 KiB
01_random_12.txt AC 47 ms 6700 KiB
01_random_13.txt AC 47 ms 6628 KiB
01_random_14.txt AC 54 ms 6608 KiB
01_random_15.txt AC 53 ms 6652 KiB
01_random_16.txt AC 45 ms 6488 KiB
01_random_17.txt AC 45 ms 6612 KiB
01_random_18.txt AC 44 ms 6636 KiB
01_random_19.txt AC 44 ms 6564 KiB
01_random_20.txt AC 46 ms 6648 KiB
01_random_21.txt AC 46 ms 6488 KiB