Codeforces Round #365 (Div. 2) (703A,703B(容斥),703C(几何),703D(树状数组))

大红球预警版-精选+自定义板块监控 这是一款简单易用的股票大单资金监控插件,兼容通达信软件,可嵌入分时图或定制版面。它以红绿圆球直观显示主力买卖情况(红球为买,绿球为卖),支持300万以上大单语音播报。插件提供实时资金流向分析、多股同时监控、自定义预警条件等功能,无需L2账号。用户可自由切换图形/列表模式,监控特定板块,并配合幻影软件实现自动交易。虽然上涨股通常红球占优,但需结合其他指标综合判断。该插件完全免费,包含详细视频教程,适合新手使用。 阅读详情

Mishka and Game

题目链接:

http://codeforces.com/problemset/problem/703/A

解题思路:

In this problem you had to do use the following algo. If Mishka wins Chris in the current round, then increase variable countM by 1. Otherwise (if Chris wins Mishka) increase variable countC. After that you had to compare this values and print the answer.

AC代码:

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

int main(){
    int n;
    while(~scanf("%d",&n)){
        int cnt1 = 0,cnt2 = 0;
        int x,y;
        for(int i = 0; i < n; ++i){
            scanf("%d%d",&x,&y);
            if(x > y)
                ++cnt1;
            else if(x < y)
                ++cnt2;
        }
        if(cnt1 > cnt2)
            puts("Mishka");
        else if(cnt1 < cnt2)
            puts("Chris");
        else
            puts("Friendship is magic!^^");
    }
    return 0;
}


Mishka and trip

题目链接:

http://codeforces.com/problemset/problem/703/B

解题思路:

Let's look at the first capital. Note that the total cost of the outgoing roads is c[id1] · (sum - c[id1]), where sum — summary beauty of allcities. Thus iterating through the capitals we can count the summary cost of roads between capitals and all the other cities. But don't forget that in this case we count the roads between pairs of capitals twice. To avoid this on each step we should update sum = sum - c[idcur] , where idcur is the position of current capital. In the end we should add to the answer the cost of roads between "non-capital" neighbour cities.

Complexity — O(n).

算法思想:

题解是O(nlogn)的,其实我们只需要求出前缀和,然后先求出每个首都城市x,对答案的贡献:c[x] * others即可。O(n).

AC代码:

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

typedef long long int ll;
const int N = 100005;
int c[N];
bool vis[N];

int main(){
    int n,k;
	while(~scanf("%d%d",&n,&k)){
        memset(vis,false,sizeof(vis));
        ll sum = 0;
        for(int i = 1; i <= n; ++i){
            scanf("%d",&c[i]);
            sum += c[i];
        }
        ll visc = 0,ans = 0;
        for(int i = 1; i <= k; ++i){
            int x;
            scanf("%d",&x);
            visc += c[x];
            ans += c[x]*(sum-visc);
            vis[x] = true;
        }
        for(int i = 1; i <= n; ++i){
            if(vis[i] || vis[i+1])
                continue;
            ans += c[i]*c[i+1];
        }
        if(!vis[1] && !vis[n])
            ans += c[1]*c[n];
        printf("%lld\n",ans);
	}
	return 0;
}


Chris and Road

题目链接:

http://codeforces.com/problemset/problem/703/C

解题思路:

Imagine that the bus stands still and we move "to the right" with a constant speed v. Then it's not hard to see that movement along the liney = (u / v) · (x  -  t0) is optimal, where t0 — time in which we begin our movement. In this way answer is t = t0 + (w / u).

If t0 = 0, then we start our movement immediately. In this case we need to check that our line doesn't intersect polygon (either we can cross the road in front of a bus, or the bus is gone).

Otherwise we need to find such minimal t0 that our line is tangent to the polygon. It can be done with binary search.

Complexity — O(n log n).

算法思想:

我们可以先考虑人直接过去,而车撞不到人的情况;然后再考虑人等车先过,人再过的情况即可。

AC代码:

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

