QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#248061#7689. Flipping CardsYshanqianWA 1ms5524kbC++142.0kb2023-11-11 17:18:482023-11-11 17:18:50

Judging History

你现在查看的是最新测评结果

  • [2023-11-11 17:18:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5524kb
  • [2023-11-11 17:18:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define xx first
#define yy second
#define endl "\n"
#define lowbit(x) x & (-x)
#define int long long
#define ull unsigned long long
#define pb push_back
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define Ysanqian ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
const int N = 1e6 + 10, M = 1010, inf = 0x3f3f3f3f, mod = 18446, P = 13331;
const double eps = 1e-8;
int n;
int s[N];
int b[N];
PII p[N];
bool check(int mid)
{
    for (int i = 1; i <= n; i++)
    {
        if (p[i].xx < mid && p[i].yy >= mid)
            b[i] = 1;
        else if (p[i].xx >= mid && p[i].yy < mid)
            b[i] = -1;
        else
            b[i] = 0;
        s[i] += s[i - 1] + b[i];
    }
    int l = 1, r = 1;
    int ansl = 0, ansr = 0;
    vector<int> ans;
    int mx = 0;
    while (r <= n)
    {
        if (s[r] - s[l - 1] >= 0)
        {
            if (s[r] - s[l - 1] > mx)
            {
                mx = s[r] - s[l - 1];
                ansl = l;
                ansr = r;
            }
        }
        else
            l = r + 1;
        r++;
    }
    for (int i = 1; i <= n; i++)
    {
        if (i >= ansl && i <= ansr)
            ans.pb(p[i].yy);
        else
            ans.pb(p[i].xx);
    }
    sort(ans.begin(), ans.end());
    int x = ans[n / 2];
    if (x >= mid)
        return true;
    return false;
}
void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> p[i].xx >> p[i].yy;
    int l = 0, r = 1e9 + 10;
    while (l < r)
    {
        int mid = l + r + 1 >> 1;
        if (check(mid))
            l = mid;
        else
            r = mid - 1;
    }
    cout << r << endl;
}
signed main()
{
    Ysanqian;
    int T;
    T = 1;
    // cin >> T;
    for (int cases = 1; cases <= T; ++cases)
    {
        // cout<<"Case #"<<cases<<": ";
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5444kb

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: 1ms
memory: 5488kb

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 5484kb

input:

1
212055293 384338286

output:

384338286

result:

ok 1 number(s): "384338286"

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 5524kb

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:

500976567

result:

wrong answer 1st numbers differ - expected: '528957505', found: '500976567'