QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#264374 | #7689. Flipping Cards | qkm66666# | RE | 0ms | 0kb | C++17 | 1.7kb | 2023-11-25 13:50:50 | 2023-11-25 13:50:50 |
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: 0
Dangerous Syscalls
input:
5 3 6 5 2 4 7 6 4 2 8