首页 > 其他分享 >专题2024.03.21

专题2024.03.21

时间:2024-03-20 22:34:10浏览次数:19  
标签:pre nxt 专题 return 21 2024.03 int long define

2024.03.21专题

T1 Bombs

答案显然具有单调性,多删一定比少删更优,这是明显的

一个数 \(a_i=x\) 不被删掉的充要条件为:

\[\sum\limits_{j=1}^{i-1}[a_j < x] \leq k \]

其中 \(k\) 为 \(i\) 之前的炸弹数量

由单调性,考虑每次加一个炸弹后怎么快速的检查一个数合不合法,可以用线段树维护全局的 \(max\) 和区间加

时间复杂度为 \(\mathcal{O}(nlogn)\)

code
// Author: xiaruize
#ifndef ONLINE_JUDGE
#define debug(x) cerr << "On Line:" << __LINE__ << #x << "=" << x << endl
bool start_of_memory_use;
#else
#define debug(x)
#endif
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
clock_t start_clock = clock();
#endif
#define int long long
#define ull unsigned long long
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pis pair<int, string>
#define sec second
#define fir first
#define sz(a) int((a).size())
#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl
#define mms(arr, n) memset(arr, n, sizeof(arr))
#define rep(i, a, n) for (int i = (a); i <= (n); ++i)
#define per(i, n, a) for (int i = (n); i >= (a); --i)
int max(int a, int b)

{
    if (a > b)
        return a;
    return b;
}
int min(int a, int b)
{
    if (a < b)
        return a;
    return b;
}
const int INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const int N = 3e5 + 10;

struct segment_tree
{
#define ls p << 1
#define rs p << 1 | 1
    struct node
    {
        int mx, lz;

        void tag(int x)
        {
            mx += x;
            lz += x;
        }
    } tr[N << 2];

    void pushdown(int p)
    {
        tr[ls].tag(tr[p].lz);
        tr[rs].tag(tr[p].lz);
        tr[p].lz = 0;
    }

    void pushup(int p)
    {
        tr[p].mx = max(tr[ls].mx, tr[rs].mx);
    }

    void update(int p, int l, int r, int ll, int rr, int v)
    {
        if (ll <= l && r <= rr)
        {
            tr[p].tag(v);
            return;
        }
        pushdown(p);
        int mid = l + r >> 1;
        if (mid >= ll)
            update(ls, l, mid, ll, rr, v);
        if (mid < rr)
            update(rs, mid + 1, r, ll, rr, v);
        pushup(p);
    }
} seg;

int n;
int p[N], q[N], pos[N];

void solve()
{
    cin >> n;
    rep(i, 1, n)
    {
        cin >> p[i];
        pos[p[i]] = i;
    }
    rep(i, 1, n) cin >> q[i];
    seg.update(1, 1, n, 1, pos[n], 1);
    int res = n;
    cout << n << ' ';
    rep(i, 1, n - 1)
    {
        seg.update(1, 1, n, 1, q[i], -1);
        while (seg.tr[1].mx <= 0)
        {
            res--;
            seg.update(1, 1, n, 1, pos[res], 1);
        }
        cout << res << ' ';
    }
}

#ifndef ONLINE_JUDGE
bool end_of_memory_use;
#endif

signed main()
{
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int testcase = 1;
    // cin >> testcase;
    while (testcase--)
        solve();
#ifndef ONLINE_JUDGE
    cerr << "Memory use:" << (&end_of_memory_use - &start_of_memory_use) / 1024.0 / 1024.0 << "MiB" << endl;
    cerr << "Time use:" << (double)clock() / CLOCKS_PER_SEC * 1000.0 << "ms" << endl;
#endif
    return 0;
}

T2 P1484 种树

\(dp\) 是 \(\mathcal{O}(nk)\) 的,且不太好优化,故考虑贪心

假设当前选择了 \(a_x\),且 \(a_x\) 周围2格都是空,那么下一步有两种情况

  1. 选择 \(a_{x-1},a_{x+1}\) 并删除 \(a_x\)
  2. 选择不与 \(a_x\) 相邻的数 \(a_y\)
对于第一种情况的证明

考虑删除 \(a_x\) 后不选择 \(a_{x-1},a_{x+1}\)

那么,选择 \(a_x\) 和新增的一个数必然覆盖的区间更小且价值更大

所以是不优的

所以如果删除 \(a_x\) 则必然选择 \(a_{x-1},a_{x+1}\)

用链表和优先队列维护,每次选择一个,将两侧的删掉,当前的的权值改为 \(a_x\leftarrow a_{x-1}+a_{x+1}-a_x\) 并重新压入优先队列

code
// Author: xiaruize
#ifndef ONLINE_JUDGE
#define debug(x) cerr << "On Line:" << __LINE__ << #x << "=" << x << endl
bool start_of_memory_use;
#else
#define debug(x)
#endif
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
clock_t start_clock = clock();
#endif
#define int long long
#define ull unsigned long long
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pis pair<int, string>
#define sec second
#define fir first
#define sz(a) int((a).size())
#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl
#define mms(arr, n) memset(arr, n, sizeof(arr))
#define rep(i, a, n) for (int i = (a); i <= (n); ++i)
#define per(i, n, a) for (int i = (n); i >= (a); --i)
int max(int a, int b)

{
    if (a > b)
        return a;
    return b;
}
int min(int a, int b)
{
    if (a < b)
        return a;
    return b;
}
const int INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const int N = 3e5 + 10;

int n, k;
int a[N << 1], pre[N], nxt[N];
priority_queue<pii> q;
bool vis[N];

void del(int x)
{
    nxt[pre[x]] = nxt[x];
    pre[nxt[x]] = pre[x];
}

