CF1151div2(Round 553)

思路题大赛

A

少考虑了一种情况,到死没想到

B

貌似我随机化50000次,没找到就无解貌似也过了

感觉随随便便乱搞+分类讨论都可以过的样子

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 505;
inline int read(){int v = 0,c = 1;char ch = getchar();while(!isdigit(ch)){if(ch == '-') c = -1;ch = getchar();}while(isdigit(ch)){v = v * 10 + ch - 48;ch = getchar();}return v * c;
}
int a[N][N];
int b[N][N];
int tot;
int s[N];
int n,m;
inline bool pan(){for(int i = 1;i <= n;++i)for(int j = 1;j <= n;++j)if(b[i][j] != 1) return 0;return 1;
}
inline bool check(){if(pan()){if(n & 1){for(int i = 1;i <= n;++i) s[++tot] = 1;return 1;   }else return 0;}}
int main(){srand(time(0));n = read(),m = read();for(int i = 1;i <= n;++i) for(int j = 1;j <= m;++j) a[i][j] = read();for(int t = 1;t <= 50000;++t){int now = 0;for(int i = 1;i < n;++i) s[i] = rand() % m + 1,now ^= a[i][s[i]];for(int i = 1;i <= m;++i){if((now ^ a[n][i]) != 0){s[n] = i;printf("TAK\n");for(int j = 1;j <= n;++j) printf("%d ",s[j]);return 0;}}}printf("NIE\n");return 0;
}

C

~~辣鸡CF连__int128都不支持~~

我们将所有的区间分成log块去考虑

每一块的内部其实都是等差数列

我们可以用等差数列求和公式

对于\(L,R\)就求一下前缀和

