A - Absolute

留坑。

B - Counting Permutations

留坑。

C - Cover

留坑。

D - Game

puts("Yes")

 #include <bits/stdc++.h>

 using namespace std;

 int n;

 int main()
{
while (scanf("%d", &n) != EOF)
{
puts("Yes");
}
return ;
}

E - Hack It

留坑。

F - Matrix

留坑。

G - Naive Operations

题意:给出$b[]$数组,里面是$1-n$ 的全排列,两种操作,一个区间+1,一个是区间求$\sum_{i = l} ^ {i = r} \lfloor \frac{a_i}{b_i} \rfloor$

思路:维护一个Min 表示这个区间内需要的最少的进位,如果有进位,就更新到底,如果没有进位就区间更新

 #include <bits/stdc++.h>

 using namespace std;

 #define N 100010
#define ll long long ll arr[N]; struct node
{
int l, r;
ll Min, lazy, sum, v;
inline node() {}
inline node(int _l, int _r)
{
l = _l; r = _r;
Min = , lazy = , sum = , v = ;
}
}tree[N << ]; inline void pushup(int id)
{
tree[id].Min = min(tree[id << ].Min, tree[id << | ].Min);
tree[id].sum = tree[id << ].sum + tree[id << | ].sum;
} inline void pushdown(int id)
{
if(tree[id].l >= tree[id].r) return;
if(tree[id].lazy)
{
tree[id << ].lazy += tree[id].lazy;
tree[id << | ].lazy += tree[id].lazy;
tree[id << ].Min -= tree[id].lazy;
tree[id << | ].Min -= tree[id].lazy;
tree[id].lazy = ;
}
} inline void build(int id, int l, int r)
{
tree[id] = node(l, r);
if (l == r)
{
tree[id].v = arr[l];
tree[id].Min = arr[l];
return;
}
int mid = (l + r) >> ;
build(id << , l, mid);
build(id << | , mid + , r);
pushup(id);
} inline void update(int id, int l, int r)
{
if (tree[id].l == l && tree[id].r == r && tree[id].Min > )
{
tree[id].lazy++;
tree[id].Min--;
return ;
}
if(tree[id].l == tree[id].r && tree[id].Min == )
{
tree[id].Min = tree[id].v;
tree[id].sum++;
return ;
}
pushdown(id);
int mid = (tree[id].l + tree[id].r) >> ;
if (r <= mid) update(id << , l, r);
else if (l > mid) update(id << | , l, r);
else
{
update(id << , l, mid);
update(id << | , mid + , r);
}
pushup(id);
} ll anssum; inline void query(int id, int l, int r)
{
if (tree[id].l >= l && tree[id].r <= r)
{
anssum += tree[id].sum;
return;
}
pushdown(id);
int mid = (tree[id].l + tree[id].r) >> ;
if (l <= mid) query(id << , l, r);
if (r > mid) query(id << | , l, r);
pushup(id);
} int n, m;
char str[];
int l, r; int main()
{
while(~scanf("%d %d", &n, &m))
{
for(int i = ; i <= n; ++i) scanf("%lld", arr + i);
build(, , n);
for(int i = ; i <= m; ++i)
{
scanf("%s", str);
if(str[] == 'a')
{
scanf("%d %d", &l, &r);
update(, l, r);
}
else
{
scanf("%d %d", &l, &r);
anssum = ;
query(, l, r);
printf("%lld\n", anssum);
}
}
}
return ;
}

H - Odd Shops

留坑。

I - Segment

留坑。

J - Swaps and Inversions

水。逆序对的意义就是每次只能交换相邻两个,最少的交换次数

 #include <bits/stdc++.h>

 using namespace std;

 #define ll long long
#define N 100010 int n, m; ll x, y;
int arr[N], brr[N];
int a[N]; inline void Init()
{
for (int i = ; i <= n; ++i) brr[i] = arr[i];
sort(brr + , brr + + n);
m = unique(brr + , brr + + n) - brr - ;
} inline int Get(int x)
{
return lower_bound(brr + , brr + + m, x) - brr;
} inline int lowbit(int x)
{
return x & (-x);
} inline void update(int x, int val)
{
for (int i = x; i <= n; i += lowbit(i))
a[i] += val;
} inline int query(int x)
{
int res = ;
for (int i = x; i > ; i -= lowbit(i))
res += a[i];
return res;
} int main()
{
while (scanf("%d%lld%lld", &n, &x, &y) != EOF)
{
for (int i = ; i <= n; ++i) scanf("%d", arr + i);
Init(); memset(a, , sizeof a);
for (int i = ; i <= n; ++i) arr[i] = Get(arr[i]);
ll ans = ;
for (int i = ; i <= n; ++i)
{
// ans += i - 1 - query(arr[i] - 1);
// printf("%d %d\n", arr[i], query(arr[i] - 1));
update(arr[i], );
ans += i - query(arr[i]);
// cout << arr[i] << " " << query(arr[i]) << endl;
}
printf("%lld\n", min(ans * x, ans * y));
}
return ;
}

