A.Alyona and copybooks

Problems: 给你一个数n和代价分别为a, b, c、数量不限的1, 2, 3,求将n凑成4的倍数的最小代价

Analysis:

  cj:取个模随便凑一凑就好

Tags: Implementation

 #define PRON "pa"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; inline ll _min(ll a, ll b, ll c){
return min(a, min(b, c));
} int main(){
ll n, a, b, c;
cin >> n >> a >> b >> c; ll r = n % , ans = ;
if (r == )
ans = _min( * a, a + b, c);
if (r == )
ans = _min( * a, b, c * );
if (r == )
ans = _min(a, b * + c, c * ); cout << ans;
}

code by cj

B.Alyona and flowers

Problems: 一个数列,每次操作选择一个区间[l, r];若a[i]被选择了b[i]次,则Alyona的幸福值增加a[i] * b[i];保留一些操作使得最后幸福值最高。

Analysis:

  cj:对于每次操作,对于幸福值的贡献是sum{a[l], a[l + 1], ... , a[r]},只要贡献是正的的操作就保留

Tags: Implementation

 #define PRON "pb"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll; const int maxn = + ; int n, m, a[maxn]; int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif cin >> n >> m;
for (int i = ; i <= n; i ++)
cin >> a[i]; int ans = , temp, l, r;
while (m --){
cin >> l >> r; temp = ;
for (int i = l; i <= r; i ++)
temp += a[i];
if (temp > )
ans += temp;
} cout << ans << endl;
}

code by cj

C.Alyona and mex

Problems: 给定m个区间,构造一个长度为n的数列,使得每个区间的mex的最小值最大。

Analysis:

  cj:首先这个mex的最小值的最大值显然是min_mex = min{r[i] - l[i] + 1};最简单的构造办法就是用{1, 2, 3 ..., min_mex - 1}来填充这个数列。

Tags: Constructive Algorithms

 #define PRON "pc"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll; const int maxn = 2e5 + ; int n, m;
pair<int, int> a[maxn]; bool cmp(pair<int, int> A, pair<int, int> B){
return A.second - A.first < B.second - B.first;
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif cin >> n >> m; int mex = inf;
for (int i = ; i < m; i ++){
cin >> a[i].first >> a[i].second;
mex = min(mex, + a[i].second - a[i].first);
} cout << mex << endl; for (int i = ; i <= n; i ++)
cout << i % mex << " ";
cout << endl;
}

code by cj

D. Alyona and a tree

Problems: 一棵以1为根的树和各边的长度,给定每个点有一个值a。当dis(v, u) < a[u]并且u在v的子树中就认为u控制了v。问每个点控制了多少个点。

Analysis:

  cj:dis(v, u) < a[u]可以变成d[u] - d[v] < a[u],即:d[v] > d[u] - a[u],其中d[i]表示dis(1, i)。用vector来维护dfs序,显然d是递增的,所以每次二分查找这个v,使得v以上的所以点都不能控制u,以下的点都可以控制u。用数组c来记录答案,初值赋1,装作能被控制的样子,对于一个点x,c[x] = sum{c[i]},i是x的子树中的点。所以当查找到v之后,将这条链上v的亲爸爸的c减1,这样的话更新答案的时候就不会加上这个点及其以上的点。最后输出c[i] - 1即可。

Tags: binary search, dfs

 #define PRON "pd"
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll; const int maxn = 2e5 + ; struct Edge {
int to, d;
Edge * next;
} e[maxn], * head[maxn]; vector<int> q;
vector<ll> dis;
int n, ne = , a[maxn], c[maxn];
ll d[maxn]; inline void add_edge(int f, int to, int d){
e[ne].to = to, e[ne].d = d;
e[ne].next = head[f];
head[f] = e + ne ++;
} void dfs(int u){
for (Edge * p = head[u]; p; p = p -> next){
d[p -> to] = d[u] + (ll)p -> d;
dfs(p -> to);
}
} void solve(int u){
c[u] = ;
q.push_back(u);
dis.push_back(d[u]); int anc = lower_bound(dis.begin(), dis.end(), d[u] - (ll)a[u]) - dis.begin(); if (anc >= )
c[q[anc - ]] --; for (Edge * p = head[u]; p; p = p -> next){
solve(p -> to);
c[u] += c[p -> to];
} q.pop_back();
dis.pop_back();
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif scanf("%d", &n);
for (int i = ; i <= n; i ++)
scanf("%d", &a[i]); int fa, dis;
for (int i = ; i <= n; i ++){
scanf("%d %d", &fa, &dis);
add_edge(fa, i, dis);
} d[] = ;
dfs();
solve(); for (int i = ; i <= n; i ++)
printf("%d ", c[i] - );
printf("\n");
}

code by cj

E. Alyona and towers

Problems:给一个数列a,每次操作让[l, r]上的数增加的,每次操作后求满足al < al + 1 < al + 2 < ... < ak > ak + 1 > ak + 2 > ... > ar的最大区间长度。

Analysis:

  cj:把数列换成差,这样的话每次区间修改操作,因为区间中的差是不变的,只有diff(arr[l - 1], arr[l])增加了d,diff(arr[r], arr[r + 1])减少了d,所以就变成了修改两个点的操作。用线段树维护一下就好了。不过要注意一下int要爆炸...并且要特判n = 1的情况。

Tags: Data structure

 #define PRON "740e"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