另外项数可能很大,一定要%mod(我就是因为这个WA的)

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const LL mod = 1e9 + 7;
inline LL read(){LL v = 0,c = 1;char ch = getchar();while(!isdigit(ch)){if(ch == '-') c = -1;ch = getchar();}while(isdigit(ch)){v = v * 10 + ch - 48;ch = getchar();}return v * c;
}
LL L,R;
LL sum[129];
LL shou[129];
inline LL quick(LL x,LL y){LL res = 1;while(y){if(y & 1) res = res * x % mod;y >>= 1;x = x * x % mod;    }   return res;
}
LL inv2 = quick(2,mod - 2);
inline LL work(LL x){if(x == 0) return 0;LL cnt = 0;LL gg = 0;LL ans = 0;while(gg + (1ll << cnt) <= x){ans = (ans + sum[cnt]) % mod;gg += (1ll << cnt);cnt++;  }if(gg != x){LL rest = (x - gg) % mod;LL rail = (shou[cnt] + (rest - 1) * 2 % mod) % mod;ans = (ans + (shou[cnt] + rail) % mod * rest % mod * inv2 % mod) % mod;}return ans;
}
int main(){L = read(),R = read();LL now = 0;LL base = 0;LL ji = 1;LL ou = 2; long long rr = R;do{rr -= (1ll << base);//  printf("%lld\n",rr);if(base & 1){shou[base] = ou;sum[base] = (ou + (ou + 2 * (quick(2,base) - 1) % mod) % mod) % mod * quick(2,base) % mod * inv2 % mod;ou = (ou + 2 * (quick(2,base)) % mod) % mod;}else{shou[base] = ji;sum[base] = (ji + (ji + 2 * (quick(2,base) - 1) % mod) % mod) % mod * quick(2,base) % mod * inv2 % mod;ji = (ji + 2 * (quick(2,base)) % mod) % mod;}base++;}while(rr > 0);
//  for(int i = 0;i <= base;++i) printf("%lld\n",(long long)(sum[i]));long long ans = ((work(R) - work(L - 1) + mod) % mod + mod) % mod;printf("%lld\n",(long long)ans); return 0;
}

D

化式子可以发现,只和\(a_i-b_i\)的值有关

然后就快乐排序算贡献

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const LL mod = 1e9 + 7;
inline LL read(){LL v = 0,c = 1;char ch = getchar();while(!isdigit(ch)){if(ch == '-') c = -1;ch = getchar();}while(isdigit(ch)){v = v * 10 + ch - 48;ch = getchar();}return v * c;
}
LL L,R;
LL sum[129];
LL shou[129];
inline LL quick(LL x,LL y){LL res = 1;while(y){if(y & 1) res = res * x % mod;y >>= 1;x = x * x % mod;    }   return res;
}
LL inv2 = quick(2,mod - 2);
inline LL work(LL x){if(x == 0) return 0;LL cnt = 0;LL gg = 0;LL ans = 0;while(gg + (1ll << cnt) <= x){ans = (ans + sum[cnt]) % mod;gg += (1ll << cnt);cnt++;  }if(gg != x){LL rest = (x - gg) % mod;LL rail = (shou[cnt] + (rest - 1) * 2 % mod) % mod;ans = (ans + (shou[cnt] + rail) % mod * rest % mod * inv2 % mod) % mod;}return ans;
}
int main(){L = read(),R = read();LL now = 0;LL base = 0;LL ji = 1;LL ou = 2; long long rr = R;do{rr -= (1ll << base);//  printf("%lld\n",rr);if(base & 1){shou[base] = ou;sum[base] = (ou + (ou + 2 * (quick(2,base) - 1) % mod) % mod) % mod * quick(2,base) % mod * inv2 % mod;ou = (ou + 2 * (quick(2,base)) % mod) % mod;}else{shou[base] = ji;sum[base] = (ji + (ji + 2 * (quick(2,base) - 1) % mod) % mod) % mod * quick(2,base) % mod * inv2 % mod;ji = (ji + 2 * (quick(2,base)) % mod) % mod;}base++;}while(rr > 0);
//  for(int i = 0;i <= base;++i) printf("%lld\n",(long long)(sum[i]));long long ans = ((work(R) - work(L - 1) + mod) % mod + mod) % mod;printf("%lld\n",(long long)ans); return 0;
}

E

首先一个小\(trick\)

树上的连通块数 = 点数 - 边数(本题是链也)

所以答案变成了点数之和减去边数之和

对于一个点\(i\),他的贡献应该是
\[ a_i*(n - a_i + 1) \]
就是左端点和右端点的取值都要合法

一条边存在仅当他链接的两个点都存在
\[ min(a_i,a_{i + 1}) * (n - max(a_i,a_{i + 1}) + 1) \]
所以把这些东西算一算就好了

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 1e5 + 3;
int a[N];
int n;
inline int read(){int v = 0,c = 1;char ch = getchar();while(!isdigit(ch)){if(ch == '-') c = -1;ch = getchar();}while(isdigit(ch)){v = v * 10 + ch - 48;ch = getchar();}return v * c;
}
int main(){LL ans = 0;n = read();for(int i = 1;i <= n;++i) a[i] = read();for(int i = 1;i <= n;++i) ans += 1ll * a[i] * (n - a[i] + 1);for(int i = 1;i < n;++i) ans -= 1ll * min(a[i],a[i + 1]) * (n - max(a[i],a[i + 1]) + 1); cout << ans; return 0;
}

F

见这一篇

转载于:https://www.cnblogs.com/wyxdrqc/p/11402982.html

CF1151div2(Round 553)相关推荐

  1. QAQorz的训练记录

    感觉还是该从今天开始记下来 5.8日查询 870(查询系统) + 100(洛谷) + 100(牛客) = 1070题, 去重按1000题算 5.8 牛客寒训营 3F 双向搜索+处理前后缀积 牛客寒训营 ...

  2. 一些比赛的题解(共32场)

    之前写在本地的,丢上来测试一下 1. Educational Codeforces Round 56 E 题意:映射后即为,给一个排列,支持两种操作:询问区间[lb,rb]内权值在[la,ra]内的数 ...

  3. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  4. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

  5. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  6. Codeforces Round #300 A. Cutting Banner 水题

    A. Cutting Banner Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/pro ...

  7. Oracle round函数是什么意思?怎么运用?

    如何使用 Oracle Round 函数 (四舍五入) 描述 : 传回一个数值,该数值是按照指定的小数位元数进行四舍五入运算的结果. SELECT ROUND( number, [ decimal_p ...

  8. Codeforces Round #270

    Codeforces Round #270 题目链接 A:我是筛了下素数.事实上偶数仅仅要输出4和x - 4,奇数输出9和x - 9就可以 B:贪心的策略,把时间排序后.取每k个的位置 C:贪心.每次 ...

  9. python3 的 round 函数的 练习

    python3 的 round 函数感觉很别扭,其运算结果与习惯不相符.特记录下来: 代码 ''' python 3的 round 函数 是"四舍六入五成双"的https://ww ...

  10. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

最新文章

  1. 大数据学习——MapReduce学习——字符统计WordCount
  2. 七种常见分布式事务详解(2PC、3PC、TCC、Saga、本地事务表、MQ事务消息、最大努力通知)
  3. bean的属性类型----ibatis类型-------oracle数据库类型
  4. 统计字符串中单词个数
  5. java 编程工具_Java开发工具可以促进编程!
  6. python协程实现一万并发_python中的协程并发
  7. 更换ssh通信证书,ssh更改公钥和密钥,以保证服务器安全
  8. Unity3D - UGUI组件的中英文对照
  9. Linux命令su、sudo、sudo su、sudo -i使用和区别
  10. 十-二进制数的最少数目
  11. 戴尔推出PowerEdge T30,主打小型办公和家庭办公市场
  12. 总是通过加班,来完成工作,那都是假象
  13. 最新彩虹DS仿小储云模板源码
  14. 保险中介系列法规年内出台
  15. 蓝桥杯第八届省赛 电子钟 by YYC
  16. (转)一个初学者RHCE学习考试之路
  17. 基于verilog状态机的八层电梯实现
  18. 浪潮服务器安装windows2008系统,浪潮NF5280M3安装Windows Server 2008 R2注意事项
  19. python求阶乘怎么做_python如何求阶乘
  20. 经典案例:卖票问题【线程同步】

热门文章

  1. 新年祝福:向所有开源工作人员表示真诚的感恩
  2. eclipse中出现代码覆盖的颜色信息,如何去掉
  3. doubango编码及发送流程的疑惑
  4. 使用超时加锁:pthread_mutex_timedlock
  5. 南宁出租车绿灯表示有客,红灯表示空车
  6. java中quickstart_Beam编程系列之Java SDK Quickstart(官网的推荐步骤)
  7. Dxg——AD(Altium Designer) 开发笔记整理分类合集【所有的相关记录,都整理在此】
  8. c++ 文件操作方式
  9. python 微信爬虫_PythonWchatScrapy
  10. 公式中的引号怎么输_Excel计数函数中这些奇怪的参数让我百思不得其解!