天天爱跑步

lca + 树上差分

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std; const int N = 3e5 + , M = 3e5 + ;
int n, m, ans[N], offset;
int ecnt, adj[N], go[M << ], nxt[M << ];
int w[N], dep[N], cnt[N << ], fa[N][];
struct node{
int val, delta;
node(){}
node(int a, int b):val(a), delta(b){}
};
vector<node> tag[N]; inline void addEdge(int u, int v){
nxt[++ecnt] = adj[u], adj[u] = ecnt, go[ecnt] = v;
nxt[++ecnt] = adj[v], adj[v] = ecnt, go[ecnt] = u;
} inline int getLca(int u, int v){
if(dep[u] < dep[v]) swap(u, v);
int delta = dep[u] - dep[v];
for(int i = ; i >= ; i--)
if(( << i) & delta) u = fa[u][i];
if(u == v) return u;
for(int i = ; i >= ; i--)
if(fa[u][i] != fa[v][i])
u = fa[u][i], v = fa[v][i];
return fa[u][];
} inline void dfs(int u, int f){
fa[u][] = f;
for(int i = ; i <= ; i++)
fa[u][i] = fa[fa[u][i - ]][i - ];
for(int e = adj[u], v; e; e = nxt[e]){
v = go[e];
if(v != f){
dep[v] = dep[u] + ;
dfs(v, u);
}
}
} inline void solve(int u){
int cur = cnt[dep[u] + w[u]] + cnt[w[u] - dep[u] + offset];
for(int i = ; i < tag[u].size(); i++)
cnt[tag[u][i].val] += tag[u][i].delta;
for(int e = adj[u], v; e; e = nxt[e]){
if((v = go[e]) == fa[u][]) continue;
solve(v);
}
ans[u] = cnt[dep[u] + w[u]] + cnt[w[u] - dep[u] + offset] - cur;
} inline int read(){
int i = , f = ; char ch = getchar();
for(; (ch < '' || ch > '') && ch != '-'; ch = getchar());
if(ch == '-') f = -, ch = getchar();
for(; ch >= '' && ch <= ''; ch = getchar())
i = (i << ) + (i << ) + (ch - '');
return i * f;
} inline void wr(int x){
if(x < ) putchar('-'), x = -x;
if(x > ) wr(x / );
putchar(x % + '');
} int main(){
n = read(), m = read(), offset = * n + ;
for(int i = ; i < n; i++){
int x = read(), y = read();
addEdge(x, y);
}
dfs(, );
for(int i = ; i <= n; i++) w[i] = read();
for(int i = ; i <= m; i++){
int s = read(), t = read(), lca = getLca(s, t);
tag[s].push_back(node(dep[s], ));
tag[t].push_back(node(dep[s] - * dep[lca] + offset, ));
tag[fa[lca][]].push_back(node(dep[s], -));
tag[lca].push_back(node(dep[s] - * dep[lca] + offset, -));
}
solve();
for(int i = ; i <= n; i++) wr(ans[i]), putchar(' ');
return ;
}

借教室

二分法

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
using namespace std; const int N = 1e6 + ;
int n, m, a[N], f[N], s[N], t[N], d[N], ans; inline int read(){
int i = , f = ; char ch = getchar();
for(; (ch < '' || ch > '') && ch != '-'; ch = getchar());
if(ch == '-') f = -, ch = getchar();
for(; ch >= '' && ch <= ''; ch = getchar())
i = (i << ) + (i << ) + (ch - '');
return i * f;
} inline void wr(int x){
if(x < ) putchar('-'), x = -x;
if(x > ) wr(x / );
putchar(x % + '');
} inline bool check(int mid){
int sum = ;
memset(f, , sizeof f);
for(int i = ; i <= mid; i++)
f[s[i]] += d[i], f[t[i] + ] -= d[i];
for(int i = ; i <= n; i++){
sum += f[i];
if(sum > a[i]) return false;
}
return true;
} int main(){
n = read(), m = read();
for(int i = ; i <= n; i++) a[i] = read();
for(int i = ; i <= m; i++) d[i] = read(), s[i] = read(), t[i] = read();
int l = , r = m;
while(l <= r){
int mid = l + r >> ;
if(check(mid)) l = mid + ;
else ans = mid, r = mid - ;
}
if(ans == ) putchar('');
else{
wr(-), putchar('\n');
wr(ans);
}
return ;
}

