这场考试的数据感觉很水。

\(T1\) 签到不解释,\(T2\) 期望 \(50pts\) 结果有 \(100pts\),\(T3\) 一如既往地不可做...


T1 Jam的计数法

题目

点这里

考场思路(正解)

其实没有什么好说的,找找规律即可,看看代码吧。

  1. #include<cstdio>
  2. // #define FILEOI
  3. #define rep(i,__l,__r) for(int i=__l,i##_end_=__r;i<=i##_end_;++i)
  4. #define dep(i,__l,__r) for(int i=__l,i##_end_=__r;i>=i##_end_;--i)
  5. #define cg (c=getchar())
  6. template<class T>inline void qread(T& x){
  7. x=0;char c;bool f=0;
  8. while(cg<'0'||'9'<c)if(c=='-')f=1;
  9. for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
  10. if(f)x=-x;
  11. }
  12. template<class T,class... Args>inline void qread(T& x,Args&... args){qread(x),qread(args...);}
  13. inline int qread(){
  14. int x=0;char c;bool f=0;
  15. while(cg<'0'||'9'<c)if(c=='-')f=1;
  16. for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
  17. return f?x:-x;
  18. }
  19. #undef cg
  20. template<class T>inline T Max(const T x,const T y){return x>y?x:y;}
  21. template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
  22. template<class T>inline T fab(const T x){return x>0?x:-x;}
  23. template<class T>void fwrit(T x){
  24. if(x<0)return (void)(putchar('-'),fwrit(-x));
  25. if(x>10)fwrit(x/10);
  26. return (void)(putchar(x%10^48));
  27. }
  28. const int MAXW=25;
  29. int s,t,w,num[(MAXW<<2)+5],T=5;
  30. char sn[(MAXW<<2)+5];
  31. inline void init(){
  32. qread(s,t,w);
  33. scanf("%s",sn+1);
  34. rep(i,1,w)num[i]=sn[i]-'a'+1;
  35. }
  36. inline void putNum(){
  37. for(int i=1;i<=w;++i)printf("%c",num[i]+'a'-1);
  38. putchar('\n');
  39. }
  40. inline void addOne(){
  41. bool f=true;
  42. for(int i=w;i>=1;--i)if(num[i]<t-w+i){
  43. ++num[i],f=false;
  44. for(int j=i+1;j<=w;++j)num[j]=num[j-1]+1;
  45. break;
  46. }
  47. if(f)return;
  48. putNum();
  49. }
  50. signed main(){
  51. #ifdef FILEOI
  52. freopen("number.in","r",stdin);
  53. freopen("number.out","w",stdout);
  54. #endif
  55. init();
  56. while(T--)addOne();
  57. return 0;
  58. }

T2 「TJOI / HEOI2016」排序

题目

点这里

考场思路(假正解)

直接看的 \(50\%\) 的数据范围,发现可以使用区间桶排序,时间复杂度 \(O(nm)\)。

  1. #include<cstdio>
  2. // #define FILEOI
  3. #define rep(i,__l,__r) for(int i=__l,i##_end_=__r;i<=i##_end_;++i)
  4. #define dep(i,__l,__r) for(int i=__l,i##_end_=__r;i>=i##_end_;--i)
  5. #define cg (c=getchar())
  6. template<class T>inline void qread(T& x){
  7. x=0;char c;bool f=0;
  8. while(cg<'0'||'9'<c)if(c=='-')f=1;
  9. for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
  10. if(f)x=-x;
  11. }
  12. template<class T,class... Args>inline void qread(T& x,Args&... args){qread(x),qread(args...);}
  13. inline int qread(){
  14. int x=0;char c;bool f=1;
  15. while(cg<'0'||'9'<c)if(c=='-')f=0;
  16. for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
  17. return f?x:-x;
  18. }
  19. #undef cg
  20. template<class T>inline T Max(const T x,const T y){return x>y?x:y;}
  21. template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
  22. template<class T>inline T fab(const T x){return x>0?x:-x;}
  23. template<class T>void fwrit(T x){
  24. if(x<0)return (void)(putchar('-'),fwrit(-x));
  25. if(x>10)fwrit(x/10);
  26. return (void)(putchar(x%10^48));
  27. }
  28. const int MAXN=1e5;
  29. int n,m,q,a[MAXN+5],t[MAXN+5];
  30. inline void init(){
  31. qread(n,m);
  32. rep(i,1,n)qread(a[i]);
  33. }
  34. inline void getOperation(){
  35. int op,l,r,li,ri;
  36. while(m--){
  37. li=n,ri=0;
  38. qread(op,l,r);
  39. rep(i,l,r)++t[a[i]],li=Min(li,a[i]),ri=Max(ri,a[i]);
  40. if(op==0){
  41. rep(i,l,r){
  42. while(t[li]==0)++li;
  43. a[i]=li,t[li]=0;
  44. }
  45. }
  46. else if(op==1){
  47. rep(i,l,r){
  48. while(t[ri]==0)--ri;
  49. a[i]=ri,t[ri]=0;
  50. }
  51. }
  52. }
  53. printf("%d\n",a[qread()]);
  54. }
  55. signed main(){
  56. #ifdef FILEOI
  57. freopen("sort.in","r",stdin);
  58. freopen("sort.out","w",stdout);
  59. #endif
  60. init();
  61. getOperation();
  62. return 0;
  63. }