2018 Multi-University Training Contest 2 Solution的更多相关文章

  1. 2018 Multi-University Training Contest 1 Solution

    A - Maximum Multiple 题意:给出一个n 找x, y, z 使得$n = x + y +z$ 并且 $n \equiv 0 \pmod x, n \equiv 0 \pmod y, ...

  2. 2018 Multi-University Training Contest 3 Solution

    A - Problem A. Ascending Rating 题意:给出n个数,给出区间长度m.对于每个区间,初始值的max为0,cnt为0.遇到一个a[i] > ans, 更新ans并且cn ...

  3. 2018 Multi-University Training Contest 4 Solution

    A - Problem A. Integers Exhibition 留坑. B - Problem B. Harvest of Apples 题意:计算$\sum_{i = 0}^{i = m}C( ...

  4. 2018 Multi-University Training Contest 5 Solution

    A - Always Online Unsolved. B - Beautiful Now Solved. 题意: 给出一个n, k  每次可以将n这个数字上的某两位交换,最多交换k次,求交换后的最大 ...

  5. 2018 Multi-University Training Contest 6 Solution

    A - oval-and-rectangle 题意:给出一个椭圆的a 和 b,在$[0, b]中随机选择c$ 使得四个顶点在椭圆上构成一个矩形,求矩形周长期望 思路:求出每种矩形的周长,除以b(积分) ...

  6. 2018 Multi-University Training Contest 7 Solution

    A - Age of Moyu 题意:给出一张图,从1走到n,如果相邻两次走的边的权值不同,花费+1, 否则花费相同,求最小花费 思路:用set记录有当前点的最小花费有多少种方案到达,然后最短路 #i ...

  7. 2018 Multi-University Training Contest 8 Solution

    A - Character Encoding 题意:用m个$0-n-1$的数去构成k,求方案数 思路:当没有0-n-1这个条件是答案为C(k+m-1, m-1),减去有大于的关于n的情况,当有i个n时 ...

  8. 2018 Multi-University Training Contest 9 Solution

    A - Rikka with Nash Equilibrium 题意:构造一个$n * m$的矩阵,使得$[1, n * m]$ 中每个数只出现一次,并且纳什均衡只出现一次. 思路:从大到小的放置,每 ...

  9. 2018 Multi-University Training Contest 10 Solution

    A - Problem A.Alkane 留坑. B - Problem B. Beads 留坑. C - Problem C. Calculate 留坑. D - Problem D. Permut ...

随机推荐

  1. ios button标记

    在写项目的时候,for循环创建多个button,在需要设置背景图片和,需要标记所选中的button的需求, 在这里提供两种方法: 一: 1:把for循环创建的button全部装到一个新建的数组中,把他 ...

  2. sql 链接符 ||

  3. linux 开机启动nginx

    这里使用的是编写shell脚本的方式来处理 vi /etc/init.d/nginx  (输入下面的代码) #!/bin/bash# nginx Startup script for the Ngin ...

  4. 如何让IOS中的文本实现3D效果

    本转载至 http://bbs.aliyun.com/read/181991.html?spm=5176.7114037.1996646101.25.p0So7c&pos=9       zh ...

  5. NSData 方法

    /****************Immutable Data****************/ @interface NSData : NSObject <NSCopying, NSMutab ...

  6. MQTT的学习研究(十四) MQTT moquette 的 Callback API 消息发布订阅的实现

    在moquette-mqtt中提供了回调callback模式的发布和订阅但是在订阅之后没有发现有消息接收的方法,参看moquette-mqtt中Block,Future式的发布订阅基础是callbac ...

  7. LeetCode——Generate Parentheses

    Description: Given n pairs of parentheses, write a function to generate all combinations of well-for ...

  8. jQuery中的ajax用法案例

    什么是 AJAX? AJAX = 异步 JavaScript 和 XML(Asynchronous JavaScript and XML). 简短地说,在不重载整个网页的情况下,AJAX 通过后台加载 ...

  9. 【BZOJ1901】Zju2112 Dynamic Rankings 主席树+树状数组

    [BZOJ1901]Zju2112 Dynamic Rankings Description 给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i,j ...

  10. Apache的配置详解,最好的Apache配置文档

    http://blog.csdn.net/apple_llb/article/details/50253889 Apache的配置由httpd.conf文件配置,因此下面的配置指令都是在httpd.c ...