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 ...
随机推荐
- 去除echarts饼状图的引导线
series: { name: "流量占比分布", type: "pie", radius: ["40%", "60%" ...
- Linux 内核错误码
#define EPERM 1 /* Operation not permitted */#define ENOENT 2 /* No such ...
- javascript基本类型和对象
JS 中分为七种内置类型,七种内置类型又分为两大类型:基本类型和对象(Object). 基本类型 null undefined boolean number string symbol 其中 JS 的 ...
- 使用Jenkins的Git Parameter插件来从远程仓库拉取指定目录的内容
更换插件安装源 系统管理---插件管理---高级---升级站点,把默认的插件下载地址换成下面这个: https://mirrors.tuna.tsinghua.edu.cn/jenkins/updat ...
- 怎样获取iframe节点的window对象
需要使用iframeElement.contentWindow; var frame = document.getElementById('theFrame'); var frameWindow = ...
- ClickOnce 部署 API 以编程方式检查应用程序更新
private void InstallUpdateSyncWithInfo() { UpdateCheckInfo info = null; if (ApplicationDeployment.Is ...
- 四、eureka服务端同步注册操作
所有文章 https://www.cnblogs.com/lay2017/p/11908715.html 正文 在eureka服务端注册服务一文中,我们提到register方法做了两件事 1)注册服务 ...
- 三:MySQL系列之SQL查询
本篇主要介绍使用SQL查询数据库的操作,包括条件查询.排序.聚合函数.分组.分页.连接查询.自关联.子查询等命令操作. 首先我们先创建一个数据库.数据表.插入字段: --------这部分在上篇以及介 ...
- 利用shell命令分析服务器日志
在没有专业日志分析系统的情况下,我们有时需要对日志进行简单的分析,下面列出一些常用的shell命令分析日志的方法,一定要收藏 1.查看有多少个ip访问 awk '{print $1}' log_f ...
- 读取xml时,报错:xml.etree.ElementTree.ParseError: no element found: line 20, column 9
读取xml时,出现报错:xml.etree.ElementTree.ParseError: no element found: line 20, column 9 原因是xml文件格式有问题,可以检查 ...