期望得分只有 \(50pts\),但是数据测出来,居然可以 \(A\) 掉...所以叫伪正解...

正解

我们发现,对于一个 \(x\),将小于 \(x\) 的数换成 \(0\),大于等于 \(x\) 的数换成 \(1\) 之后,所得到的排序结果其实是一样的。

但是这样做有唯一的缺陷,就是我们只知道最后 \(q\) 位置的数是 \(0\) 还是 \(1\)。

其实很好解决,二分这个 \(x\) 即可。

这里先把标称附上

std version

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cctype>
  4. #define lc o << 1
  5. #define rc o << 1 | 1
  6. #define mid (l + r) / 2
  7. using namespace std;
  8. const int N = 100010;
  9. int n, m, p;
  10. int T[4 * N], lazy[4 * N]; // segment tree
  11. int a[N], ch[N], L[N], R[N]; // the information by reading
  12. inline int read() {
  13. char ch = getchar();
  14. int x = 0;
  15. while (!isdigit(ch)) ch = getchar();
  16. while (isdigit(ch)) {
  17. x = x * 10 + ch - '0';
  18. ch = getchar();
  19. }
  20. return x;
  21. }
  22. inline void build(int o, int l, int r, int x) {
  23. if (l == r) {
  24. T[o] = a[l] >= x;
  25. lazy[o] = 0;
  26. return;
  27. }
  28. build(lc, l, mid, x);
  29. build(rc, mid + 1, r, x);
  30. T[o] = T[lc] + T[rc];
  31. lazy[o] = 0;
  32. }
  33. inline void pushdown(int o, int l, int r) {
  34. if (!lazy[o])
  35. return;
  36. lazy[lc] = lazy[rc] = lazy[o];
  37. if (lazy[o] == 1) {
  38. T[lc] = mid - l + 1;
  39. T[rc] = r - mid;
  40. } else
  41. T[lc] = T[rc] = 0;
  42. lazy[o] = 0;
  43. }
  44. inline int query(int o, int l, int r, int x, int y) {
  45. if (x <= l && y >= r)
  46. return T[o];
  47. if (x > r || y < l)
  48. return 0;
  49. pushdown(o, l, r);
  50. return query(lc, l, mid, x, y) + query(rc, mid + 1, r, x, y);
  51. }
  52. inline int queryPoint(int o, int l, int r, int x) {
  53. if (l == x && r == x)
  54. return T[o];
  55. pushdown(o, l, r);
  56. if (x <= mid)
  57. return queryPoint(lc, l, mid, x);
  58. else
  59. return queryPoint(rc, mid + 1, r, x);
  60. }
  61. inline void update(int o, int l, int r, int x, int y, int val) {
  62. if (x <= l && y >= r) {
  63. T[o] = val * (r - l + 1);
  64. lazy[o] = val ? 1 : -1;
  65. return;
  66. }
  67. if (x > r || y < l)
  68. return;
  69. pushdown(o, l, r);
  70. update(lc, l, mid, x, y, val);
  71. update(rc, mid + 1, r, x, y, val);
  72. T[o] = T[lc] + T[rc];
  73. }
  74. inline bool check(int x) {
  75. build(1, 1, n, x);
  76. for (int i = 1; i <= m; i++) {
  77. int cnt1 = query(1, 1, n, L[i], R[i]);
  78. if (ch[i] == 0) {
  79. update(1, 1, n, R[i] - cnt1 + 1, R[i], 1);
  80. update(1, 1, n, L[i], R[i] - cnt1, 0);
  81. } else {
  82. update(1, 1, n, L[i], L[i] + cnt1 - 1, 1);
  83. update(1, 1, n, L[i] + cnt1, R[i], 0);
  84. }
  85. }
  86. return queryPoint(1, 1, n, p);
  87. }
  88. int main() {
  89. freopen("sort.in","r",stdin);
  90. freopen("sort.out","w",stdout);
  91. n = read();
  92. m = read();
  93. for (int i = 1; i <= n; i++) a[i] = read();
  94. for (int i = 1; i <= m; i++) {
  95. ch[i] = read();
  96. L[i] = read();
  97. R[i] = read();
  98. }
  99. p = read();
  100. int ll = 1, rr = n, midd, ans;
  101. while (ll <= rr) {
  102. midd = (ll + rr) >> 1;
  103. if (check(midd))
  104. ans = midd, ll = midd + 1;
  105. else
  106. rr = midd - 1;
  107. }
  108. printf("%d\n", rr);
  109. return 0;
  110. }

