首页 > 其他分享 >CSP模拟57联测19_全球覆盖

CSP模拟57联测19_全球覆盖

时间:2023-10-29 11:44:25浏览次数:49  
标签:ch 每个 19 57 long int 联测 区间 include

题面:

image

赛时给我搞破防了,没有一点思路。

Part1

对于这四种神奇有病的操作,可以把 \(x\)轴 和 \(y\)轴 分开考虑,它们之间互不影响。最后答案就是 \(x\)轴上的最长距离 乘 \(y\)轴上的最长距离。这样就把二维的问题拆分成了两个序列上的问题。现在问题变成了给定几个区间,可以取区间的中间或者两边,求所有区间交集的最大长度。

Part2

把每个区间的端点离散成若干个点,我们发现对于两个点之间的线段,要想要使其成为答案的一部分,每个区间的状态是确定的,这里状态指取中间或者取两边,不存在两种状态都可以的情况。我们把每个区间的状态成为需求。

只要满足需求,这个线段就可以被算进答案里,那我们把需求 哈希 一下, 给每个哈希值累加长度, 最后给每个需求取个 \(\max\) 就可以了

复杂度 \(\Theta(n)\)

Code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>

#define ull unsigned long long

#define int long long

const int N=5e5+10;
const int base=233;

using namespace std;

inline int read() {
    int f=1, x=0;
    char ch=getchar();
    while(ch>'9' || ch<'0') {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9') {
        x=(x<<3)+(x<<1)+(ch^48);
        ch=getchar();
    }
    return f*x;
}

inline void write(int x) {
    cout<<x; putchar('\n');
}

int n, X, Y, ans=1, lim, tot, cnt;
struct Martix {
    int x1, y1;
    int x2, y2;
}mart[N];
struct Point {
    int pos, bel;
}p[N<<1];
ull power[N];

unordered_map <ull, int> mp;

void prework() {
    power[0]=1;
    for(int i=1;i<=N-5;i++) {
        power[i]=power[i-1]*base;
    }
}

bool cmp(Point a,Point b) {
    return a.pos < b.pos;
}

void init(int x) {
    tot=0, lim=x;
    cnt=0, mp.clear();
}

int work() {
    sort(p+1, p+tot+1, cmp);

    int res=0;
    p[++tot].pos=lim;
    ull ha=0;
    mp[0]=p[1].pos;
    for(int i=1;i<tot;i++) {
        int l=p[i].pos, r=p[i+1].pos;
        ha^=power[p[i].bel];
        mp[ha]+=r-l;
        res=max(res,mp[ha]);
    }
    return res;
}

signed main() {

    n=read(), X=read() ,Y=read();

    prework();

    for(int i=1;i<=n;++i) {
        mart[i]=(Martix){read(), read(), read(), read()};
    }

    init(X);
    for(int i=1;i<=n;i++) {
        p[++tot].pos=mart[i].x1;
        p[tot].bel=i;

        p[++tot].pos=mart[i].x2;
        p[tot].bel=i;
    }
    ans*=work();

    init(Y);
    for(int i=1;i<=n;i++) {
        p[++tot].pos=mart[i].y1;
        p[tot].bel=i;

        p[++tot].pos=mart[i].y2;
        p[tot].bel=i;
    }
    ans*=work();

    write(ans);

    return 0;
}

标签:ch,每个,19,57,long,int,联测,区间,include
From: https://www.cnblogs.com/cwymp/p/17795676.html

相关文章

  • SharePoint 2019开发:如何通过脚本来变更SharePoint Group的 Permission Level
    Blog链接:https://blog.51cto.com/13969817很多企业出于安全管理需要,ITadmin需要根据SecurityPolicy或者审计要求定期批量的修改SharePoint权限,比如添加或者删除某个用户,或者更换某个Group的Permissionlevel等等,如果单纯的修改一个网站,那么我们可以直接到SiteSettings的Permiss......
  • 19 redis实现分布式锁
    使用setnx命令获取锁,然后使用expire命令,保证有个过期时间,让锁能够及时释放。setnx的含义是,当要设置的key不存在时,那么这个字符串设置成功。否则,就会设置失败。它避免了重复执行命令,导致前值被覆盖的问题。......
  • 1357. Apply Discount Every n Orders 每隔n个顾客打折
    Thereisasupermarketthatisfrequentedbymanycustomers.Theproductssoldatthesupermarketarerepresentedastwoparallelintegerarrays products and prices,wherethe ith producthasanIDof products[i] andapriceof prices[i].Whenacust......
  • 代码随想录第四天 | 24. 两两交换链表中的节点 19.删除链表的倒数第N个节点 面试题
    question1:SwapNodesinPairshttps://leetcode.cn/problems/swap-nodes-in-pairs/IwasalittleconfusedatfirstbecauseI'mthinkingwhethershouldIcreatanewhead,butsoonIcameupwiththeideaofcreatpre=Noneandwithan'if-els......
  • 考场(NOIP2023模拟5联测26)
    T1题目好评,但是hanzelic小姐是大主播啊。对于\(a_1\)^\(a_2\)^\(a_3\)^\(a_4\)......来说,要让\(a_2\)^\(a_3\)^\(a_4\)最小。啊,为什么我觉得运算顺序不会对这个题造成影响啊QAQ,我是菜狗QAQ。奥,我的意思是让所有次幂乘起来最小,因为\(x*y\)一定小于等于\(x^y......
  • 【安洵杯 2019】easy_serialize_php
    【安洵杯2019】easy_serialize_php收获php反序列化逃逸数组变量覆盖POST请求体传递数组分析代码:<?php$function=@$_GET['f'];functionfilter($img){$filter_arr=array('php','flag','php5','php4','fl1g');......
  • MicroSIP-3.21.3+pjproject-2.13.1+ opus-1.3.1+VS2019
    本文记录了我通过VS2019编译MicroSIP-3.21.3开源项目的过程。Microsip:MicroSIPsourcecodepjproject:DownloadPJSIP-OpenSourceSIP,Media,andNATTraversallibraryopus:Downloads–OpusCodec(opus-codec.org)下载并解压后如图: 用vs2019将microsip的平......
  • P5289 [十二省联考 2019] 皮配
    很容易想到设\(dp_{i,j,k}\)表示考虑前\(i\)个阵营,\(C_0=j\),\(D_0=k\)时的方案数,层内转移时可以用辅助数组对两种阵营决策分别转移,此时时间复杂度为\(O(nM^2)\)。考虑\(k=0\)的情况,如果我们能做这个的话,\(k=30\)其实就是在暗示我们把特殊选手拆出来单独做。而如果所有选......
  • ABC219H Candles
    很显然的区间dp+费用提前计算。但是每个位置上的\(a_i\)还有一个上限的机制,走到某个位置上时似乎还需要判断该\(a_i\)是否已被减完。但其实不需要,因为一旦选到负的\(a_i\),就一定不再是最优解了,所以我们可以将走到\(a_i\)不大于\(0\)的位置时的决策看作不选,否则看作选,那......
  • NOIP2023模拟5联测26 题解
    NOIP2023模拟5联测26题解感觉我这场的官方题解写的是真的挺好的,所以我只能作少量补充。你可以直接去看官方题解,如果你想的话。T1x题解\(n=2\)没啥可说的。\(\color{white}{这档分你要是没拿到那你还是蛮强的。}\)\(n=3\)的时候,我们需要比较\((a_1^{a_2})^{a_3}\)与......