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 ...
随机推荐
- L2范数归一化概念和优势
1 归一化处理 归一化是一种数理统计中常用的数据预处理手段,在机器学习中归一化通常将数据向量每个维度的数据映射到(0,1)或(-1,1)之间的区间或者将数据向量的某个范数映射为1,归一化 ...
- 在论坛中出现的比较难的sql问题:32(row_number函数+子查询 sql循环取差值)
原文:在论坛中出现的比较难的sql问题:32(row_number函数+子查询 sql循环取差值) 所以,觉得有必要记录下来,这样以后再次碰到这类问题,也能从中获取解答的思路. sql循环取差值,该怎 ...
- NetCore.SignalR.Demo演示
项目github,点击https://github.com/wangpengzong/NetCore.SignalR.Demo 1.打开服务端Server(\SignalR.Server\bin\De ...
- git push error. ! [rejected] master -> master (non-fast-forward)
错误提示: Cheetah@xxxx MINGW64 /e/Projs/enft/data/cv_key_frame (master) $ git push To github.com:Anthony ...
- English-培训4-How do you spend your day
- 苹果APP内购客户付款成功,没收到相应虚拟产品的解决办法
一.引导用户走申请苹果的退款 1.告知用户新版本可以使用支付宝.微信支付,更划算 2.苹果可申请90天以内的退款,一般情况申请后48小时内就有反馈. 参考链接 https://jingyan.baid ...
- c# VS.NET 中的调试工具
- rhel7下安装EPEL源
1.rhel7安装aliyun下的epel源 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
- DoraBox漏洞测试环境搭建和测试过程
未完待续...
- 《Python编程:从入门到实践》第四章 操作列表 习题答案
#4.1 pizzas = ['KFC','MDL','DKS'] ''' for pizza in pizzas: print(pizza); ''' for pizza in pizzas: pr ...