Submission #1118279


Source Code Expand

// ba mei zi !

#include<bits/stdc++.h>

#define HEAP priority_queue
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define nrof(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9+7;
const LL linf = 1ll<<60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}

template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }

template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }

template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T>
void chkmax(T &x, const T &y){ if(y > x) x = y; return; }

template <typename T>
void chkmin(T &x, const T &y){ if(y < x) x = y; return; }

#ifdef ONLINE_JUDGE
#define debug(x,c) ;
#else
#define DEBUG
#define debug(x,c) cerr<<#x<<"="<<x<<c;
#endif

#undef DEBUG

//---------------------------head----------------------------

const int N = 2e4 + 100;

int n;
int pos[N], chs[N];
int rnk[N], id[N];
bool vis[N];

namespace BIT_vis
{
    int num[N];
    void init(){ FILL(num, 0); }
    inline int lowbit(int i){ return i & (-i); }
    inline void modify(int i, int x)
    {
        for(; i <= n; i += lowbit(i)) num[i] += x;
        return;
    }
    inline int query(int i)
    {
        int ret = 0;
        for(; i; i ^= lowbit(i)) ret += num[i];
        return ret;
    }
}

namespace BIT_chs
{
    int num[N];
    void init(){ FILL(num, 0); }
    inline int lowbit(int i){ return i & (-i); }
    inline void modify(int i, int x)
    {
        for(; i <= n; i += lowbit(i)) num[i] += x;
        return;
    }
    inline int query(int i)
    {
        int ret = 0;
        for(; i; i ^= lowbit(i)) ret += num[i];
        return ret;
    }
}

void MEI()
{
    int tot = 0;
    map<int, int> M; M.clear();

    scf(n); n <<= 1;
    rep(i, n)
    {
        scf(pos[i]);
        if(M.find(pos[i]) == M.end()) M[pos[i]] = 0;
        ++M[pos[i]];
    }

    for(auto it = M.begin(); it != M.end(); ++it) tot += it -> Y, it -> Y = tot;

    rep(i, n)
    {
        id[M[pos[i]]] = i;
        rnk[i] = M[pos[i]];
        M[pos[i]]--;
    }
    return;
}

vi pool_chs, pool_vis;
int MID;

inline int find_nxt()
{
    int lb = 1, rb = n;
    while(lb <= rb)
    {
        int mid = lb + rb >> 1;
        if(BIT_vis::query(mid) < mid) rb = mid - 1;
        else lb = mid + 1;
    }
    return lb;
}

inline int get_l(int i)
{
    int LB = pos[id[i]] - MID;
    int lb = 1, rb = n;
    while(lb <= rb)
    {
        int mid = lb + rb >> 1;
        int x = pos[id[mid]];
        if(x <= LB) lb = mid + 1;
        else rb = mid - 1;
    }
    return lb;
}

inline int get_r(int i)
{
    int RB = pos[id[i]] + MID;
    int lb = 1, rb = n;
    while(lb <= rb)
    {
        int mid = lb + rb >> 1;
        int x = pos[id[mid]];
        if(x >= RB) rb = mid - 1;
        else lb = mid + 1;
    }
    return rb;
}

inline int find_l(int i)
{
    int sum = BIT_vis::query(i);
    int lb = 1, rb = i - 1;
    while(lb <= rb)
    {
        int mid = lb + rb >> 1;
        int x = BIT_vis::query(mid - 1);
        if(sum - x == (i - mid + 1)) rb = mid - 1;
        else lb = mid + 1;
    }
    return rb;
}

inline int find_r(int i)
{
    int sum = BIT_vis::query(i - 1);
    int lb = i + 1, rb = n;
    while(lb <= rb)
    {
        int mid = lb + rb >> 1;
        int x = BIT_vis::query(mid);
        if(x - sum == (mid - i + 1)) lb = mid + 1;
        else rb = mid - 1;
    }
    return lb;
}

inline bool chk(int i)
{
    #ifdef DEBUG
    printf("\t%d %d:\n\t", i, rnk[id[i] ^ 1]);
    forn(i, 1, n) cout<<chs[i]<<' '; cout<<endl<<'\t';
    forn(i, 1, n) cout<<vis[i]<<' '; cout<<endl;
    #endif // DEBUG
    if(chs[i]) return 1;

    int j = rnk[id[i] ^ 1];
    chs[i] = 1;
    BIT_chs::modify(i, 1);
    pool_chs.pb(i);

    int li = get_l(i), ri = get_r(i);

    #ifdef DEBUG
    cout<<"\t\t"<<li<<' '<<ri<<endl<<endl;
    #endif // DEBUG

    if(BIT_chs::query(ri) - BIT_chs::query(li - 1) > 1) return 0;

    vis[i] = vis[j] = 1;
    BIT_vis::modify(i, 1); BIT_vis::modify(j, 1);
    pool_vis.pb(i); pool_vis.pb(j);

    j = find_l(i);
    while(j >= li)
    {
        if(!chk(rnk[id[j] ^ 1])) return 0;
        j = find_l(j);
    }

    j = find_r(i);
    while(j <= ri)
    {
        if(!chk(rnk[id[j] ^ 1])) return 0;
        j = find_r(j);
    }

    return 1;
}