void solve()
{
    cin >> n >> k;
    rep(i, 1, n)
    {
        cin >> a[i];
        pre[i] = i - 1;
        nxt[i] = i + 1;
        q.push({a[i], i});
    }
    int res = 0;
    int ans = 0;
    while (k--)
    {
        while (vis[q.top().second])
            q.pop();
        int x = q.top().second;
        q.pop();
        res += a[x];
        ans = max(ans, res);
        a[x] = a[pre[x]] + a[nxt[x]] - a[x];
        q.push({a[x], x});
        vis[pre[x]] = vis[nxt[x]] = true;
        del(pre[x]);
        del(nxt[x]);
    }
    cout << ans << endl;
}

#ifndef ONLINE_JUDGE
bool end_of_memory_use;
#endif

signed main()
{
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int testcase = 1;
    // cin >> testcase;
    while (testcase--)
        solve();
#ifndef ONLINE_JUDGE
    cerr << "Memory use:" << (&end_of_memory_use - &start_of_memory_use) / 1024.0 / 1024.0 << "MiB" << endl;
    cerr << "Time use:" << (double)clock() / CLOCKS_PER_SEC * 1000.0 << "ms" << endl;
#endif
    return 0;
}

标签:pre,nxt,专题,return,21,2024.03,int,long,define
From: https://www.cnblogs.com/xiaruize/p/18086242

相关文章

  • 水果软件FL Studio 21 for mac 21.2.3.3586破解版的最新版本2024介绍安装
    音乐是人类最美好的语言,它能够跨越国界、文化和语言,将人们紧密地联系在一起。在当今数字化时代,音乐创作已经不再是专业人士的专利,越来越多的音乐爱好者开始尝试自己动手制作音乐。而FLStudio21中文版编曲软件正是这样一个为你打开音乐创作之门的工具。FLStudio21中文版编......
  • 中考英语首字母快速突破012-2021上海青浦英语二模-Earth Hour: A Global Call for Env
    PDF格式公众号回复关键字:ZKSZM012原文​WhatisEarthHour?​EarthHourisorganizedbytheWorldWideFundforNature(WWF)andit’sabigeventusuallyattheendofMarcheveryyear.Onthisevening,people‘godark’-thatis,switcho......
  • 模拟赛记录2024.03
    2024.03模拟赛记录2024.03.20TheBrickTowerMediumDivOne不考虑相同元素顺序,最优解的形式为,将原序列从小到大排序,从前往后依次放在当前答案的开头或者结尾考虑相同元素的影响,发现在贪心的同时记录当前放在首尾的同样元素的编号然后贪心的把小的编号靠前即可code//Autho......
  • 【漏洞复现】Progress Kemp LoadMaster 命令注入漏洞(CVE-2024-1212)
    0x01产品简介ProgressKempLoadMaster是一款高性能的应用交付控制器,具有可扩展性,支持实体硬件和虚拟机的负载均衡。它提供了当今应用服务所需的各种功能,包括深度用户验证、资安防护(如WAF/IPS/DDoS防护)以及零信任架构服务。这款控制器旨在为各种规模的企业和单位提供出色的负......
  • 每日一看大模型新闻(2024.1.20-1.21)英伟达新对话QA模型准确度超GPT-4,却遭吐槽:无权重代
    1.产品发布1.1韩国Kakao:推出多模态大模型Honeybee发布日期:2024.1.20KakaounveilsmultimodallargelanguagemodelHoneybee-TheKoreaTimes主要内容:韩国科技巨头Kakao今天宣布他们已经开发了一种名为“蜜蜂”(Honeybee)的多模态大语言模型。据Kakao称,“蜜蜂”能够同时......
  • FL Studio21.2.2最新破解中文版编曲软件功能及使用讲解
     音乐是人类最美好的语言,它能够跨越国界、文化和语言,将人们紧密地联系在一起。在当今数字化时代,音乐创作已经不再是专业人士的专利,越来越多的音乐爱好者开始尝试自己动手制作音乐。而FLStudio21中文版编曲软件正是这样一个为你打开音乐创作之门的工具。FLStudio21中文版编......
  • 三分钟手把手教你激活flstudio21.2.3.4004中文破解版2024年图文激活教程
    flstudio21是什么软件?​flstudio21是由比利时软件公司Image-Line开发的音乐制作软件,它拥有丰富的音效、合成器、采样器、鼓机等工具。FL Studio支持多种音频文件格式,包括MIDI、MP3、WAV、OGG等,可以帮助用户自由地进行音乐创作。flstudio21.2.3.4004中文破解版作为一款极具......
  • 1-21 继承丶合理化复制丶抽象
    一为什么要学习继承?类与类之间具备某些内在的联系,一般指具有相同含义的属性或者相同(类似)的功能所谓的继承将多个类之间存在的共同点(成员属性和成员方法)抽取出来,定义在指定的类中,这个类就称之为父类(或超类基类);存放特性的类叫做子类,而父子类之间具备的关系---......
  • P2181 对角线
    原题链接题解有点思维,已知一个交点不会有三条对角线经过,所以有且只有两条对角线经过,而两条对角线又对应四个顶点,所以变成了组合数学,n个顶点里取四个。为了防止溢出,这里做了一些处理code#include<bits/stdc++.h>usingnamespacestd;intmain(){longlongn;cin>......
  • [HAOI2007][洛谷P2218]覆盖问题
    看到这道题,思考一下后发现要用二分答案。所以为什么要用二分?因为标签有二分还在二分专题里因为对于\(ans\)来说,如果\(ans\)不行,那么\(ans-1\)也一定不行;也就是说,答案满足单调性,所以可以二分;也是因为暴力明显过不了那么对于平面上的一些点来说,如果我们用一个最小的矩形......