hihoCoder 2 * problem
1792
模拟,转化为二进制后逐位比较
1819
线段树维护区间加
维护每个数加了多少
每次弹出栈顶元素后栈顶位置注意清空
1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string> using namespace std; const int N = ; int a[N], b[N];
int n; int Tow(int A[], int x) {
static int c[N];
int js = ;
while(x) {
c[++ js] = x % ;
x /= ;
}
for(int i = ; i <= js; i ++) A[i] = c[js - i + ];
return js;
} int main() {
cin >> n;
int Max = max(Tow(a, n), Tow(b, n - ));
int Answer = ;
for(int i = ; i <= Max; i ++) Answer += (a[i] != b[i]);
cout << Answer; return ;
}
1819
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string> using namespace std; #define LL long long
#define int long long
#define gc getchar()
inline int read() {int x = ; char c = gc; while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc; return x;}
inline LL read_LL() {LL x = ; char c = gc; while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc; return x;}
#undef gc const int N = 2e5 + ; LL W[N << ], F[N << ], Size[N << ];
int n;
int Num[N], js; #define lson jd << 1
#define rson jd << 1 | 1 void Build_tree(int l, int r, int jd) {
Size[jd] = (r - l + );
if(l == r) return ;
int mid = (l + r) >> ;
Build_tree(l, mid, lson), Build_tree(mid + , r, rson);
} void Push_down(int jd) {
W[lson] += Size[lson] * F[jd], W[rson] += Size[rson] * F[jd];
F[lson] += F[jd], F[rson] += F[jd];
F[jd] = ;
} LL Poi_A(int l, int r, int jd, int x) {
if(l == r) {
return W[jd];
}
if(F[jd]) Push_down(jd);
int mid = (l + r) >> ;
if(x <= mid) Poi_A(l, mid, lson, x);
else Poi_A(mid + , r, rson, x);
} void Sec_G(int l, int r, int jd, int x, int y, int num) {
if(x <= l && r <= y) {
W[jd] += Size[jd] * num;
F[jd] += num;
return ;
}
if(F[jd]) Push_down(jd);
int mid = (l + r) >> ;
if(x <= mid) Sec_G(l, mid, lson, x, y, num);
if(y > mid ) Sec_G(mid + , r, rson, x, y, num);
W[jd] = W[lson] + W[rson];
} main() {
n = read();
Build_tree(, n, );
for(int i = ; i <= n; i ++) {
char opt[]; scanf("%s", opt);
if(opt[] == 'p' && opt[] == 'u') {
int x = read(); Num[++ js] = x;
} else if(opt[] == 'p' && opt[] == 'o') {
LL Answer = Poi_A(, n, , js);
cout << Answer + Num[js] << "\n";
Sec_G(, n, , js, js, - Answer);
js --;
} else {
int k = read(), x = read();
Sec_G(, n, , , k, x);
}
}
return ;
}
hihoCoder 2 * problem的更多相关文章
- hihoCoder 1430 : A Boring Problem(一琐繁题)
hihoCoder #1430 : A Boring Problem(一琐繁题) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 As a ...
- 【hihocoder 1424】 Asa's Chess Problem(有源汇上下界网络流)
UVALive-7670 ICPC北京2016-C题 hihocoder 1424 题意 有个 \(N\times N\) 的棋盘,告诉你每个格子黑色(1)或白色(0),以及每对能相互交换的同行或同列 ...
- hihocoder #1260 : String Problem I
题目链接 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 我们有一个字符串集合S,其中有N个两两不同的字符串. 还有M个询问,每个询问给出一个字符串w,求有多少S中的 ...
- hihoCoder 1261 String Problem II
时间限制:50000ms 单点时限:5000ms 内存限制:512MB 描写叙述 我们有一个字符串集合S,当中有N个两两不同的字符串.还有M个询问,每一个询问都会先给出一个字符串w,你须要回答下面三个 ...
- 【最短路】【Heap-dijkstra】hihocoder 1587 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 J. Typist's Problem
题意:给你一个串,仅含有a~g,且每个字母只出现最多一次.和一个光标初始位置,以及一个目标串,问你最少要多少的代价变化成目标串. 有五种操作:在光标前添加一个未出现过的字母,代价1. 删除光标前或者光 ...
- 【hihoCoder 1454】【hiho挑战赛25】【坑】Rikka with Tree II
http://hihocoder.com/problemset/problem/1454 调了好长时间,谜之WA... 等我以后学好dp再来看为什么吧,先弃坑(╯‵□′)╯︵┻━┻ #include& ...
- 【hihocoder#1413】Rikka with String 后缀自动机 + 差分
搞了一上午+接近一下午这个题,然后被屠了个稀烂,默默仰慕一晚上学会SAM的以及半天4道SAM的hxy大爷. 题目链接:http://hihocoder.com/problemset/problem/1 ...
- 【hihoCoder】1148:2月29日
问题:http://hihocoder.com/problemset/problem/1148 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 思路: 1. 将问题转换成求两个日 ...
- 【hihoCoder】1288 : Font Size
题目:http://hihocoder.com/problemset/problem/1288 手机屏幕大小为 W(宽) * H(长),一篇文章有N段,每段有ai个字,要求使得该文章占用的页数不超过P ...
随机推荐
- STM32中引脚复用说明
端口复用的定义 STM32有许多的内置外设(如串口.ADC.DCA等等),这些外设的外部引脚都是和GPIO复用的.也就是说,一个GPIO如果可以复用为内置外设的功能引脚,那么当这个GPIO作为内置外设 ...
- Scratch编程:画多边形(八)
“ 上节课的内容全部掌握了吗?反复练习了没有,编程最好的学习方法就是练习.练习.再练习.一定要记得多动手.多动脑筋哦~~” 01 — 游戏介绍 这节我们将实现:程序提示用户输入数据,然后根据用户的输入 ...
- 整合MyBatis
配置数据源相关属性(见前一章节 DataSource配置) 引入依赖 <dependency> <groupId>org.mybatis.spring.boot</gro ...
- iOS - 回顾总结Runtime原理及使用
runtime简介 因为Objc是一门动态语言,所以它总是想办法把一些决定工作从编译连接推迟到运行时.也就是说只有编译器是不够的,还需要一个运行时系统 (runtime system) 来执行编译后的 ...
- ol li 兼容
ol 标签在 chrome 60 和 safari12 缩进不一样. 因为序号距离copy距离不一样,导致显示不一样.解决办法. list-style-position: inside;text-in ...
- 13 个 JS 数组精简技巧
来自 https://juejin.im/post/5db62f1bf265da4d560906ab 侵删 数组是 JS 最常见的一种数据结构,咱们在开发中也经常用到,在这篇文章中,提供一些小技巧,帮 ...
- jquery判断数据类型源码解读
var class2type = {}; ("Boolean Number String Function Array Date RegExp Object Error").spl ...
- Eclipse 交叉编译环境
创建空工程 添加交叉编译环境 添加工程文件 如需修改交叉编译环境 Cross GCC:使用交叉编译命令编译,需要自己指定 MinGW GCC:使用make命令编译,需要有Makefile Make T ...
- MySQL binlog反解析
反解析delete语句 背景:delete table忘了加条件导致整张表被删除 恢复方式:直接从binlog里反解析delete语句为insert进行恢复 导出删指定表的DELETE语句: # my ...
- 静态链接 VS 动态链接
什么是链接? 链接其实就是连接的意思,将所有相关的东西连接起来. 简单理解静态连接和动态链接: 静态链接:编译时完成链接 动态链接:程序运行起来后,根据需求再去链接,这就是动态链接 静态链接 什么是静 ...