typedef long long ll;
const int N = 10005;
int n,w,v,u;
int x[N],y[N];

bool pre(){
    for(int i = 0; i < n; ++i)
        if(ll(x[i])*u < ll(y[i])*v)
            return false;
    return true;
}

double solve(){
    double ret = w*1.0/u;
    for(int i = 0; i < n; ++i)
        ret = max(ret, x[i]*1.0/v + (w-y[i])*1.0/u);
    return ret;
}

int main(){
    while(~scanf("%d%d%d%d",&n,&w,&v,&u)){
        for(int i = 0; i < n; i++)
            scanf("%d%d",&x[i],&y[i]);
        if(pre()){
            printf("%.6lf\n",w*1.0/u);
            return 0;
        }
        printf("%.6lf\n",solve());
    }
    return 0;
}


Mishka and Interesting sum

题目链接:

http://codeforces.com/problemset/problem/703/D

解题思路:

Easy to see, that the answer for query is XOR-sum of all elements in the segment xored with XOR-sum of distinct elements in the segment. XOR-sum of all numbers we can find in O(1) using partial sums. As for the XOR-sum of distinct numbers... Let's solve easier problem.

Let the queries be like "find the number of distinct values in a segment". Let's sort all the queries according to their right bounds and iterate through all elements of our array. We also need to make a list last, where last[value] is the last position of value on the processed prefix of array. Assume we are at position r. Then the answer for the query in the segment [l,  r] (l ≤ r) is , where cnt[i] = 1 iflast[ai] = i and 0 otherwise. It's easy to store and update such values in cnt. When moving to the next position we have to make the following assignments: cnt[last[ai]] = 0, cnt[i] = 1, last[ai] = i. To get described sum in O(log n) we can use segment tree (or Fenwick tree) instead of standard array.

Now let's turn back to our problem. Everything we have to do is to change assignment cnt[i] = 1 to cnt[i] = ai and count XOR-sum instead of sum. Now we can solve this problem in O(n log n).

题目大意:

给你n个数,然后m次查询,每一次查询输出所在给定区间内出现偶数次数的数的异或值,如果只有一个出现偶数次数的数,则直接

输出该数,如果没有出现偶数次数的数,则直接输出0。

算法思想:

和求一个区间内不同元素个数的做法一样。树状数组存的是不同元素的前缀异或和。用map标记数a[i]最近的出现的下标。其实就是

先求出这个区间的(异或和),然后再异或上这个区间不同数的异或和(即由树状数组来完成的)。

AC代码:

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

typedef long long ll;
const int N = 1000005;
map<int,int> mp;
vector<int> que[N];
int n,m;
int a[N];
int l[N],r[N];
ll res[N],bit[N];
ll ans[N];

int lowbit(int x){
    return x&(-x);
}

void update(int x, ll val){
	for(int i = x; i <= n; i += lowbit(i))
		bit[i] ^= val;
}

int sum(int x){
	ll res = 0;
	for(int i = x; i > 0; i -= lowbit(i))
		res ^= bit[i];
	return res;
}

int main(){
	while(~scanf("%d",&n)){
        mp.clear();
        memset(res,0,sizeof(res));
        for(int i = 0; i <= n; ++i)
            que[i].clear();
        for(int i = 1; i <= n; ++i){
            scanf("%d",&a[i]);
            res[i] = (res[i-1]^a[i]);
        }
        scanf("%d",&m);
        for(int i = 0; i < m; ++i){
            scanf("%d%d",&l[i],&r[i]);
            que[l[i]].push_back(i);
            ans[i] = res[r[i]]^res[l[i]-1];
        }
        for(int i = n; i >= 1; --i){
            int x = a[i];
            if(mp.count(x))
                update(mp[x],x);
            update(i,x);
            mp[x] = i;
            for(int j = 0; j < que[i].size(); ++j){
                int id = que[i][j];
                ans[id] ^= sum(r[id]);
            }
        }
        for(int i = 0; i < m; ++i)
            printf("%lld\n", ans[i]);
	}
	return 0;
}


