QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#805042#1458. Binary Search AlgorithmRong7RE 0ms0kbC++143.6kb2024-12-08 12:12:302024-12-08 12:12:30

Judging History

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

  • [2024-12-08 12:12:30]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-12-08 12:12:30]
  • 提交

answer

// Go in my style.
// Not afraid to dark.

#include <bits/stdc++.h>
using namespace std;

clock_t sttime;
#define STCLOCK sttime = clock ();
#define TIMENOW fprintf (stderr, "\nNOW TIME COSSEMED: %0.4lf\n", 1.0 * (clock () - sttime) / CLOCKS_PER_SEC);
#define inline __inline__ __attribute__ ((always_inline))

#define FS fflush (stdout)

namespace io {
    int read_pos, read_dt; char read_char;
    inline int read (int &p = read_pos){
        p = 0, read_dt = 1; read_char = getchar ();
        while (! isdigit (read_char)){
            if (read_char == '-')
                read_dt = - 1;
            read_char = getchar ();
        }
        while (isdigit (read_char)){
            p = (p << 1) + (p << 3) + read_char - 48;
            read_char = getchar ();
        }
        return p = p * read_dt;
    }
    int write_sta[65], write_top;
    inline void write (int x){
        if (x < 0)
            putchar ('-'), x = - x;
        write_top = 0;
        do
            write_sta[write_top ++] = x % 10, x /= 10;
        while (x);
        while (write_top)
            putchar (write_sta[-- write_top] + 48);
    }
    inline char next_blank (){
        static char c; c = getchar ();
        while (c < 'a' || c > 'z') c = getchar ();
        return c;
    }
}

const int N = 8e3;
int n;

namespace HEAP {
    #define lson(p) ((p) << 1)
    #define rson(p) ((p) << 1 | 1)
    const int P = N * 4;
    int tot, rp[P], mins[P], bel[P];
    struct que {
        vector < int > q, pos; unordered_map < int , int > to;
        inline void push (int x){ x <= tot ? (q.push_back (rp[x]), pos.push_back (x)) : void (); }
        inline void query (){
            sort (q.begin (), q.end ());
            q.erase (unique (q.begin (), q.end ()), q.end ());
            io::write ((int) q.size ());
            for (int x : q) putchar (' '), io::write (x);
            putchar ('\n'); FS;
            for (int i = 0;i < (int) q.size ();++ i)
                io::read (q[i]), to[q[i]] = i;
        }
        inline void clear (){ q.clear (), to.clear (), pos.clear (); }
        que (){ clear (); }
    };
    inline void upd (int x){
        if (! tot) return puts ("0"), FS, void ();
        static que Q; Q.clear ();
        static int u;
        Q.push (x);
        for (u = x;u <= tot;){
            Q.push (lson (u)); Q.push (rson (u));
            u = mins[u];
        }
        for (u = x;u >> 1;){
            Q.push (u >> 1); Q.push (u ^ 1);
            u >>= 1;
        }
        Q.query (); vector < int > l;
        for (u = x;mins[u] <= tot && Q.to[rp[mins[u]]] < Q.to[rp[u]];u = mins[u])
            swap (rp[mins[u]], rp[u]), l.push_back (u);
        for (u = x;(u >> 1) && Q.to[rp[u >> 1]] > Q.to[rp[u]];u >>= 1)
            swap (rp[u >> 1], rp[u]), l.push_back (u);
        for (int u : l)
            if (rson (u) > tot) mins[u] = lson (u);
            else mins[u] = Q.to[rp[lson (u)]] < Q.to[rp[rson (u)]] ? lson (u) : rson (u);
        for (int u : Q.pos) bel[rp[u]] = u;
    }
} using namespace HEAP;

signed main (){
    STCLOCK

    io::read (n);
    for (int T = n << 1, x;T --;){
        if (io::next_blank () == 'a'){
            rp[++ tot] = io::read (x); bel[x] = tot;
            mins[tot] = lson (tot); upd (tot);
        } else {
            if (rp[bel[x]] != x) exit (1);
            io::read (x); swap (rp[bel[x]], rp[tot]);
            if ((tot & 1) && (tot >> 1)) mins[tot >> 1] = tot ^ 1;
            -- tot; upd (bel[x]);
        }
        io::write (tot ? rp[1] : - 1), putchar ('\n'); FS;
    }

    TIMENOW
    return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

3
add 1
1
add 3
3 1
delete 1
3
add 2
3 2
delete 3
2
delete 2

output:

1 1
1
2 1 3
3
1 3
3
2 2 3
3
1 2
2

result: