首页 > 编程语言 >武汉大学2023年新生程序设计竞赛(同步赛)

武汉大学2023年新生程序设计竞赛(同步赛)

时间:2023-10-06 16:56:17浏览次数:41  
标签:武汉大学 int 1000000000 tr Write ++ 2023 程序设计 define

C. 覆叶之交(线段树+离散化+扫描线)

输入格式:

输出格式:

输入

0 0 2 3
0 0 3 2
-1 -1 1 1

输出

11

说明

线段树+离散化+扫描线
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr)
#define lowbit(ver) ver&(-ver)
#define pii pair<int,int>
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define ull unsigned long long
// #define int long long
#define int __int128
#define eps 1e-9
#define pb push_back
#define mod1 1000000007
#define mod2 998244353
#define endl "\n"
#define YES "YES\n"
#define NO "NO\n"
#define Yes "Yes\n"
#define No "No\n"
#define yes "yes\n"
#define no "no\n"
#define fi first
#define se second

using namespace std;

typedef __int128 i64;

const int N = 2e5 + 10;

int n;

inline i64 Read(){
    i64 x=0,f=1;char c=getchar();//isdigit
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
    return x * f;
}
inline void Write(int x){
    if(x < 0){putchar('-');x=-x;}
    if(x>9)Write(x/10);putchar(x%10+'0');
    return;
}
inline void Write(int x, char c){
    Write(x), putchar(c);
}

struct Segment
{
    int x, y1, y2;
    int k;
    bool operator< (const Segment &t)const
    {
        return x < t.x;
    }
}seg[N * 2];
struct Node
{
    int l, r;
    int cnt;
    int len;
}tr[N * 8];

vector<int> ys;

int find(int y)
{
    return lower_bound(ys.begin(), ys.end(), y) - ys.begin();
}

void pushup(int u)
{
    if (tr[u].cnt) tr[u].len = ys[tr[u].r + 1] - ys[tr[u].l];
    else if (tr[u].l != tr[u].r)
    {
        tr[u].len = tr[u << 1].len + tr[u << 1 | 1].len;
    }
    else tr[u].len = 0;
}

void build(int u, int l, int r)
{
    tr[u] = {l, r, 0, 0};
    if (l != r)
    {
        int mid = l + r >> 1;
        build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
    }
}

void modify(int u, int l, int r, int k)
{
    if (tr[u].l >= l && tr[u].r <= r)
    {
        tr[u].cnt += k;
        pushup(u);
    }
    else
    {
        int mid = tr[u].l + tr[u].r >> 1;
        if (l <= mid) modify(u << 1, l, r, k);
        if (r > mid) modify(u << 1 | 1, l, r, k);
        pushup(u);
    }
}

void solve()
{
    n = 3;
    for (int i = 0, j = 0; i < n; i ++ )
    {
        int x1, y1, x2, y2;
        x1 = Read();
        y1 = Read();
        x2 = Read();
        y2 = Read();
        seg[j ++ ] = {x1, y1, y2, 1};
        seg[j ++ ] = {x2, y1, y2, -1};
        ys.push_back(y1), ys.push_back(y2);
    }

    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());

    build(1, 0, ys.size() - 2);

    sort(seg, seg + n * 2);

    int ans = 0;
    for (int i = 0; i < n * 2; i ++ )
    {
        if (i > 0) ans += tr[1].len * (seg[i].x - seg[i - 1].x);
        modify(1, find(seg[i].y1), find(seg[i].y2) - 1, seg[i].k);
    }

    Write(ans);
    // printf("%.0lf\n\n", res * eps * eps);
}

signed main(){
    IOS; int _ = 1;
    // cin >> _;
    while(_ --)
        solve();
    return _ ^ _;
}
/*
100000 100000 -100000000 -10000000
-1000000 -10000000 10000000 -100000
-1000000 1000000 -1000000000 -100000000

1000000000 0 -1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
-1000000000 1000000000 1000000000 1000000000
*/

J. 放棋子(模拟orDP)

输入格式:

输出格式:

输入

3 3
.#.

.#.

输出

32

说明

点击查看代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr)
#define int long long

using namespace std;

typedef __int128 i64;

const int N = 2e5 + 10;

int a[N], b[N], f[N];
int ans;
int n, m;

inline i64 Read(){
    i64 x=0,f=1;char c=getchar();//isdigit
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
    return x * f;
}
inline void Write(int x){
    if(x < 0){putchar('-');x=-x;}
    if(x>9)Write(x/10);putchar(x%10+'0');
    return;
}
inline void Write(int x, char c){
    Write(x), putchar(c);
}

