Codeforces Global Round 13 ABC题解
A. K-th Largest Value
思路:操作就是0变1,1变0。那么只用统计1有多少个就知道第x大是谁了。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll 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 - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll a[maxn];
int main()
{
ll n = read(), q = read();
ll zeros = 0, ones = 0;
rep(i,1,n) a[i] = read();
rep(i,1,n)
{
if(a[i]==1) ones++;
else zeros++;
}
rep(i,1,q)
{
ll t = read();
if(t==1)
{
ll x = read();
if(a[x]==1) ones--, zeros++, a[x] = 0;
else ones++, zeros--, a[x] = 1;
}
else
{
ll k = read();
if(ones>=k) cout<<1<<endl;
else cout<<0<<endl;
}
}
return 0;
}
B. Minimal Cost
思路:手动模拟几个数据就能找到规律了。要把路封死不得不移动障碍物就两种情况:
1.一列纵向排列,这个时候要把其中一个右移或左移后,再横向或纵向移动一次,选\(min(u+v,v*2)\)。
2.分散排列,但每两个之间的间距都不超过1,(如一条斜线),这种就要将其中一个纵向或横向移动, 选\(min(u,v)\)。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll 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 - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll a[maxn];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read(), u = read(), v = read();
rep(i,1,n) a[i] = read();
ll ma = 0;
rep(i,2,n) ma = max(abs(a[i] - a[i-1]) ,ma);
ll ans = 0;
if(ma==1) ans = min(u,v);
else if(ma==0)
{
ans = min(u+v,v*2);
}
cout<<ans<<endl;
}
return 0;
}
C. Pekora and Trampoline
思路:其实贪心的核心很简单:在不得不以第i个蹦床当起跳点的时候,我想它已经尽可能地多次从前面跳过来过了。
那么就从前往后遍历,每次先看看当前已经被跳过来多少次,如果还需要跳(>1),那说明[i+2,i+left]的位置都是以它为起点需要跳的(注意若前面跳过来的次数比a[i]还大的话多出来的还会跳到i+1)。这个时候将前面过来的次数和自己当起点的次数继续传递下去即可。
注意一下细节,这题可能很多人迷之wa2和TL。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(long long i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll 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 - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll a[maxn];
ll cnt[maxn];
int main()
{
int kase;
scanf("%d",&kase);
while(kase--)
{
ll n = read();
rep(i,0,n+1) cnt[i] = 0;
rep(i,1,n) a[i] = read();
ll ans = 0;
rep(i,1,n)
{
ll Left = max(1LL, a[i]-cnt[i]);
ll final = Left + i;
rep(j,1,cnt[i])
{
ll to = max(i + a[i] - cnt[i] + j , i+1);
if(to>n) break;
if(to==i+1)
{
ll num = min(cnt[i] - a[i] + 1 - j + 1, cnt[i] - j + 1);
cnt[to] += num;
j = cnt[i] - a[i] + 1;
continue;
}
cnt[to] ++;
}
ll need = Left - 1;
if(need)
{
rep(j,1,need)
{
if(j+i+1>n) break;
cnt[j+i+1]++;
}
ans += need;
}
}
cout<<ans<<endl;
}
return 0;
}
Codeforces Global Round 13 ABC题解的更多相关文章
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- Codeforces Global Round 11 个人题解(B题)
Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...
- Codeforces Global Round 2部分题解
传送门 好难受啊掉\(rating\)了-- \(A\ Ilya\ and\ a\ Colorful\ Walk\) 找到最后一个与第一个颜色不同的,比一下距离,然后再找到最左边和最右边与第一个颜色不 ...
- Codeforces Global Round 2 部分题解
F.Niyaz and Small Degrees 挺sb的一题,为什么比赛时只过了4个呢 考虑当\(x\)固定的时候怎么做.显然可以树形DP:设\(f_{u,i=0/1}\)表示只考虑\(u\)子树 ...
- Codeforces Global Round 13
比赛地址 A(水题) 题目链接 题目: 给出一个\(01\)序列,有2种操作:1.将某个位置取反:2.询问\(01\)序列中第\(k\)大的数 解析: 显然维护1的数目即可 #include<b ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
随机推荐
- python,获取当前日期且以当前日期为名称创建文件名
爬虫爬取信息时,需要把爬取的内容存到txt文档中,且爬虫是每天执行,以日期命名能避免出现名称重复等问题,解决方法如下 import time import os import sys path = o ...
- .net clr 8年才修复的BUG,你让我损失太多了
一.概述 .NET社区修复问题可谓是龟速,一个BUG在.NET 7.0+版本才修复,你让我损失了几万块,我现在还记得客户那种质疑的表情,你了解那种尬尴的气氛吗?你让我一度怀疑dotnetty,我从来不 ...
- MySQL 中 int(11) 的 11 表示什么?
MySQL 中 int(11) 的 11 表示什么? 在 MySQL 中,int(11) 中的 11 并不表示整数的取值范围,而是用于显示宽度(Display Width).它的含义和具体影响如下: ...
- 一文速通Python并行计算:08 Python多进程编程-multiprocessing模块、进程的创建命名、获取进程ID、创建守护进程和进程的终止
一文速通 Python 并行计算:08 Python 多进程编程-multiprocessing 模块.进程的创建命名.获取进程 ID.创建守护进程和进程的终止 摘要: 本节介绍 Python 中 m ...
- C#高性能开发之类型系统:从C# 7.0 到C# 14的类型系统演进全景
自C# 7.0以来,C#语言在类型系统方面引入了众多新数据类型.类型构造和语言特性,以提升性能.类型安全性和开发效率.本文全面整理了从C# 7.0到C# 14.0(截至2025年4月,C# 14.0为 ...
- 【记录】gnuplot|gnuplot怎么把多个图画成一个?
版本:gnuplot 5.2 patchlevel 2 解决了无数次了还是反复忘,气,遂记. 下列程序的功能: 读取文件夹下的所有dat文件,并把所有dat的结果画在一张图里并标好图例: set te ...
- P10856 【MX-X2-T5】「Cfz Round 4」Xor-Forces题解
题意: 给定一个长度为 \(n=2^k\) 的数组 \(a\),下标从 \(0\) 开始,维护 \(m\) 次操作: 给定 \(x\),设数列 \(a'\) 满足 \(a'_i=a_{i\oplus ...
- Python基础 - 控制结构
控制结构: 顺序, 分支, 循环, 理解了, 其实编程就入门一半了. 条件表达式 条件表达式的值只要不是:0 . None. False. 空列表. 空元组. 空集合. 空字典. 空字符串. 空ran ...
- 如何医治一条慢SQL?
前言 "苏工,订单列表又崩了!" 接到电话时,我对着监控大屏上999ms的SQL响应时间哭笑不得. 几年来,我发现一个定律:所有SQL问题都是在凌晨三点爆发! 今天抽丝剥茧,教你用 ...
- python简单的time ticker
在某些时候,我们需要精确的启动一个func,如果用time.sleep简单的轮询,会因为执行的任务阻塞,或者其他原因导致无法精确的定时执行. 例如在采集某些数据的时候,需要精确的每60秒采集一次,如果 ...