题意:

给你1-n的序列,然后有k次机会的操作,每一次你可以选择两个数交换。

求一个最大的逆序数。

思路:

感觉就是最后一个和第一个交换,然后往中间逼近,到最终的序列,用树状数组求一下逆序数。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define MAX 100010
typedef __int64 LL;
#define mod 10000007 const int N=1e5+10; struct asd{
int v,pos;
};
asd q[N*4];
int c[N*4];
int n; int Sum(int x)
{
LL ans=0;
while(x>0)
{
ans+=c[x];
x-=x&(-x);
}
return ans;
} void update(int x,int t)
{
while(x<=n+5)
{
c[x]+=t;
x+=x&(-x);
}
}
int a[N+10]; int main()
{
int k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
a[i]=i;
for(int i=1;i+i<=n&&i<=k;i++)
swap(a[i],a[n-i+1]); LL ans=0;
for(int i=1;i<=n;i++)
{
update(a[i],1);
ans+=i-Sum(a[i]);
}
printf("%I64d\n",ans);
return 0;
}

还有很多简单的操作…对不会总结的人来说,看的智商有点做急。。。。

情人节快乐…汪!

最新文章

  1. ASP.NET MVC——Razor视图引擎
  2. ROS语音交互(三)科大讯飞语音在ROS平台下使用
  3. MATLAB画图
  4. spring mvc如何获取问号后的url参数
  5. 欢迎参加MVP主讲的Windows 10开发线上课程
  6. selenium简介
  7. Stimulsoft Reports报表工具
  8. 对Cost (%CPU) 粗略的理解
  9. 将数字n转换为字符串并保存到s中
  10. 》》css3--动画
  11. 【一天一道LeetCode】#371. Sum of Two Integers
  12. 嵌入页面的几种方法(转载自萤火虫小Q)
  13. UITableView的分割线长短的控制
  14. 【转载】springboot四 全局异常处理
  15. webstorm安装 利用host破解
  16. 理解TCP之Keepalive
  17. mysql添加事件
  18. ZOJ3202-Second-price Auction(根据输入输出判断是队列还是栈)
  19. Angular动态表单生成(五)
  20. hadoop日常维护之问题解决01

热门文章

  1. Java之基于Eclipse搭建SSH框架(下)
  2. Ubuntu下编译Android JNI实例全过程
  3. POJ - 1062 昂贵的聘礼(最短路Dijkstra)
  4. SpringBoot学习之快速入门创建
  5. ditaa - 把ascii图形转成图片
  6. android-測试so动态库(九)
  7. PCH in Xcode 6
  8. gRPC错误码 http状态码 provide your APIs in both gRPC and RESTful style at the same time
  9. this that 时间戳转日期 小程序 列表 与 加载
  10. Ruby map、each、select、inject、collect 、detect reference