P3608 [USACO17JAN]Balanced Photo平衡的照片 题目描述 Farmer John is arranging his NN cows in a line to take a photo (1 \leq N \leq 100,0001≤N≤100,000). The height of the iith cow in sequence is h_ih​i​​, and the heights of all cows are distinct. As with all ph…
题目链接:https://www.luogu.org/problemnew/show/P3608 乍一看很容易想到O(N^2)的暴力. 对于每个H[i]从i~i-1找L[i]再从i+1~n找R[i],然后比较. 60分(数据够水) 但是这个思路就是很直白的模拟,让人不容易想到如何去优化. 然后我们换一个也是差不多O(N^2)的思路: 我们设法把H[i]所对应的第k大的k求出来. for example: H 34 6 23 0 5 99 2 Kth 2 4 3 7 5 1 6 那么我们就能发现,…
传送门 树状数组裸题 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 100001 using namespace std; int n, m, ans; int a[N], b[N], R[N], L[N], c[N]; inline int read() { int x = 0, f = 1; char ch = getchar…
题目链接 Solution 先离散化,然后开一个大小为 \(100000\) 的树状数组记录前面出现过的数. 然后查询 \((h[i],n]\) 即可. 还要前后各做一遍. Code #include<bits/stdc++.h> #define N 200008 #define ll long long using namespace std; void in(ll &x) { char ch=getchar();ll f=1,w=0; while(ch<'0'||ch>…
题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to narrow down the list of features shared by his cows to a list of only K different features (1 ≤ K ≤ 30). For example, cows exhibiting feature #1 might h…
P3609 [USACO17JAN]Hoof, Paper, Scissor蹄子剪刀… 题目背景 欢迎提供翻译,请直接在讨论区发帖,感谢你的贡献. 题目描述 You have probably heard of the game "Rock, Paper, Scissors". The cows like to play a similar game they call "Hoof, Paper, Scissors". The rules of "Hoof…
题目链接:https://www.luogu.com.cn/problem/P3608 方法一 用树状数组求逆序对先后扫两遍,一次从前往后,一次从后往前,算出每头奶牛左右两边比她高的数量. 最后统计一下. #include <bits/stdc++.h> using namespace std; int sum[500010], l[100010], r[100010]; int n, m, u, v, a[500010], t[500010]; int ans; inline int rea…
传送门 一道感觉比较简单的dp. 注意是要求翻转一个子序列而不是一段连续的数(被坑了很多次啊)... 看到数据范围果断开一个四维数组来dp一波. 我们显然可以用f[i][j][k][t]表示下标在[l,r]内,值域在[k,t]之间且最多只会翻转一次能够生成的最长不下降子序列. 这不就简单了吗,从[l(+1),r(-1)]转移过来就三种情况. 第一种:该区间的值可以从[l+1,r]转移过来,如果a[l]=k的话对当前区间的贡献加1. 第二种:该区间的值可以从[l,r-1]转移过来,如果a[r]=t…
题目传送门 Promotion Counting 题目描述 The cows have once again tried to form a startup company, failing to remember from past experience that cows make terrible managers! The cows, conveniently numbered 1 \ldots N1…N (1 \leq N \leq 100,0001≤N≤100,000), organ…
题目描述 After several months of rehearsal, the cows are just about ready to put on their annual dance performance; this year they are performing the famous bovine ballet "Cowpelia". The only aspect of the show that remains to be determined is the s…