My version

  1. #include<cstdio>
  2. // #define FILEOI
  3. #define lc (i<<1)
  4. #define rc (i<<1|1)
  5. #define rep(i,__l,__r) for(int i=__l,i##_end_=__r;i<=i##_end_;++i)
  6. #define dep(i,__l,__r) for(int i=__l,i##_end_=__r;i>=i##_end_;--i)
  7. #define cg (c=getchar())
  8. template<class T>inline void qread(T& x){
  9. x=0;char c;bool f=0;
  10. while(cg<'0'||'9'<c)if(c=='-')f=1;
  11. for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
  12. if(f)x=-x;
  13. }
  14. template<class T,class... Args>inline void qread(T& x,Args&... args){qread(x),qread(args...);}
  15. inline int qread(){
  16. int x=0;char c;bool f=1;
  17. while(cg<'0'||'9'<c)if(c=='-')f=0;
  18. for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
  19. return f?x:-x;
  20. }
  21. #undef cg
  22. template<class T>inline T Max(const T x,const T y){return x>y?x:y;}
  23. template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
  24. template<class T>inline T fab(const T x){return x>0?x:-x;}
  25. template<class T>void fwrit(T x){
  26. if(x<0)return (void)(putchar('-'),fwrit(-x));
  27. if(x>10)fwrit(x/10);
  28. return (void)(putchar(x%10^48));
  29. }
  30. const int MAXN=1e5;
  31. const int MAXM=1e5;
  32. struct change{int op,l,r;}p[MAXM+5];
  33. struct node{
  34. int l,r,mid,t1,lazy;
  35. node(){lazy=-1;}
  36. node(const int L,const int R,const int M):l(L),r(R),mid(M){lazy=-1;}
  37. }tre[(MAXN<<2)+5];
  38. int n,m,a[MAXN+5],t[MAXN+5],q;
  39. inline void init(){
  40. qread(n,m);
  41. rep(i,1,n)qread(a[i]);
  42. for(int i=1;i<=m;++i)p[i]=change{qread(),qread(),qread()};
  43. qread(q);
  44. }
  45. inline void pushup(const int i){tre[i].t1=tre[lc].t1+tre[rc].t1;}
  46. inline void pushdown(const int i){
  47. if(tre[i].l^tre[i].r){
  48. if(tre[i].lazy==1){
  49. tre[lc].lazy=tre[rc].lazy=1;
  50. tre[lc].t1=(tre[lc].r-tre[lc].l+1);
  51. tre[rc].t1=(tre[rc].r-tre[rc].l+1);
  52. }
  53. else if(tre[i].lazy==0){
  54. tre[lc].lazy=tre[rc].lazy=0;
  55. tre[lc].t1=tre[rc].t1=0;
  56. }
  57. }
  58. tre[i].lazy=-1;
  59. }
  60. inline void buildtre(const int i,const int l,const int r,const int x){
  61. // printf("buildtre : %d %d %d %d\n",i,l,r,x);
  62. int mid=(l+r)>>1;
  63. tre[i]=node(l,r,mid);
  64. if(l==r)return (void)(tre[i].t1=(a[l]>=x));
  65. buildtre(lc,l,mid,x);
  66. buildtre(rc,mid+1,r,x);
  67. pushup(i);
  68. }
  69. inline int query(const int i,const int l,const int r){
  70. // printf("query : %d %d %d\n",i,l,r);
  71. if(l<=tre[i].l&&tre[i].r<=r)return tre[i].t1;
  72. if(tre[i].lazy!=-1)pushdown(i);
  73. int ret=0;
  74. if(l<=tre[i].mid)ret+=query(lc,l,r);
  75. if(tre[i].mid<r)ret+=query(rc,l,r);
  76. pushup(i);
  77. return ret;
  78. }
  79. inline void update(const int i,const int l,const int r,const int var){
  80. // if(l>r)return;
  81. // printf("update : %d to %d, %d\n",l,r,var);
  82. if(l<=tre[i].l&&tre[i].r<=r){
  83. tre[i].lazy=var;
  84. tre[i].t1=(tre[i].r-tre[i].l+1)*var;
  85. return;
  86. }
  87. if(tre[i].lazy!=-1)pushdown(i);
  88. if(l<=tre[i].mid)update(lc,l,r,var);
  89. if(tre[i].mid<r)update(rc,l,r,var);
  90. pushup(i);
  91. }
  92. inline int query(const int i,const int p){
  93. // printf("update : %d %d\n",i,p);
  94. if(tre[i].l==tre[i].r)return tre[i].t1;
  95. if(tre[i].lazy!=-1)pushdown(i);
  96. int ret;
  97. if(p<=tre[i].mid)ret=query(lc,p);
  98. else ret=query(rc,p);
  99. pushup(i);
  100. return ret;
  101. }
  102. inline bool check(const int x){
  103. // printf("Now check : x == %d\n",x);
  104. buildtre(1,1,n,x);
  105. // 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);
  106. rep(i,1,m){
  107. int cnt1=query(1,p[i].l,p[i].r);
  108. int cnt0=p[i].r-p[i].l+1-cnt1;
  109. // printf("query : %d %d, cnt1 == %d, cnt0 == %d\n",p[i].l,p[i].r,cnt1,cnt0);
  110. if(p[i].op==0){
  111. if(cnt0)update(1,p[i].l,p[i].l+cnt0-1,0);
  112. if(cnt1)update(1,p[i].l+cnt0,p[i].r,1);
  113. // printf("update : %d to %d, %d\n",p[i].l,p[i].l+cnt0-1,0);
  114. // printf("update : %d to %d, %d\n",p[i].l+cnt0,p[i].r,1);
  115. }
  116. else{
  117. if(cnt1)update(1,p[i].l,p[i].l+cnt1-1,1);
  118. if(cnt0)update(1,p[i].l+cnt1,p[i].r,0);
  119. // printf("update : %d to %d, %d\n",p[i].l,p[i].l+cnt1-1,0);
  120. // printf("update : %d to %d, %d\n",p[i].l+cnt1,p[i].r,1);
  121. }
  122. // printf("Now The info of the tre :\n");
  123. // 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);
  124. }
  125. // printf("When x == %d,ans == %d\n",x,query(1,q));
  126. return query(1,q);
  127. }
  128. inline void biSearch(){
  129. int l=0,r=n,x=0,ans;
  130. while(l<=r){
  131. x=(l+r)>>1;
  132. if(check(x))ans=x,l=x+1;
  133. else r=x-1;
  134. }
  135. fwrit(ans),putchar('\n');
  136. }
  137. signed main(){
  138. #ifdef FILEOI
  139. freopen("sort.in","r",stdin);
  140. freopen("sort.out","w",stdout);
  141. #endif
  142. init();
  143. biSearch();
  144. return 0;
  145. }