线段树

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std; const int N = 1e6 + , oo = 0x3f3f3f3f;
int n, m, minn[N * ], a[N], tag[N * ]; inline int read(){
int i = , f = ; char ch = getchar();
for(; (ch < '' || ch > '') && ch != '-'; ch = getchar());
if(ch == '-') f = -, ch = getchar();
for(; ch >= '' && ch <= ''; ch = getchar())
i = (i << ) + (i << ) + (ch - '');
return i * f;
} inline void wr(int x){
if(x < ) putchar('-'), x = -x;
if(x > ) wr(x / );
putchar(x % + '');
} inline void build(int k, int l, int r){
if(l == r){
minn[k] = a[l];
return;
}
int mid = l + r >> , lc = k << , rc = k << | ;
build(lc, l, mid);
build(rc, mid + , r);
minn[k] = min(minn[lc], minn[rc]);
} inline void minuss(int k, int v){
minn[k] -= v;
tag[k] += v;
} inline void pushDown(int k){
if(tag[k]){
if(minn[k << ] != -) minuss(k << , tag[k]);
if(minn[k << | ] != -) minuss(k << | , tag[k]);
tag[k] = ;
}
} inline void modify(int k, int l, int r, int x, int y, int v){
if(x <= l && r <= y){
minuss(k, v);
return;
}
pushDown(k);
int mid = l + r >> , lc = k << , rc = k << | , ret = oo;
if(x <= mid) modify(lc, l, mid, x, y, v);
if(y > mid) modify(rc, mid + , r, x, y, v);
minn[k] = min(minn[lc], minn[rc]);
} inline int query(int k, int l, int r, int x, int y){
if(x <= l && r <= y) return minn[k];
pushDown(k);
int mid = l + r >> , lc = k << , rc = k << | , ret = oo;
if(x <= mid) ret = min(ret, query(lc, l, mid, x, y));
if(y > mid) ret = min(ret, query(rc, mid + , r, x, y));
return ret;
} int main(){
n = read(), m = read();
for(int i = ; i <= n; i++) a[i] = read();
memset(minn, -, sizeof tag);
build(, , n);
for(int i = ; i <= m; i++){
int d = read(), s = read(), t = read();
if(s > t) swap(s, t);
// cout<<s<<" "<<t<<" "<<query(1, 1, n, s, t)<<"!!!"<<endl;
if(query(, , n, s, t) < d){
wr(-), putchar('\n'), wr(i);
return ;
}
modify(, , n, s, t, d);
}
wr();
return ;
}

积木大赛

简单分析

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std; const int N = 1e5 + ;
int n, ans, last; int main(){
cin >> n;
for(int i = ; i <= n; i++){
int tmp; cin >> tmp;
if(tmp - last > ) ans += tmp - last;
last = tmp;
}
cout << ans;
return ;
}

Vigenère密码

简单分析 + 模拟

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std; int klen, slen, key[];
char k[], s[], t[]; int main(){
cin >> k >> s;
klen = strlen(k), slen = strlen(s);
for(int i = ; i < klen; i++){
if('a' <= k[i] && k[i] <= 'z')
key[i] = k[i] - 'a';
else key[i] = k[i] - 'A';
}
for(int i = ; i < slen; i++){
if('a' <= s[i] && s[i] <= 'z'){
t[i] = s[i] - key[i % (klen)];
while(t[i] < 'a') t[i] += ;
}
else if('A' <= s[i] && s[i] <= 'Z'){
t[i] = s[i] - key[i % (klen)];
while(t[i] < 'A') t[i] += ;
}
else continue;
putchar(t[i]);
}
return ;
}

花匠

动态规划 + 树状数组优化

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std; const int N = 1e5 + , H = 1e6 + ;
int n, h[N], f[N], g[N], maxh, maxxF[H], maxxG[H], ans; inline int read(){
int i = , f = ; char ch = getchar();
for(; (ch < '' || ch > '') && ch != '-'; ch = getchar());
if(ch == '-') f = -, ch = getchar();
for(; ch >= '' && ch <= ''; ch = getchar())
i = (i << ) + (i << ) + (ch - '');
return i * f;
} inline void wr(int x){
if(x < ) putchar('-'), x = -x;
if(x > ) wr(x / );
putchar(x % + '');
} inline void uptF(int x, int v){
for(int i = x; i <= maxh; i += (i&(-i)))
maxxF[i] = max(maxxF[i], v);
} inline void uptG(int x, int v){
for(int i = x; i <= maxh; i += (i&(-i)))
maxxG[i] = max(maxxG[i], v);
} inline int queryF(int x){
int ret = ;
for(int i = x; i > ; i-=(i&-i))
ret = max(maxxF[i], ret);
return ret;
} inline int queryG(int x){
int ret = ;
for(int i = x; i > ; i-=(i&-i))
ret = max(ret, maxxG[i]);
return ret;
} int main(){
n = read();
for(int i = ; i <= n; i++) h[i] = read() + , maxh = max(maxh, h[i]);
maxh += ;
for(int i = ; i <= n; i++){
f[i] = max(queryG(h[i] - ) + , f[i]);
g[i] = max(queryF(maxh - h[i] - ) + , g[i]);
uptF(maxh - h[i], f[i]);
uptG(h[i], g[i]);
ans = max(ans, max(f[i], g[i]));
}
wr(ans);
return ;
}

