Codeforces Gym 100463A Crossings 逆序数
Crossings
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100463
Description
Input
There are several test cases in the input file. Each test case is specified by three space-separated numbers n, a, and b on a line. The prime n will be at most 1,000,000. The input is terminated with a line containing three zeros.
Output
For each case in the input print out the case number followed by the crossing number of the permutation. Follow the format in the example output.
Sample Input
5 2 1 19 12 7 0 0 0
Sample Output
Case 1: 3 Case 2: 77
HINT
题意
给你n个数,第i个数等于(a*i+b)%n,然后问你逆序数是多少
题解:
树状数组,大胆上
代码
- //qscqesze
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <ctime>
- #include <iostream>
- #include <algorithm>
- #include <set>
- #include <vector>
- #include <sstream>
- #include <queue>
- #include <typeinfo>
- #include <fstream>
- #include <map>
- typedef long long ll;
- using namespace std;
- //freopen("D.in","r",stdin);
- //freopen("D.out","w",stdout);
- #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
- #define maxn 1000101
- #define mod 10007
- #define eps 1e-9
- const int inf=0x7fffffff; //无限大
- /*
- inline ll read()
- {
- int x=0,f=1;char ch=getchar();
- while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
- while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
- return x*f;
- }
- */
- //**************************************************************************************
- int d[maxn];
- int c[maxn];
- ll n;
- int t;
- inline int read()
- {
- int x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- int lowbit(int x)
- {
- return x&-x;
- }
- void update(int x,int y)
- {
- while(x<=n)
- {
- d[x]+=y;
- x+=lowbit(x);
- }
- }
- int sum(int x)
- {
- int s=;
- while(x>)
- {
- s+=d[x];
- x-=lowbit(x);
- }
- return s;
- }
- int num[maxn];
- ll a,b;
- int main()
- {
- int t=;
- while(scanf("%lld%lld%lld",&n,&a,&b)!=EOF)
- {
- t++;
- if(n==&&a==&&b==)
- break;
- memset(d,,sizeof(d));
- ll ans=;
- for(int i=;i<n;i++)
- {
- int x=(a*i+b)%n+;
- ans+=sum(x-);
- update(x,);
- }
- printf("Case %d: %lld\n",t,(n-)*n/-ans);
- }
- }
Codeforces Gym 100463A Crossings 逆序数的更多相关文章
- Gym 100463A Crossings 逆序对
Crossings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463 Description ...
- Gym 100463A Crossings (树状数组 逆序对)
Crossings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463 Description ...
- Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida's problem(求逆序数对)
题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...
- Codeforces 645B Mischievous Mess Makers【逆序数】
题目链接: http://codeforces.com/problemset/problem/645/B 题意: 给定步数和排列,每步可以交换两个数,问最后逆序数最多是多少对? 分析: 看例子就能看出 ...
- Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem (树状数组求逆序数 变形)
题目链接 题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求i和j的种类数. 我们可以用map预处理出 ...
- Codeforces Round #301 (Div. 2) E . Infinite Inversions 树状数组求逆序数
E. Infinite Inversions ...
- Codeforces Gym 100187K K. Perpetuum Mobile 构造
K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
- CF 61E 树状数组+离散化 求逆序数加强版 三个数逆序
http://codeforces.com/problemset/problem/61/E 题意是求 i<j<k && a[i]>a[j]>a[k] 的对数 会 ...
- poj3067树状数组求逆序数
Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Jap ...
随机推荐
- 顺序表的基本操作(C)
在顺序存储结构实现基本操作:初始化.创建.插入.删除.查找.遍历.逆置.合并运算. 运行示例: 请输入线性表La的长度: 请输入线性表La中的元素(共5个) *** 此时线性表La中的元素 *** * ...
- TortoiseSVN 插件配置及使用方法
一.安装和配置 TortoiseSVN的下载地址 32bit:TortoiseSVN-1.8.2.24708-win32-svn-1.8.3.msi 64bit:TortoiseSVN-1.8.2.2 ...
- Hadoop 2 初探
Hadoop 2.6.0的安装略复杂,在一台既有Hadoop 1又有Hadoop 2的server上,要设置好环境变量,必要时候echo $HADOOP_HOME一下看运行的是哪个版本. Master ...
- 20+非常棒的Photoshop卡通设计教程
现在把一个人的脸变成卡通图案再用它来当头像这种现象使非常常见的,同样的卡通插图可以用于多种渠道的设计.网上有很多公司都会创立一种吉祥物并把它应用到市场营销中.因为有了类似于photoshop这样强大的 ...
- Google Glass应用开发探索
摘要:2012年6月的Google开发者大会上,作者有幸预定到了Google Glass.8个月后,她收邀参加了Google纽约总部举行的Google Glass Foundry开发大赛.在为期两天的 ...
- 纯JS Web在线可拖拽的流程设计器
F2工作流引擎之-纯JS Web在线可拖拽的流程设计器 Web纯JS流程设计器无需编程,完全是通过鼠标拖.拉.拽的方式来完成,支持串行.并行.分支.异或分支.M取N路分支.会签.聚合.多重聚合.退回. ...
- 可迭代的集合类型使用foreach语句
在学习算法这本书图论那一部分的时候,接触到了几个类似for(int w:G.adj(v)),的语句,不是很理解,就去百度,发现这是一种叫做foreach的语法,在书的76页有讲到,但是之前没认真看书, ...
- Cisco SDM
SDM连接方式:http+telnet / https+ssh 要使用SDM对CISCO设备实现集中式管理,必须在设备上键入如下命令: 步骤1: 要启用路由器的HTTP/HTTPS 服务器,请 ...
- js 设置回车事件
document.onkeydown=function(event){ var e = event || window.event || arguments.callee.caller.argumen ...
- Compactness问题
今天偶然在论坛讨论在halcon下紧密度的问题,现在总结一下 Calculation: If L is the length of the contour (see contlength) and F ...