Two Types of Spells【模拟】

题目链接


  有两种魔法,一种是单纯的伤害为d(0 d),另一种是伤害为d,但是下一次伤害暴击(*2)为(1 d),现在,我们要用已有的魔法来进行组合,使得伤害总值最大。

  那么,很显然的,我们尽可能让值大的去进行“暴击化”处理,于是有如果这个值更大,我们就把这个值放进去暴击堆内去,这样的做法。

  然后,很多细节吧,调了蛮久的。

11
1 1
1 -1
1 2
0 3
0 -3
1 4
1 -4
1 5
0 6
1 -2
1 -5
36
0 136177412
0 -136177412
0 455326434
1 14442996
0 -455326434
0 958682748
1 104290903
0 -958682748
1 -14442996
1 -104290903
1 393108768
1 969925414
1 -393108768
1 -969925414
0 79968028
1 799927246
1 618210305
0 -79968028
1 -799927246
1 116180540
1 -116180540
1 -618210305
0 255573897
0 -255573897
0 295690421
0 -295690421
0 126320824
0 480081046
0 164983131
0 -480081046
1 402044589
0 -164983131
0 449987533
0 -449987533
1 927277221
1 -402044589
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
int N, can_push_in;
set inque, no_inque[2], minn[2];
map is_it_in, spells;
/* 1 times or 2 times */
void Push_in_1(int x)
{
    no_inque[spells[x]].insert(x);
    is_it_in[x] = false;
}
void Pop_out_1(int x)
{
    no_inque[spells[x]].erase(x);
}
void Push_in_2(int x)
{
    inque.insert(x);
    is_it_in[x] = true;
    minn[spells[x]].insert(x);
}
void Pop_out_2(int x)
{
    inque.erase(x);
    is_it_in[x] = false;
    minn[spells[x]].erase(x);
}
/*max or min value*/
int Min_Inque()
{
    if(inque.empty()) return 0;
    return *inque.begin();
}
int Min_In_0()
{
    if(minn[0].empty()) return 0;
    return *minn[0].begin();
}
int Min_In_1()
{
    if(minn[1].empty()) return 0;
    return *minn[1].begin();
}
int Max_not_in_0()
{
    if(no_inque[0].empty()) return 0;
    return *no_inque[0].rbegin();
}
int Max_not_in_1()
{
    if(no_inque[1].empty()) return 0;
    return *no_inque[1].rbegin();
}
/*end*/
int main()
{
    scanf("%d", &N);
    can_push_in = 0;
    ll ans = 0;
    for(int i=1, op, d, x, y, tmp, p; i<=N; i++)
    {
        scanf("%d%d", &op, &d);
        switch (op)
        {
            case 0:
            {
                if(d > 0)
                {
                    spells[d] = false;
                    if(can_push_in > inque.size())
                    {
                        Push_in_2(d);
                        ans += 2 * d;
                    }
                    else
                    {
                        x = Min_Inque();
                        if(x && d > x)
                        {
                            Pop_out_2(x);
                            Push_in_1(x);
                            ans -= x;
                            Push_in_2(d);
                            ans += 2 * d;
                        }
                        else
                        {
                            Push_in_1(d);
                            ans += d;
                        }
                    }
                }
                else
                {
                    d = -d;
                    if(is_it_in[d])
                    {
                        Pop_out_2(d);
                        ans -= 2 * d;
                        x = Max_not_in_0();
                        y = Max_not_in_1();
                        tmp = max(x, y);
                        if(minn[1].size() == can_push_in - 1)
                        {
                            if(x)
                            {
                                Push_in_2(x);
                                Pop_out_1(x);
                                ans += x;
                            }
                        }
                        else
                        {
                            if(tmp)
                            {
                                Push_in_2(tmp);
                                Pop_out_1(tmp);
                                ans += tmp;
                            }
                        }
                    }
                    else
                    {
                        Pop_out_1(d);
                        ans -= d;
                    }
                }
                break;
            }
            default:
            {
                if(d > 0)
                {
                    spells[d] = true;
                    p = Max_not_in_1();
                    if(d < p)
                    {
                        ans += d;
                        Push_in_1(d);
                        Pop_out_1(p);
                        ans -= p;
                        d = p;
                    }
                    if(can_push_in == inque.size() + 1)
                    {
                        Push_in_2(d);
                        ans += 2 * d;
                    }
                    else
                    {
                        x = Max_not_in_0();
                        y = Max_not_in_1();
                        tmp = max(x, y);
                        if(can_push_in)
                        {
                            if(d > tmp)
                            {
                                Push_in_2(d);
                                ans += 2 * d;
                            }
                            else
                            {
                                Pop_out_1(tmp);
                                Push_in_2(tmp);
                                Push_in_1(d);
                                ans += d;
                                ans += tmp;
                            }
                        }
                        else
                        {
                            Push_in_1(d);
                            ans += d;
                            x = Max_not_in_0();
                            if(x)
                            {
                                Pop_out_1(x);
                                Push_in_2(x);
                                ans += x;
                            }
                        }
                    }
                    can_push_in++;
                }
                else
                {
                    d = -d;
                    can_push_in--;
                    if(is_it_in[d])
                    {
                        Pop_out_2(d);
                        ans -= 2 * d;
                    }
                    else
                    {
                        Pop_out_1(d);
                        ans -= d;
                        x = Min_In_0();
                        y = Min_In_1();
                        tmp = x && y ? min(x, y) : x ^ y;
                        if(minn[1].size() == can_push_in)
                        {
                            if(y)
                            {
                                Pop_out_2(y);
                                Push_in_1(y);
                                ans -= y;
                            }
                            else
                            {
                                if(x)
                                {
                                    Pop_out_2(x);
                                    Push_in_1(x);
                                    ans -= x;
                                }
                            }
                        }
                        else
                        {
                            Pop_out_2(tmp);
                            Push_in_1(tmp);
                            ans -= tmp;
                        }
                    }
                }
                break;
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}

 

你可能感兴趣的:(模拟,模拟)