【Flutter 问题系列第 85 篇】Xcode 运行 Flutter 提示 The Dart VM Service was not discovered after 60 seconds. 在 Xcode 上运行 Flutter 时提示 `The Dart VM Service was not discovered after 60 seconds. This is taking much longer than expected...`,意思是 `60秒后未发现Dart虚拟机服务。这比预期的要长得多` 阅读详情

相关推荐

投研必备工具:Wind(万得)数据库快速入门

Wind数据库对于金融从业者来说是必不可少的一个软件,本文主要介绍了股票和债券的信息查找,帮助后续对数据进行分析,开始学习吧!

weixin_56581108的博客 10万+

Codeforces Round 703 (Div. 2)(A~D)

Codeforces Round 703 (Div. 2)(A~D)

m0_62289613的博客 407

基于Simulink与CarSim的SH垂向控制模块联合仿真优化及性能验证

本文详细介绍了基于Simulink与CarSim的SH垂向控制模块联合仿真优化及性能验证方法。通过天棚控制算法实现、参数调优方法论和C级路面仿真分析,展示了如何有效提升车辆悬架系统的舒适性和稳定性。联合仿真技术显著降低了开发成本,SH控制使车身垂向加速度RMS值降低19.3%,轮胎动载荷减少12%。

weixin_29182481的博客 316

Codeforces Round #703 (Div. 2)(A ~ F)超高质量题解【每日亿题2 / 19】

Codeforces Round #703 (Div. 2)(A、B、C、D、E、F)超高质量题解 A. Shifting Stacks B - Eastern Exhibition C1 - Guessing the Greatest (easy version) C2 - Guessing the Greatest (hard version) D - Max Median E - Paired Payment F - Pairs of Paths

繁凡さん的博客 4072

cuda安装时出现错误 Unable to locate package cuda-toolkit-12-4

cuda安装时出现错误 Unable to locate package cuda-toolkit-12-4

4892

两种方法解决这个问题OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.

两种方法解决这个问题OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.在进行深度学习比如在训练yolov8模型时,在加载训练集和验证集时会报以下那个错误时会导致模型训练中断,有以下两个方法去解决这个问题,来使模型正常训练。

weixin_73044854的博客 2万+

Codeforces Round #703 (Div. 2) (自闭场)

A. Shifting Stacks 这题我能记很久,直接给我打自闭了,从开赛一直到了最后,我就一个菜鸡 题意非常简单,给你n个数,让你把他们构造成递增的,然后只能从后往前,你直接想就行了,直接构造0 1 2 3 4 5 6 7 8 9…n如果可以的话,就是yes,不可以的话就是no 然后上我第一遍的代码 #include <bits/stdc++.h> #define int long long #define BUFF ios::sync_with_stdio(false), cin.t

godhandsjoker的博客 2661

BOE CHPI协议解析:高速显示驱动的核心技术

本文深入解析了BOE CHPI协议,这是一种为高分辨率、高刷新率显示面板设计的时钟嵌入式高速点对点接口技术。文章详细阐述了其三层架构(物理层、链路层、协议层)、核心机制(如链路训练与BCC通道)以及如何通过高速串行差分传输解决大尺寸屏幕内部数据传输的带宽与干扰难题,是驱动8K、窄边框等高端显示应用的关键核心技术。

m9n0o的博客 553

Codeforces Round #703 (Div. 2) 题解

倒序补题法

Irving0323的博客 1587

量化交易如何利用涨停板策略收割散户

量化交易通过算法筛选特定特征的股票,在早盘建立底仓后,利用大单拉升制造抢筹假象,吸引散户跟风买入。这种策略利用了散户的认知偏差,如锚定效应和从众心理,导致次日低开闷杀。从技术实现来看,量化策略通过控制买入量、隐藏真实意图等手段,精准执行隔日砸策略。对于短线交易者而言,理解量化资金的运作逻辑和识别危险涨停板的特征至关重要,这包括观察封板时间、盘口挂单、量价关系等多维度数据。在算法主导的市场中,散户需要升级交易工具和策略,从预测走势转向应对走势,才能避免成为量化策略的牺牲品。