noip刷题记录 20170818的更多相关文章

  1. noip刷题记录 20170823

    独木桥 怎么说呢 #include<iostream> #include<cstdio> #include<algorithm> using namespace s ...

  2. PE刷题记录

    PE刷题记录 PE60 / 20%dif 这道题比较坑爹. 所有可以相连的素数可以构成一张图,建出这张图,在其中找它的大小为5的团.注意上界的估算,大概在1W以内.1W内有1229个素数,处理出这些素 ...

  3. leetcode刷题记录--js

    leetcode刷题记录 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但 ...

  4. Leetcode刷题记录(python3)

    Leetcode刷题记录(python3) 顺序刷题 1~5 ---1.两数之和 ---2.两数相加 ---3. 无重复字符的最长子串 ---4.寻找两个有序数组的中位数 ---5.最长回文子串 6- ...

  5. 刷题记录:[HarekazeCTF2019]encode_and_encode

    目录 刷题记录:[HarekazeCTF2019]encode_and_encode 一.知识点 JSON转义字符绕过 php伪协议 刷题记录:[HarekazeCTF2019]encode_and_ ...

  6. 刷题记录:[De1CTF 2019]Giftbox && Comment

    目录 刷题记录:[De1CTF 2019]Giftbox && Comment 一.知识点 1.sql注入 && totp 2.RCE 3.源码泄露 4.敏感文件读取 ...

  7. 刷题记录:[强网杯 2019]Upload

    目录 刷题记录:[强网杯 2019]Upload 一.知识点 1.源码泄露 2.php反序列化 刷题记录:[强网杯 2019]Upload 题目复现链接:https://buuoj.cn/challe ...

  8. 刷题记录:[XNUCA2019Qualifier]EasyPHP

    目录 刷题记录:[XNUCA2019Qualifier]EasyPHP 解法一 1.error_log结合log_errors自定义错误日志 2.include_path设置包含路径 3.php_va ...

  9. 刷题记录:[DDCTF 2019]homebrew event loop

    目录 刷题记录:[DDCTF 2019]homebrew event loop 知识点 1.逻辑漏洞 2.flask session解密 总结 刷题记录:[DDCTF 2019]homebrew ev ...

随机推荐

  1. [D3] Build a Line Chart with D3 v4

    Line charts are often used to plot temporal data, like a stock price over time. In this lesson we’ll ...

  2. iOS ERROR: unable to get the receiver data from the DB 解决方式

    这个错误通常发生在iOS7其中,可能是缓存的导致的问题. 解决步骤: 右击Finder,选择 Go to Folder 复制上:"~/Library/Application Support/ ...

  3. Valgrind的用法

    Valgrind是执行在Linux上一套基于仿真技术的程序调试和分析工具,它包括一个内核──一个软件合成的CPU,和一系列的小工具,每一个工具都能够完毕一项任务──调试.分析,或測试等. Valgri ...

  4. 微信支付v2开发(2) 微信支付账号体系

    本文介绍微信支付账号体系各参数. 商户在微信公众平台提交申请资料以及银行账户资料,资料审核通过并签约后,可以获得表6-4所示帐户(包含财付通的相关支付资金账户),用于公众帐号支付. 帐号 作用 app ...

  5. HibernateCRUD基础框架(1)-实体类

    HibernateCRUD基础框架包括3篇文章,主要讲述整个CRUD基础框架的思路. 第1篇:讲述最基本的实体类,这些实体类是对SQL语言中的一些概念的封装. 第2篇:在这些实体类的基础上,开发一个& ...

  6. Spring拦截器和Servlet过滤器区别

    http://blog.csdn.net/chenleixing/article/details/44573495

  7. C语言创建删不掉的目录

    上一篇博客写了一个杀不死的进程,如今再写一个删不掉的目录(文件同理),所谓删不掉不是真的删不掉而是删掉后立即又一次创建. 代码例如以下: #include <stdio.h> #inclu ...

  8. 【Codeforces Round #440 (Div. 2) C】 Maximum splitting

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 肯定用尽量多的4最好. 然后对4取模的结果 为0,1,2,3分类讨论即可 [代码] #include <bits/stdc++ ...

  9. [Angular] HostListener Method Arguments - Blocking Default Keyboard Behavior

    We are going to see how to using method arguments for @HostListener. First, we can use HostListener ...

  10. 解决java中ZipFile解压缩时候的中文路径和乱码问题

    JAVA中对jar文件或zip文件解压的时候,能够使用JDK内置的API:JarFile和ZipFile,在windows下解压这2种格式文件的时候,常常报下面错误: Exception in thr ...