void solve()
{
    cin >> n >> m;
    int ans = 0, t = 0, f = 1;
    string s[n];
    for(int i = 0; i < n; i ++)
        cin >> s[i];
    for(int i = 0; i < n; i ++)
    {
        f = 0;
        for(int j = 0; j < m; j ++)
        {
            if(s[i][j] == '#')
            {
                f ++;
                ans += f * f;
            }
            else f = 0;
        }
    }
    for(int i = 0; i < m; i ++)
    {
        f = 0;
        for(int j = 0; j < n; j ++)
        {
            if(s[j][i] == '#')
            {
                f ++;
                ans += f * f;
            }
            else f = 0;
        }
    }
    cout << ans << '\n';
}

signed main(){
    IOS; int _ = 1;
    // cin >> _;
    while(_ --)
        solve();
    return _ ^ _;
}

标签:武汉大学,int,1000000000,tr,Write,++,2023,程序设计,define
From: https://www.cnblogs.com/chfychin/p/17744712.html

相关文章

  • 2022-2023 ICPC Central Europe Regional Contest
    The1stUniversalCup.Stage8:SloveniaD.Deforestation这道题出题人比较谜语人,对于一个分叉点,只能选择若干个儿子和父亲组成一组,剩下的儿子之间不能相互组合。所以从叶子节点开始贪心处理就好。对于一个父亲他有若干个儿子,就贪心的选择剩下部分更小的儿子。#include<bits......
  • 2023.10.5测试
    \[\text{NOIP模拟赛-2023.10.5}\]T1魔法少女定义\(f(i)\)为\(i\)所有约数的异或和,求\(f(1)\simf(n)\)的异或和\(1\leqn\leq10^{14}\)容易想到枚举约数然后计算出约数出现的次数并对答案做贡献,复杂度\(\mathcal{O}(n)\)发现约数\(x\)出现的次数即\(\left\lfloor......
  • 2023-2024-1 学号20231315《计算机基础与程序设计》第二周学习总结
    学期:2023-2024-1学号:20231315《计算机基础与程序设计》第二周学习总结作业信息这个作业属于哪个课程2023-2024-1《计算机基础与程序设计》这个作业要求在哪里2023-2024-1《计算机基础与程序设计》这个作业的目标学习计算机科学概论第1章和《C语言程序设计》第1......
  • 【GJOI 2023.10.5 T1】 雷老师的正偏态分布
    雷老师的正偏态分布题意:给出一个长度为\(n\)的\(a\)数组,其中\(1\lea_i\leV,1\lei\len\)。统计其中的满足平均数严格小于中位数且大小为奇数的子集数量,\(n\le100,V\le800\),时限\(4\)s。输入:510127910输出:8首先,可以考虑排序,保证一个子集中小......
  • 2023-10-06 useState数据渲染不同步==》async await
    业务:点击按钮增加数据并渲染出来。框架:antd+ts+react。原来写法:const[tagData,setTagData]=useState<Array<number>>([]);点击事件://添加标签constaddTag=()=>{letarr:(number)[]=[];arr=tagData;arr.push(Math.floor(Math.random()......
  • 2023-10-06 Warning: [antd: Switch] `value` is not a valid prop, do you mean `che
    该报错意思是你用的这个switch组件对应的属性应该是checked而不是value,后者应该是antd默认设置的属性,可以通过valuePropName来手动指定对应的属性值。如:<FormItemname="status"label="状态"valuePropName="checked"rules={[{required:true}]}><Switch/></FormIte......
  • 板刷2023.10.04
    CF1878F.VasilijeLovesNumberTheory题解:约数个数+取模性质对\(n\)质因子分解得到,\(n=p_1^{\alpha_1}p_2^{\alpha_2}...p_k^{\alpha_k}\)那么显然\(d(n)=(\alpha_1+1)\times(\alpha_2+1)...(\alpha_k+1)\)根据题意可以得到:\(n\%d(n)=0\)的时候一定......
  • 202310061227-《心得:低版本mysql配置一,些轮子插件》
    1.对于mysql5.7.42,驱动(connector)选择:5.1.46。2.测试链接时:useSSL=true&enabledTLSProtocols=TLSv1.1 驱动链接字符串上要拼接上。3.驱动链接字符串:高版本mysql,意味着高版本connector,选>=8;低版本,选择5.x;               高版本mysql,com.my......
  • 2023-10-02-周一
    吾日三省吾身titlecontent简单评价这一天只能说差强人意今天运动了吗?0学习还满意否0.5会不会又emo了0今日学习任务titlecontent学习ELF文件格式0.2安卓开发0呃..上午才是搞笑的我很早起来,洗了一个澡..然后还是很困...所以......
  • 2023-10-05-周五
    运动,,,貌似不可能了,,,哈哈我发现,,最近的睡眠好像真还有点小离谱了基本上都是闹钟一响,然后差不多8:30的样子,然后咪一咪然后继续睡,差不多9:20~9:40的样子,,就内心挣扎,愧疚的醒过来然后洗漱一下,然后杂七杂八看一下手机然后....就差不多10:00的样子然后懒懒散散的去实验......