weixin_33046983的博客 319

避开这5个坑!STC8H DMA串口通信的实战避坑指南(115200波特率实测)

本文深入解析了STC8H单片机利用DMA实现稳定全双工串口通信的实战要点。针对115200高波特率场景,详细拆解了DMA-UART架构、关键寄存器配置、时钟精度计算、缓冲区管理及中断协同等核心环节,并提供了具体的避坑指南和调试方法,帮助开发者构建高效可靠的通信链路。

melon的博客 686

拓扑排序练习题

A题:HDU1285    题解传送门        拓扑排序模板,注意输出格式,最后没有空格 B题:POJ 2367    题解传送门         也是模板题,注意题意:第i行中的每个数字j表示j是i的后代。利用这条信息建图。每行输入以0结束 C题:UVA 10305  题解传送门         模板题。。注意输入停止条件是while(cin&gt;&gt;n&gt;&gt;m&amp...

执念 3831

2023华为OD面试手撕真题【最长公共前缀】

2023华为OD面试手撕真题【最长公共前缀】

MISAYAONE的博客 5270

【解题报告】Codeforces Round #365 (Div. 2)

简略的解题报告。

TRiddle的博客 692

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Codeforces Round #365 (Div. 2) C

链接:http://codeforces.com/problemset/problem/703/C 分析: 这题其实是个大水题,只要短短的几行就可以搞定的, 首先需要直觉判断一点,就是只要判断最左边的点和最下面的点 以及和他们相邻边的右边的点 第二部我们就需要判断人与这两个边有没有交点,如果人与上面的有交点,那么人肯定就需要在下面的那条边等待 等待的时间是 max(x - y*1.0*v/...

weixin_30340353的博客 74

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Codeforces Round #703 (Div. 2) D. Max Median

题意:给一个长度为n的序列,对于一个区间长度不小于k的子区间,中位数为这个区间排序后的第(k+1)/2个数字。现在求所有的长度不小于k的子区间,中位数的最大值是多少。 思路:首先要想到,对于一个中位数,在这题中,对于偶数长度,取的中位数是靠左边的那个,那么大于等于中位数的就有一半以上。 所以大于等于中位数的个数要比小于中位数的个数多。 利用这点,那么其实我们可以在On复杂度判断出来一个数字是不是 ≤中位数。 可以判断一个数是不是≤中位数? 那么我们是不是可以去二分? 其实这是有单调性的。 判断一个数字是不是

菜鸡的学习记录 1412

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Codeforces Round #703 (Div. 2) D . Max Median 二分 +思维

传送门 题意: 给定一个数组和k,求一段连续区间中位数最大值,连续区间长度>=k。 如果=k的话可以直接秒了,这里是>=k,我们可以通过二分让后利用>=k这个条件来检查答案。 二分中位数,假设当前二分的为midmidmid,那么a[i]>=mida[i]>=mida[i]>=mid的数可以变成111,a[i]<mida[i]<mida[i]<mid的数变成−1-1−1,现在问题就变成了寻找长度>=k且值为正的序列。这个问题可以用前缀和解决,我们枚举

m0_51068403的博客 379

Codeforces Round #703 (Div. 2)

传送门 A. Shifting Stacks 给你一个序列,每次可以选择一个aiaiai将此值(一次只能操作1)填充到ai+1a_{i+1}ai+1​,问操作无限次后能不能让序列严格递增?(0=<ai<=1090=<ai<=10^90=<ai<=109)。 最低的可能就是{0,1,2,3…}这种序列。一开始直接求前n项和n*(n-1)/2,然后判断序列和大于就是YES否则NO。但是这种0 0 9实际上是不可能的。因为9不能往前加1。所以不可做。换一种方法,我们从1~n构

pingfanblog 238

平常水题 - CodeForces - 703C(二分 + 几何)

C. Chris and Road time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output And while Mishka is enjoying her trip...

dreams___的博客 627

codeforces 702div3 题解

前天打了codeforces703div3的比赛,这场比赛我一个小时做出了前6题,第7题在场内因为看错了题意,很遗憾没能AK,从200名掉到了800多名,在算排名的人里面排了200多名,涨了差不多100分吧。我codeforces有两个账号, 一个1800分,一个1600多分。今天的cf我没有打,先休息一天吧,下周在继续冲击更高的目标。 G题:(单调栈 + 二分 + 数学推导) 前面六个题都很基础,就不讲解了,重点讲一下G题吧。 G题是让你求一个长度为n的循环序列至少多少项的前缀和大于等于x。 n是2000

Einsteinme的博客 517

Codeforces Round #703 Div2 D. Max Median 二分答案

Codeforces Round #703 Div2 D. Max Median 二分答案题意思路Code(78MS) 传送门:https://codeforces.com/contest/1486/problem/D 题意 给一个长度为n的数组,在里面找若干个长度≥k的区间,问这些区间中最大的中位数是多少。给一个长度为n的数组,在里面找若干个长度\ge k的区间,问这些区间中最大的中位数是多少。给一个长度为n的数组,在里面找若干个长度≥k的区间,问这些区间中最大的中位数是多少。 中位数,请输出最大值。\r

狙击美佐的博客 388

Codeforces Round #703 (Div. 2) C interactive problem

这场div2被这个交互题打的头皮发麻。 20分钟我AC了AB两题,那是觉得这场要飞天,但开到C题的时候就懵逼了,题目是什么意思?输入是什么意思?输出又是什么鬼?%%%%% 因为这是本蒟蒻第一次写交互题,所以写这种题需要注意的点我完全不知道,于是乎出现了这个诡异的一幕:其他人拼命输出,而我却在学习what is interactive problem? 废话不多说,直接上题。 题目如下: 注释: 交互题,顾名思义就是一种通过不断给出信息,然后通过程序利用信息,最后得到答案的过程。 其不同于传统的题目,这种

weixin_50547586的博客 432

codeforces - 703A - Mishka and Game(水)

LINK:http://codeforces.com/contest/703/problem/A 两人掷骰子,看谁赢得次数多#include<bits/stdc++.h> using namespace std; #define LL long long int main() { int n,a,b,cnt1=0,cnt2=0; cin>>n; for(int i=0;i<

horihori_的博客 330

Codeforces Round #703 (Div. 2)个人总结

A. Shifting Stacks https://codeforces.com/contest/1486/problem/A 题意: 有一个操作对于1<=i<n; if(a[i]>0)a[i]–,a[i+1]++; 给你一个序列a[],长度为n,是否能够构成一个严格上升数组 即:a[i]<a[i+1] (1<=i<n) 思路: 贪心、 对于每一位至少为i-1; 每次将第i位多的往后添加就行 参考代码: #include <iostream> #includ

WIFIfw的博客 357

Codeforces Round #703 (Div. 2) Guessing the Greatest C1 C2 二分

link 题意:交互题,每次可以询问一个区间的次大值,保证所有值都不相同,求最大值位置。easy是询问最多40次,hard最多20次。 交互题大部分都是二分,可以向二分考虑。 easy比较好想,假设当前区间为[l,r][l,r][l,r],中点midmidmid,先查询[l,r][l,r][l,r],得到次大值的位置pos1pos_1pos1​,假设pos1<=midpos_1<=midpos1​<=mid,那么就查询[l,mid][l,mid][l,mid]的次大值得到pos2pos_2

m0_51068403的博客 256

Codeforces Round #703 (Div. 2) 题解

Codeforces Round #703 (Div. 2)

310
上一篇: BestCoder Round #85 (hdu5776,hdu5777,hdu5776)
下一篇: BestCoder Round #85 (hdu5804,hdu5805,hdu5806,hdu5807)
yphacker
博客等级 码龄12年 199粉丝 540原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址