#define ls root << 1
#define rs root << 1 | 1
#define mid ((l + r) >> 1)
#ifdef UNIX
#define LL "%lld"
#else
#define LL "%I64d"
#endif
using namespace std;
typedef long long ll; const int maxn = 3e5 + ; struct node {
int lans, rans, ans;
} t[maxn << ]; int n, m;
ll arr[maxn], a[maxn]; void push_up(int l, int r, int root){
t[root].ans = max(t[ls].ans, t[rs].ans);
t[root].lans = t[ls].lans;
t[root].rans = t[rs].rans; if ((a[mid] > && a[mid + ] != ) || (a[mid] < && a[mid + ] < )){
t[root].ans = max(t[root].ans, t[ls].rans + t[rs].lans);
if (mid - l + == t[ls].lans)
t[root].lans = t[ls].lans + t[rs].lans;
if (r - mid == t[rs].rans)
t[root].rans = t[ls].rans + t[rs].rans;
}
} void build_tree(int l, int r, int root){
if (l == r){
t[root].ans = t[root].lans = t[root].rans = a[l] ? : ;
return;
} build_tree(l, mid, ls);
build_tree(mid + , r, rs); push_up(l, r, root);
} void update(int l, int r, int pos, int root){
if (l == r && l == pos){
t[root].ans = t[root].lans = t[root].rans = a[l] ? : ;
return;
} if (l <= pos && pos <= mid)
update(l, mid, pos, ls);
else
update(mid + , r, pos, rs); push_up(l, r, root);
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif scanf("%d", &n);
for (int i = ; i < n; i ++){
scanf(LL, &arr[i]);
if (i)
a[i] = arr[i] - arr[i - ];
} if (n != )
build_tree(, n - , ); int l, r, d;
scanf("%d", &m);
while (m --){
scanf("%d %d %d", &l, &r, &d);
if (n == ){
printf("1\n");
continue;
}
if (l > ){
a[l - ] += d;
update(, n - , l - , );
}
if (r < n){
a[r] -= d;
update(, n - , r, );
} printf("%d\n", t[].ans + );
}
}

code by cj

CODEFORCES ROUND #740 ANALYSES BY TEAM:RED & BLACK的更多相关文章

  1. CODEFORCES ROUND #761 ANALYSES BY TEAM:RED & BLACK

    A. Dasha and Stairs Problems: 一个按照1,2,3……编号的楼梯,给定踩过的编号为奇数奇数和偶数的楼梯数量a和b,问是否可以有区间[l, r]符合奇数编号有a个,偶数编号有 ...

  2. Codeforces Round #233 (Div. 2) B. Red and Blue Balls

    #include <iostream> #include <string> using namespace std; int main(){ int n; cin >&g ...

  3. Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black

    A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...

  4. Codeforces Round #740 Div. 2

    题目跳转链接 A. Simply Strange Sort 题意 定义一个函数\(f_{i}\) : 如果\(a_i \ge a_{i+1}\) swap(\(a_i\) \(a_{i+1}\)) 定 ...

  5. Codeforces Round #486 (Div. 3) A. Diverse Team

    Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. CodeForces Round

    CodeForces Round 199 Div2   完了,这次做扯了,做的时候有点发烧,居然只做出来一道题,差点被绿. My submissions     # When Who Problem ...

  8. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  9. Codeforces Round #485 (Div. 2)

    Codeforces Round #485 (Div. 2) https://codeforces.com/contest/987 A #include<bits/stdc++.h> us ...

随机推荐

  1. 限时订单实现方案(DelayQueue、ActiveMq)

    原文链接:http://www.studyshare.cn/blog-front/blog/details/1132 一.在各种电商网站下订单后会保留一个时间段,时间段内未支付则自动将订单状态设置为已 ...

  2. 如何引入.graphql文件并优雅的使用fragment

    你还在为代码中放入长长的模版字符串所苦恼吗,如下图代码片段: ps:这个是grqphql client在nodejs后端项目的实践,如果你是在前端使用graphql,并使用了webpack,那么这些问 ...

  3. <Dare To Dream>团队项目用户验收评审

    实验十二 团队作业8—团队项目用户验收评审 任务1:团队作业Beta冲刺 Beta冲刺第一天:http://www.cnblogs.com/Dare-To-Dream/p/9226994.html B ...

  4. sql两表连接

    一直以来认为exists比in效率高的说法是不准确的.如果查询的两个表大小相当,那么用in和exists差别不大.如果两个表中一个较小,一个是大表,则子查询表大的用exists,子查询表小的用in:例 ...

  5. oracl遇到的问题

    使用oracl数据库用  ALTER TABLE Students ADD CONSTRAINT PRINF_NAME_UNIQUE UNIQUE (sname) 添加唯一性约束,出现问题,报错为:a ...

  6. vue 下拉刷新 上拉加载(vue-scroller)

    <template> <div class="wdRecordCon"> <x-header :left-options="{backTex ...

  7. dubbo常见面试问题(二)

    1.什么是Dubbo? Duubbo是一个RPC远程调用框架, 分布式服务治理框架 2.什么是Dubbo服务治理? 服务与服务之间会有很多个Url.依赖关系.负载均衡.容错.自动注册服务 3.Dubb ...

  8. CentOS7搭建Zookeeper环境

    Linux下安装JDK 1.检查一下系统中的jdk版本 [root@localhost software]# java -version 显示: openjdk version "1.8.0 ...

  9. CodeWarrior 10 配置Jlint初始化文件

    新建一个项目之后,飞思卡尔的仿真器的配置不如德州仪器那么简单.他需要一些配置. 当我们新建一个工程后,可以采取如下步骤配置Jlint: 1.右击工程名,选择属性. 2.在Run/Debug Setti ...

  10. Golang学习---常用库

    1. 路由库:github.com/julienschmidt/httprouter 2. mysql驱动:github.com/go-sql-driver/mysql