T3 「THUWC 2017」随机二分图

题目

点这里

考场思路

看到二分图,再看到数学期望,直接跳过 虽然后面已经没有题可以跳了

正解

讲了半天,有点昏,先让我缓一下...

「CSP-S模拟赛」2019第二场的更多相关文章

  1. 「CSP-S模拟赛」2019第一场

    目录 T1 小奇取石子 题目 考场思路 正解 T2 「CCO 2017」专业网络 题目 考场思路 题解 T3 「ZJOI2017」线段树 题目 考场思路 正解 这场考试感觉很奇怪. \(T1.T2\) ...

  2. 「CSP-S模拟赛」2019第四场

    「CSP-S模拟赛」2019第四场 T1 「JOI 2014 Final」JOI 徽章 题目 考场思考(正解) T2 「JOI 2015 Final」分蛋糕 2 题目 考场思考(正解) T3 「CQO ...

  3. #10471. 「2020-10-02 提高模拟赛」灌溉 (water)

    题面:#10471. 「2020-10-02 提高模拟赛」灌溉 (water) 假设只有一组询问,我们可以用二分求解:二分最大距离是多少,然后找到深度最大的结点,并且把它的\(k\)倍祖先的一整子树删 ...

  4. #10470. 「2020-10-02 提高模拟赛」流水线 (line)

    题面:#10470. 「2020-10-02 提高模拟赛」流水线 (line) 题目中的那么多区间的条件让人感觉极其难以维护,而且贪心的做法感觉大多都能 hack 掉,因此考虑寻找一些性质,然后再设计 ...

  5. 「CSP-S模拟赛」2019第三场

    目录 T1 「POI2007」山峰和山谷 Ridges and Valleys 题目 考场思路(几近正解) 正解 T2 「JOI 2013 Final」 现代豪宅 题目 考场思路(正解) T3 「SC ...

  6. 「2019-8-13提高模拟赛」树 (tree)

    传送门 Description 你有一个 \(n\)个点的树,第 \(i\)个点的父亲是\(p_i\).每个点有一个权值 \(t_i\) 和一个颜色黑或者白.所有点一开始都是白色. 你要进行 \(m\ ...

  7. 「2019-8-11提高模拟赛」女装盛宴 (flag)

    传送门 Solution  基环树+倍增+双指针 第一次因为#define int long long而玄学RE 为什么标程都不用开\(long long\)啊 Code  /*玄学RE 看来defi ...

  8. 「THP3考前信心赛」解题报告

    目录 写在前面&总结: T1 T2 T3 T4 写在前面&总结: \(LuckyBlock\) 良心出题人!暴力分给了 \(120pts\) \(T1\) 貌似是个结论题,最后知道怎么 ...

  9. 「Vijos 1284」「OIBH杯NOIP2006第二次模拟赛」佳佳的魔法阵

    佳佳的魔法阵 背景 也许是为了捕捉猎物(捕捉MM?),也许是因为其它原因,总之,佳佳准备设计一个魔法阵.而设计魔法阵涉及到的最关键问题,似乎就是那些带有魔力的宝石的摆放-- 描述 魔法阵是一个\(n ...

随机推荐

  1. 顶级Kagglers的心得和技巧

    这是一篇笔记,课程来自Coursera上的How to Win a Data Science Competition: Learn from Top Kagglers 本篇可以算是顶级Kaggler大 ...

  2. Java类、方法、属性等

    java是面向对象的编程语言 Object,就是指面向对象的对象,对象就是类的具体实例. 在java里,对象是类的一个具体实例.就像:人,指一个类.张三.李四.王五等则是一个个具体的实例,也就是jav ...

  3. print format

    python基础_格式化输出(%用法和format用法) name = 'jack' age = 18 sex = 'man' job = "IT" salary = 9999.9 ...

  4. Jarvis OJ - class10 -Writeup

    Jarvis OJ - class10 -Writeup 转载请注明出处:http://www.cnblogs.com/WangAoBo/p/7552266.html 题目: Jarivs OJ的一道 ...

  5. Ubuntu 的apt install 和卸载正确姿势

    先说下使用apt  installl 安装的包的卸载: apt-get remove: 卸载软件apt-get purge: 卸载软件和配置文件apt-get autoremove: 移除没有使用的依 ...

  6. dp--C - Mysterious Present

    C - Mysterious Present Peter decided to wish happy birthday to his friend from Australia and send hi ...

  7. jquery如何将信息遍历到界面上

    1.使用的时候一定要导入juqery库 1.1 这里放置一个cdn的库 <script src="https://cdn.staticfile.org/jquery/1.10.2/jq ...

  8. 常用的 19 条 MySQL 优化

    一.EXPLAIN 做MySQL优化,我们要善用 EXPLAIN 查看SQL执行计划. 下面来个简单的示例,标注(1,2,3,4,5)我们要重点关注的数据 type列,连接类型.一个好的sql语句至少 ...

  9. iframe宽高自适应

    iframe子页面结尾添加本script iframe子页面结尾添加本script <script type="text/javascript">         fu ...

  10. 实体的时间date属性的字段之表单提交

    @InitBinder public void initBinder(WebDataBinder binder) { DateFormat dateFormat = new SimpleDateFor ...