F题感觉自己想的很麻烦,双指针+dp,结果最后还是多亏了wls;

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
typedef long long LL;
void slove()
{map<int,int>mp;int n,k;cin>>n>>k;for(int i=0;i<n;i++){int x;cin>>x;mp[x]++;}int ans=0,l=-1,r=-1,w=0;//ans是最大的区间长,也就是l-r的距离;for(auto it : mp){int x=it.first;int y=it.second;if(y<k)//不满足{l=-1,w=0;}else{if(x!=l+1)//有间断,连续距离置为0;w=0;w++;if(w>ans)//更新最大连续距离{r=x;//更新右端点ans=w;}l=x;}}if(r==-1)cout<<"-1"<<endl;elsecout<<r-ans+1<<" "<<r<<endl;
}
int main()
{int t;cin>>t;while(t--){slove();}return 0;
}

H一开始没看出来其实就是求逆序对= =,既然是逆序对方法就多了,注意这里的逆序对可以是一组相同的数i<j,a[i]>=a[j];
这里我用了树状数组,分治(归并排序)也可以

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long LL;
int a[N],c[N],n;
/*
抽象成统计逆序对,元素重复也算一组逆序对;
*/
struct node
{int val;int pos;
}nodes[N];
bool cmp(const node &n1,const node &n2)
{if(n1.val==n2.val)//这里加个特判,元素重复就让位置大的排在前面; return n1.pos>n2.pos;return n1.val<n2.val;
}
int lowbit(int i)
{return (-i)&i;
}
void add(int i,int v)
{for(;i<=n;i+=lowbit(i))c[i]+=v;
}
LL query(int i)
{LL res=0;for(;i>0;i-=lowbit(i))res+=c[i];return res;
}
int main()
{int t;cin>>t;while(t--){memset(a,0,sizeof a);memset(nodes,0,sizeof nodes);memset(c,0,sizeof c);cin>>n;for(int i=1;i<=n;i++){cin>>nodes[i].val;nodes[i].pos=i;}sort(nodes+1,nodes+1+n,cmp);for(int i=1;i<=n;i++)a[nodes[i].pos]=i;LL cnt=0;for(int i=1;i<=n;i++){cnt+=i-1-query(a[i]);add(a[i],1);}cout<<cnt<<endl;}return 0;
}

Codeforces Round #790 div4补题(F,H)相关推荐

  1. codeforces round 418 div2 补题 CF 814 A-E

    A An abandoned sentiment from past 水题 #include<bits/stdc++.h>using namespace std;int a[300],b[ ...

  2. codeforces round 422 div2 补题 CF 822 A-F

    A I'm bored with life 水题 #include<bits/stdc++.h> using namespace std; typedef long long int LL ...

  3. codeforces round 416 div2补题

    第一题,水题 A. Vladik and Courtes #include<bits/stdc++.h> using namespace std; int main() {long lon ...

  4. codeforces round 421 div2 补题 CF 820 A-E

    A Mister B and Book Reading  O(n)暴力即可 #include<bits/stdc++.h> using namespace std; typedef lon ...

  5. codeforces round 420 div2 补题 CF 821 A-E

    A Okabe and Future Gadget Laboratory 暴力 #include<bits/stdc++.h> using namespace std; typedef l ...

  6. Codeforces Round #797 (Div. 3)无F

    Codeforces Round #797 (Div. 3)无F 这打的也太屎了,白天把G补了才知道简单的很,但f还是没头绪呜呜呜 Problem - A - Codeforces Given the ...

  7. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  8. 信仰之题——Codeforces Round 259(附题面完整翻译)

    终于下定决心要把整套题做完了. 最早认识这套题不是因为什么板刷,也不是因为什么模拟赛,而是这套题目标题里清一色的"pony",我想这也是为什么我会管这套题叫信仰之题吧(笑). 不过 ...

  9. 2019年湘潭大学程序设计竞赛(重现赛)补题:H.Chat(分组背包)

    链接:https://ac.nowcoder.com/acm/problem/25581 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  10. Educational Codeforces Round 110 div.2 A~F题解

    视频讲解:BV1254y137Rn A. Fair Playoff 题目大意 有 444 位选手参加比赛,第 iii 位选手的水平为 si(1≤si≤100)s_i(1 \leq s_i \leq 1 ...

最新文章

  1. Spring Workflow
  2. 复现经典:《统计学习方法》第15章 奇异值分解
  3. 2020 JVM生态报告
  4. C/C++ 中变量的声明、定义、初始化的区别
  5. Python之路【第十七篇】:装饰器
  6. c语言编写考试程序,c语言考试编写三个程序:1.从键盘输入一些字符,逐个把它们送到磁? 爱问知识人...
  7. Bzoj1899: [Zjoi2004]Lunch 午餐
  8. 怎么创建数据表的实体类和业务类_SSM搭建二手市场交易平台(二):数据表设计...
  9. t–sql pl–sql_糟糕SQL查询设计– SQL查询性能的杀手–基本知识
  10. 【安卓的一个进程等级】
  11. 190727每日一句
  12. 开源日志系统log4cplus(五)
  13. 啊哈c语言逻辑推箱子答案,啊哈C语言!逻辑的挑战(修订版)
  14. ISO 9000 族标准的构成
  15. word打开wps文件乱码_Word文档打开是乱码怎么解决
  16. java记忆翻牌_html5记忆翻牌游戏
  17. 人脸检测——UnitBox
  18. 如何把自己的项目部署在腾讯云服务器上,别人可以访问(超详细教程)
  19. python实现千牛客服自动回复语_千牛客服自动回复话术
  20. iOS 苹果官方Demo合集

热门文章

  1. 关于ele框架样式修改
  2. 微信支付服务器白名单,总结下我在微信支付中趟的那些坑。
  3. 移动网络安装测试软件,家宽众测中国移动手机版(在线宽带网速测试器)V2.0.3 去广告版...
  4. excel合并两列内容_10.表格中如何将两列文本内容合并
  5. 结构化程序设计知识点总结
  6. 软件工程——软件开发过程中用到的各种图
  7. html字体外颜色轮廓,文字轮廓效果
  8. xp系统重装后无法连接服务器6,winXP重装系统后不能上网的解决方法
  9. 怎么搜索代码里的所有中文汉字
  10. request请求头中出现Provisional headers are shown