bool check(int mid)
{
    #ifdef DEBUG
    puts("=====================================================================");
    debug(mid, '\n')
    #endif // DEBUG
    MID = mid;
    FILL(vis, 0); FILL(chs, 0);
    BIT_vis::init(); BIT_chs::init();
    for(;;)
    {
        int i = find_nxt();
        if(i > n) return 1;

        pool_chs.clear();
        pool_vis.clear();

        if(!chk(i))
        {
            for(int i: pool_chs) BIT_chs::modify(i, -1), chs[i] = 0;
            for(int i: pool_vis) BIT_vis::modify(i, -1), vis[i] = 0;

            pool_chs.clear();
            pool_vis.clear();
            i = rnk[id[i] ^ 1];
            if(!chk(i)) return 0;
        }
    }
}

void ZI()
{
    int lb = 0, rb = (pos[id[n]] - pos[id[1]]) / (n / 2 - 1);
    #ifdef DEBUG
    forn(i, 1, n) cout<<id[i]<<' '; cout<<endl;
    rep(i, n) cout<<rnk[i]<<' '; cout<<endl;
    cout<<rb<<endl;
    #endif // DEBUG
    while(lb <= rb)
    {
        int mid = lb + rb >> 1;
        if(check(mid)) lb = mid + 1;
        else rb = mid - 1;
    }
    printf("%d\n", rb);
    return;
}

/*
Main
code
is
over
.
If
you
are
in
a
hurry
trying
to
hack
me
you
don't
need
to
read
the
part
left
.
Trust
me
.
It
is
useless
.
My
code
always
gets
a
failed
system
test
,
so
it
will
be
pretty
easy
for
you
to
hack
me
.
Just
find
a
test
case
and
hack
.
Wish
you
all
happy
hack
.
 _____
/     \
| . . |
|     |
|  |  |
| --- |
| \_/ |
\_____/

*/

#ifdef DEBUG
struct I{ int x; I(){} I(int y):x(y){} bool operator <(const I &a) const{ return x < a.x; }};

pair<I,LL> time_limit_exceeded;
const bool FLAG = 1;
static vector<I> wrong_answer;
I *RP=new I;

I FUCK=min(I{*RP}, I{0});
static int memory_limit_exceeded[10];
vi O(){cout<<FUCK.x<<endl; vi ert; int x=0;
x=(int)hypot(3.0, 4.0); ert.pb(x);
if(x&1)exit(0);
auto t=lower_bound(ALL(ert), 5);
static list<int> runtime_error_;
return ert;}
#endif // DEBUG

#define MEI int
#define ZI main
MEI ZI()
{
#undef MEI
#undef ZI

    MEI();
    ZI();

#define BA return
#define MEI 0
#define ZI ;
BA MEI ZI
#undef BA
#undef MEI
#undef ZI
}

Submission Info

Submission Time
Task F - Flags
User King_George
Language C++14 (GCC 5.4.1)
Score 1200
Code Size 8013 Byte
Status AC
Exec Time 169 ms
Memory 1664 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1200 / 1200
Status
AC × 3
AC × 30
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 512 KB
00_example_02.txt AC 1 ms 512 KB
00_example_03.txt AC 2 ms 512 KB
01.txt AC 4 ms 512 KB
02.txt AC 3 ms 512 KB
03.txt AC 2 ms 512 KB
04.txt AC 2 ms 512 KB
05.txt AC 2 ms 512 KB
06.txt AC 108 ms 1664 KB
07.txt AC 61 ms 1664 KB
08.txt AC 97 ms 1664 KB
09.txt AC 6 ms 512 KB
10.txt AC 3 ms 512 KB
11.txt AC 2 ms 512 KB
12.txt AC 2 ms 512 KB
13.txt AC 2 ms 512 KB
14.txt AC 114 ms 1664 KB
15.txt AC 102 ms 1664 KB
16.txt AC 63 ms 1664 KB
17.txt AC 7 ms 512 KB
18.txt AC 4 ms 512 KB
19.txt AC 169 ms 1536 KB
20.txt AC 169 ms 1536 KB
21.txt AC 17 ms 1024 KB
22.txt AC 17 ms 1024 KB
23.txt AC 10 ms 768 KB
24.txt AC 22 ms 1152 KB
25.txt AC 9 ms 768 KB
26.txt AC 156 ms 1152 KB
27.txt AC 2 ms 512 KB