QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#264378#7689. Flipping Cardsqkm66666#WA 1ms5808kbC++171.7kb2023-11-25 13:51:342023-11-25 13:51:35

Judging History

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

  • [2023-11-25 13:51:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5808kb
  • [2023-11-25 13:51:34]
  • 提交

answer

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<cstdio>
#include<cctype>
#include<vector>
#include<bitset>
#include<random>
#include<ctime>
#include<queue>
#include<cmath>
#include<list>
#include<map>
#include<set>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<long long,long long>
#define FF fflush(stdout)
#define inf 0x3f3f3f3f
#define endl "\n"
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
//char buf[1<<20],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline int read()
{
    int s=0,f=1;
    char x=getchar();
    while(!isdigit(x))f=(x=='-'?-1:1),x=getchar();
    while(isdigit(x))s=s*10+x-'0',x=getchar();
    return s*f;
}
const int p=1e9+7;
//ll ksm(int a,int b){ll ans=1,bs=a;while(b){if(b&1)ans=ans*bs%p;bs=bs*bs%p;b>>=1;}return ans;}
mt19937 rd(time(0));
#define reaD read
int a[300005],b[300005];
int n;
int up;
bool ck(int x)
{
    int s=0,mi=0;
    int d=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<x&&b[i]<x)d--;
        else if(a[i]>=x&&b[i]>=x)d++;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]>=x&&b[i]<x)s--;
        else if(a[i]<x&&b[i]>=x)s++;
        mi=min(mi,s);
        if(s-mi+d>=up)return 1;
    }
    return 0;
}
int main()
{
    n=read();
    int up=(n+1)/2;
    for(int i=1;i<=n;i++)
    a[i]=reaD(),b[i]=reaD();
    int l=1,r=1e9;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(ck(mid))l=mid+1;
        else r=mid-1;
    }
    printf("%d",r);
    // system("pause");
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3956kb

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: 5808kb

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

1
212055293 384338286

output:

384338286

result:

ok 1 number(s): "384338286"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3768kb

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:

502470196

result:

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