「CSP-S模拟赛」2019第二场
这场考试的数据感觉很水。
\(T1\) 签到不解释,\(T2\) 期望 \(50pts\) 结果有 \(100pts\),\(T3\) 一如既往地不可做...
T1 Jam的计数法
题目
考场思路(正解)
其实没有什么好说的,找找规律即可,看看代码吧。
#include<cstdio>
// #define FILEOI
#define rep(i,__l,__r) for(int i=__l,i##_end_=__r;i<=i##_end_;++i)
#define dep(i,__l,__r) for(int i=__l,i##_end_=__r;i>=i##_end_;--i)
#define cg (c=getchar())
template<class T>inline void qread(T& x){
x=0;char c;bool f=0;
while(cg<'0'||'9'<c)if(c=='-')f=1;
for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
if(f)x=-x;
}
template<class T,class... Args>inline void qread(T& x,Args&... args){qread(x),qread(args...);}
inline int qread(){
int x=0;char c;bool f=0;
while(cg<'0'||'9'<c)if(c=='-')f=1;
for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
return f?x:-x;
}
#undef cg
template<class T>inline T Max(const T x,const T y){return x>y?x:y;}
template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
template<class T>inline T fab(const T x){return x>0?x:-x;}
template<class T>void fwrit(T x){
if(x<0)return (void)(putchar('-'),fwrit(-x));
if(x>10)fwrit(x/10);
return (void)(putchar(x%10^48));
}
const int MAXW=25;
int s,t,w,num[(MAXW<<2)+5],T=5;
char sn[(MAXW<<2)+5];
inline void init(){
qread(s,t,w);
scanf("%s",sn+1);
rep(i,1,w)num[i]=sn[i]-'a'+1;
}
inline void putNum(){
for(int i=1;i<=w;++i)printf("%c",num[i]+'a'-1);
putchar('\n');
}
inline void addOne(){
bool f=true;
for(int i=w;i>=1;--i)if(num[i]<t-w+i){
++num[i],f=false;
for(int j=i+1;j<=w;++j)num[j]=num[j-1]+1;
break;
}
if(f)return;
putNum();
}
signed main(){
#ifdef FILEOI
freopen("number.in","r",stdin);
freopen("number.out","w",stdout);
#endif
init();
while(T--)addOne();
return 0;
}
T2 「TJOI / HEOI2016」排序
题目
考场思路(假正解)
直接看的 \(50\%\) 的数据范围,发现可以使用区间桶排序,时间复杂度 \(O(nm)\)。
#include<cstdio>
// #define FILEOI
#define rep(i,__l,__r) for(int i=__l,i##_end_=__r;i<=i##_end_;++i)
#define dep(i,__l,__r) for(int i=__l,i##_end_=__r;i>=i##_end_;--i)
#define cg (c=getchar())
template<class T>inline void qread(T& x){
x=0;char c;bool f=0;
while(cg<'0'||'9'<c)if(c=='-')f=1;
for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
if(f)x=-x;
}
template<class T,class... Args>inline void qread(T& x,Args&... args){qread(x),qread(args...);}
inline int qread(){
int x=0;char c;bool f=1;
while(cg<'0'||'9'<c)if(c=='-')f=0;
for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
return f?x:-x;
}
#undef cg
template<class T>inline T Max(const T x,const T y){return x>y?x:y;}
template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
template<class T>inline T fab(const T x){return x>0?x:-x;}
template<class T>void fwrit(T x){
if(x<0)return (void)(putchar('-'),fwrit(-x));
if(x>10)fwrit(x/10);
return (void)(putchar(x%10^48));
}
const int MAXN=1e5;
int n,m,q,a[MAXN+5],t[MAXN+5];
inline void init(){
qread(n,m);
rep(i,1,n)qread(a[i]);
}
inline void getOperation(){
int op,l,r,li,ri;
while(m--){
li=n,ri=0;
qread(op,l,r);
rep(i,l,r)++t[a[i]],li=Min(li,a[i]),ri=Max(ri,a[i]);
if(op==0){
rep(i,l,r){
while(t[li]==0)++li;
a[i]=li,t[li]=0;
}
}
else if(op==1){
rep(i,l,r){
while(t[ri]==0)--ri;
a[i]=ri,t[ri]=0;
}
}
}
printf("%d\n",a[qread()]);
}
signed main(){
#ifdef FILEOI
freopen("sort.in","r",stdin);
freopen("sort.out","w",stdout);
#endif
init();
getOperation();
return 0;
}
期望得分只有 \(50pts\),但是数据测出来,居然可以 \(A\) 掉...所以叫伪正解...
正解
我们发现,对于一个 \(x\),将小于 \(x\) 的数换成 \(0\),大于等于 \(x\) 的数换成 \(1\) 之后,所得到的排序结果其实是一样的。
但是这样做有唯一的缺陷,就是我们只知道最后 \(q\) 位置的数是 \(0\) 还是 \(1\)。
其实很好解决,二分这个 \(x\) 即可。
这里先把标称附上
std version
#include <cstdio>
#include <cstring>
#include <cctype>
#define lc o << 1
#define rc o << 1 | 1
#define mid (l + r) / 2
using namespace std;
const int N = 100010;
int n, m, p;
int T[4 * N], lazy[4 * N]; // segment tree
int a[N], ch[N], L[N], R[N]; // the information by reading
inline int read() {
char ch = getchar();
int x = 0;
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x;
}
inline void build(int o, int l, int r, int x) {
if (l == r) {
T[o] = a[l] >= x;
lazy[o] = 0;
return;
}
build(lc, l, mid, x);
build(rc, mid + 1, r, x);
T[o] = T[lc] + T[rc];
lazy[o] = 0;
}
inline void pushdown(int o, int l, int r) {
if (!lazy[o])
return;
lazy[lc] = lazy[rc] = lazy[o];
if (lazy[o] == 1) {
T[lc] = mid - l + 1;
T[rc] = r - mid;
} else
T[lc] = T[rc] = 0;
lazy[o] = 0;
}
inline int query(int o, int l, int r, int x, int y) {
if (x <= l && y >= r)
return T[o];
if (x > r || y < l)
return 0;
pushdown(o, l, r);
return query(lc, l, mid, x, y) + query(rc, mid + 1, r, x, y);
}
inline int queryPoint(int o, int l, int r, int x) {
if (l == x && r == x)
return T[o];
pushdown(o, l, r);
if (x <= mid)
return queryPoint(lc, l, mid, x);
else
return queryPoint(rc, mid + 1, r, x);
}
inline void update(int o, int l, int r, int x, int y, int val) {
if (x <= l && y >= r) {
T[o] = val * (r - l + 1);
lazy[o] = val ? 1 : -1;
return;
}
if (x > r || y < l)
return;
pushdown(o, l, r);
update(lc, l, mid, x, y, val);
update(rc, mid + 1, r, x, y, val);
T[o] = T[lc] + T[rc];
}
inline bool check(int x) {
build(1, 1, n, x);
for (int i = 1; i <= m; i++) {
int cnt1 = query(1, 1, n, L[i], R[i]);
if (ch[i] == 0) {
update(1, 1, n, R[i] - cnt1 + 1, R[i], 1);
update(1, 1, n, L[i], R[i] - cnt1, 0);
} else {
update(1, 1, n, L[i], L[i] + cnt1 - 1, 1);
update(1, 1, n, L[i] + cnt1, R[i], 0);
}
}
return queryPoint(1, 1, n, p);
}
int main() {
freopen("sort.in","r",stdin);
freopen("sort.out","w",stdout);
n = read();
m = read();
for (int i = 1; i <= n; i++) a[i] = read();
for (int i = 1; i <= m; i++) {
ch[i] = read();
L[i] = read();
R[i] = read();
}
p = read();
int ll = 1, rr = n, midd, ans;
while (ll <= rr) {
midd = (ll + rr) >> 1;
if (check(midd))
ans = midd, ll = midd + 1;
else
rr = midd - 1;
}
printf("%d\n", rr);
return 0;
}
My version
#include<cstdio>
// #define FILEOI
#define lc (i<<1)
#define rc (i<<1|1)
#define rep(i,__l,__r) for(int i=__l,i##_end_=__r;i<=i##_end_;++i)
#define dep(i,__l,__r) for(int i=__l,i##_end_=__r;i>=i##_end_;--i)
#define cg (c=getchar())
template<class T>inline void qread(T& x){
x=0;char c;bool f=0;
while(cg<'0'||'9'<c)if(c=='-')f=1;
for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
if(f)x=-x;
}
template<class T,class... Args>inline void qread(T& x,Args&... args){qread(x),qread(args...);}
inline int qread(){
int x=0;char c;bool f=1;
while(cg<'0'||'9'<c)if(c=='-')f=0;
for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
return f?x:-x;
}
#undef cg
template<class T>inline T Max(const T x,const T y){return x>y?x:y;}
template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
template<class T>inline T fab(const T x){return x>0?x:-x;}
template<class T>void fwrit(T x){
if(x<0)return (void)(putchar('-'),fwrit(-x));
if(x>10)fwrit(x/10);
return (void)(putchar(x%10^48));
}
const int MAXN=1e5;
const int MAXM=1e5;
struct change{int op,l,r;}p[MAXM+5];
struct node{
int l,r,mid,t1,lazy;
node(){lazy=-1;}
node(const int L,const int R,const int M):l(L),r(R),mid(M){lazy=-1;}
}tre[(MAXN<<2)+5];
int n,m,a[MAXN+5],t[MAXN+5],q;
inline void init(){
qread(n,m);
rep(i,1,n)qread(a[i]);
for(int i=1;i<=m;++i)p[i]=change{qread(),qread(),qread()};
qread(q);
}
inline void pushup(const int i){tre[i].t1=tre[lc].t1+tre[rc].t1;}
inline void pushdown(const int i){
if(tre[i].l^tre[i].r){
if(tre[i].lazy==1){
tre[lc].lazy=tre[rc].lazy=1;
tre[lc].t1=(tre[lc].r-tre[lc].l+1);
tre[rc].t1=(tre[rc].r-tre[rc].l+1);
}
else if(tre[i].lazy==0){
tre[lc].lazy=tre[rc].lazy=0;
tre[lc].t1=tre[rc].t1=0;
}
}
tre[i].lazy=-1;
}
inline void buildtre(const int i,const int l,const int r,const int x){
// printf("buildtre : %d %d %d %d\n",i,l,r,x);
int mid=(l+r)>>1;
tre[i]=node(l,r,mid);
if(l==r)return (void)(tre[i].t1=(a[l]>=x));
buildtre(lc,l,mid,x);
buildtre(rc,mid+1,r,x);
pushup(i);
}
inline int query(const int i,const int l,const int r){
// printf("query : %d %d %d\n",i,l,r);
if(l<=tre[i].l&&tre[i].r<=r)return tre[i].t1;
if(tre[i].lazy!=-1)pushdown(i);
int ret=0;
if(l<=tre[i].mid)ret+=query(lc,l,r);
if(tre[i].mid<r)ret+=query(rc,l,r);
pushup(i);
return ret;
}
inline void update(const int i,const int l,const int r,const int var){
// if(l>r)return;
// printf("update : %d to %d, %d\n",l,r,var);
if(l<=tre[i].l&&tre[i].r<=r){
tre[i].lazy=var;
tre[i].t1=(tre[i].r-tre[i].l+1)*var;
return;
}
if(tre[i].lazy!=-1)pushdown(i);
if(l<=tre[i].mid)update(lc,l,r,var);
if(tre[i].mid<r)update(rc,l,r,var);
pushup(i);
}
inline int query(const int i,const int p){
// printf("update : %d %d\n",i,p);
if(tre[i].l==tre[i].r)return tre[i].t1;
if(tre[i].lazy!=-1)pushdown(i);
int ret;
if(p<=tre[i].mid)ret=query(lc,p);
else ret=query(rc,p);
pushup(i);
return ret;
}
inline bool check(const int x){
// printf("Now check : x == %d\n",x);
buildtre(1,1,n,x);
// for(int i=1;i<=13;++i)printf("tre[%d] : %d %d %d %d %d\n",i,tre[i].l,tre[i].r,tre[i].mid,tre[i].t1,tre[i].lazy);
rep(i,1,m){
int cnt1=query(1,p[i].l,p[i].r);
int cnt0=p[i].r-p[i].l+1-cnt1;
// printf("query : %d %d, cnt1 == %d, cnt0 == %d\n",p[i].l,p[i].r,cnt1,cnt0);
if(p[i].op==0){
if(cnt0)update(1,p[i].l,p[i].l+cnt0-1,0);
if(cnt1)update(1,p[i].l+cnt0,p[i].r,1);
// printf("update : %d to %d, %d\n",p[i].l,p[i].l+cnt0-1,0);
// printf("update : %d to %d, %d\n",p[i].l+cnt0,p[i].r,1);
}
else{
if(cnt1)update(1,p[i].l,p[i].l+cnt1-1,1);
if(cnt0)update(1,p[i].l+cnt1,p[i].r,0);
// printf("update : %d to %d, %d\n",p[i].l,p[i].l+cnt1-1,0);
// printf("update : %d to %d, %d\n",p[i].l+cnt1,p[i].r,1);
}
// printf("Now The info of the tre :\n");
// for(int j=1;j<=13;++j)printf("tre[%d] : %d %d %d %d %d\n",j,tre[j].l,tre[j].r,tre[j].mid,tre[j].t1,tre[j].lazy);
}
// printf("When x == %d,ans == %d\n",x,query(1,q));
return query(1,q);
}
inline void biSearch(){
int l=0,r=n,x=0,ans;
while(l<=r){
x=(l+r)>>1;
if(check(x))ans=x,l=x+1;
else r=x-1;
}
fwrit(ans),putchar('\n');
}
signed main(){
#ifdef FILEOI
freopen("sort.in","r",stdin);
freopen("sort.out","w",stdout);
#endif
init();
biSearch();
return 0;
}
T3 「THUWC 2017」随机二分图
题目
考场思路
看到二分图,再看到数学期望,直接跳过 虽然后面已经没有题可以跳了
正解
讲了半天,有点昏,先让我缓一下...
「CSP-S模拟赛」2019第二场的更多相关文章
- 「CSP-S模拟赛」2019第一场
目录 T1 小奇取石子 题目 考场思路 正解 T2 「CCO 2017」专业网络 题目 考场思路 题解 T3 「ZJOI2017」线段树 题目 考场思路 正解 这场考试感觉很奇怪. \(T1.T2\) ...
- 「CSP-S模拟赛」2019第四场
「CSP-S模拟赛」2019第四场 T1 「JOI 2014 Final」JOI 徽章 题目 考场思考(正解) T2 「JOI 2015 Final」分蛋糕 2 题目 考场思考(正解) T3 「CQO ...
- #10471. 「2020-10-02 提高模拟赛」灌溉 (water)
题面:#10471. 「2020-10-02 提高模拟赛」灌溉 (water) 假设只有一组询问,我们可以用二分求解:二分最大距离是多少,然后找到深度最大的结点,并且把它的\(k\)倍祖先的一整子树删 ...
- #10470. 「2020-10-02 提高模拟赛」流水线 (line)
题面:#10470. 「2020-10-02 提高模拟赛」流水线 (line) 题目中的那么多区间的条件让人感觉极其难以维护,而且贪心的做法感觉大多都能 hack 掉,因此考虑寻找一些性质,然后再设计 ...
- 「CSP-S模拟赛」2019第三场
目录 T1 「POI2007」山峰和山谷 Ridges and Valleys 题目 考场思路(几近正解) 正解 T2 「JOI 2013 Final」 现代豪宅 题目 考场思路(正解) T3 「SC ...
- 「2019-8-13提高模拟赛」树 (tree)
传送门 Description 你有一个 \(n\)个点的树,第 \(i\)个点的父亲是\(p_i\).每个点有一个权值 \(t_i\) 和一个颜色黑或者白.所有点一开始都是白色. 你要进行 \(m\ ...
- 「2019-8-11提高模拟赛」女装盛宴 (flag)
传送门 Solution 基环树+倍增+双指针 第一次因为#define int long long而玄学RE 为什么标程都不用开\(long long\)啊 Code /*玄学RE 看来defi ...
- 「THP3考前信心赛」解题报告
目录 写在前面&总结: T1 T2 T3 T4 写在前面&总结: \(LuckyBlock\) 良心出题人!暴力分给了 \(120pts\) \(T1\) 貌似是个结论题,最后知道怎么 ...
- 「Vijos 1284」「OIBH杯NOIP2006第二次模拟赛」佳佳的魔法阵
佳佳的魔法阵 背景 也许是为了捕捉猎物(捕捉MM?),也许是因为其它原因,总之,佳佳准备设计一个魔法阵.而设计魔法阵涉及到的最关键问题,似乎就是那些带有魔力的宝石的摆放-- 描述 魔法阵是一个\(n ...
随机推荐
- 批量启动关闭MS SQL 2005服务BAT
当装上了MSSQL2005后,内存的占用会变得很大.所以如果用一个批量处理来开启或关闭MSSQL2005所有的服务,那将会让我们的电脑更好使用.根据自己的经验,做出了下面两个批处理: 1.开启服务:( ...
- TP-网页静态化
首先放上一张某手册中的一段代码: 我们要想在TP框架中执行网页静态化,在这段代码的基础上稍加添加就可以了: 在TP5框架中,为了方便寻找模板文件与生成的静态文件,我们将模板文件以及生成的静态文件放在p ...
- 7.Springboot之web开发
自用 要解决的问题: 1.导入静态资源(html之类的(webapp)) 2.首页 3.没有写Jsp的地方-------->所以要学模板引擎Thymeleaf 4.装配扩展springmvc 5 ...
- 【Python】程序计时
- K3/Cloud树形单据体的rowId赋值
RowId是树形单据体独有的,同一单据体中不能重复,用如下语句取. System.Guid.NewGuid().ToString() 同时FGROUP也需要重新设置,值可以和FSeq一样.
- Learn from Niu 2020.1.21
1. 你一定要看计算机领域的文章. 如果你是看一堆应用,你最终还是会不知道怎么做. 从计算机到energy是降维打击, 当你学习了计算机的hot skill,再去做应用很容易. 2. 搞研究的思路: ...
- web前端常用库
项目中可能用到的web前端库(持续记录): 1.轻量化货币库:https://github.com/openexchangerates/accounting.js ,美元形式.欧元形式等 2.时间 ...
- c# DPI SCale
public class Screen { /// Primary Screen #region Win32 API [DllImport("user32.dll")] stati ...
- AC3 encoder flow
AC3 encoder flow 如下: 1.input PCM PCM在进入encoder前会使用high pass filter来移除信号的DC部分来达到更有效的编码. 2.Transient d ...
- 【C语言】输入三个正整数a,b,c,求最大值,要求定义一个计算最大值的函数max(a,b),返回a,b的值
#include<stdio.h> int max(int a, int b)/*定义函数*/ { if (a > b) return a; else return b; } int ...