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-1个数等于(a*i+b)%n,问逆序对有多少
题解:
树状数组
代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define MOD 1000000007
#define maxn 32001
using namespace std;
typedef __int64 ll;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//******************************************************************* struct ss
{
int v,index;
} in[];
int c[];
int a[];
ll n;
bool cmp(ss s1,ss s2)
{
return s1.v<s2.v;
}
int lowbit(int x)
{
return x&(-x);
}
int getsum(int x)
{
int sum=;
while(x>)
{
sum+=c[x];
x-=lowbit(x);
}
return sum;
}
void update(int x,int value)
{
while(x<=n)
{
c[x]+=value;
x+=lowbit(x);
}
} int main()
{
ll x,y;
int oo=;
while(scanf("%lld%lld%lld",&n,&x,&y)!=EOF)
{
if(n==&&x==&&y==)break;
memset(c,,sizeof(c));
for(int i=; i<n; i++)
{
a[i+]=(x*i+y)%n+;
}
ll ans=;
for(int i=; i<=n; i++)
{
update(a[i],);
ans+=i-getsum(a[i]);
}
printf("Case %d: ",oo++);
cout<<ans<<endl;
} return ;
}
Gym 100463A Crossings 逆序对的更多相关文章
- Codeforces 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 ...
- Gym - 101908C 树状数组 逆序对
Grandpa Giuseppe won a professional pizza cutter, the kind of type reel and, to celebrate, baked a r ...
- CF Gym 100463A (树状数组求逆序数)
题意:给你一个序列,和标准序列连线,求交点数. 题解:就是求逆序对个数,用树状数组优化就行了.具体过程就是按照顺序往树状数组了插点(根据点的大小),因为第i大的点应该排在第i位,插进去的时候他前面本该 ...
- POJ 2299 逆序对
Crossings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463 Description I ...
- POJ 3067 - Japan - [归并排序/树状数组(BIT)求逆序对]
Time Limit: 1000MS Memory Limit: 65536K Description Japan plans to welcome the ACM ICPC World Finals ...
- Japan POJ - 3067 转化思维 转化为求逆序对
Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Jap ...
- 【CQOI2011】动态逆序对 BZOJ3295
Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依次删除m个元素,你的任务是在每次删除一个元素之前统计 ...
- CH Round #72 奇数码问题[逆序对 观察]
描述 你一定玩过八数码游戏,它实际上是在一个3*3的网格中进行的,1个空格和1~8这8个数字恰好不重不漏地分布在这3*3的网格中. 例如:5 2 81 3 _4 6 7 在游戏过程中,可以把空格与其上 ...
随机推荐
- zstu.4019.排队购票(多维dp)
排队购票 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1264 Solved: 808 Description 一常球赛开始前,售票工作正在进行中. ...
- 推荐两款Xcode插件:KSImageNamed & ColorSense
之前没怎么接触过Xcode插件,最近发现有人给Xcode做了一些方便编程的插件.今天就推荐两个我个人认为比较好的. 1.KSImageNamed 网站地址 KSImageNamed是一款方便填写图片文 ...
- java笔记--超级类Object多线程的应用+哲学家进餐算法内部类与多线程结合
关于Object类中的线程方法: Object类是所有Java类的 父类,在该类中定义了三个与线程操作有关的方法,使得所有的Java类在创建之后就支持多线程 这三个方法是:notify(),notif ...
- Android计时器实例
布局文件 <Chronometer android:id="@+id/chronometer" android:layout_width="wrap_content ...
- facedetect
继续学习大神的博文http://www.cnblogs.com/tornadomeet/archive/2012/03/22/2411318.html
- apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104))
apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104)) 今天用apache 自带的ab工具测试,当并发量达到1000多的时 ...
- Linux下列格式化工具 - column
[root@localhost ~]# mount/dev/sda2 on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type ...
- 【Python】Django 时间字段 最佳实践
. python datetime from datetime import datetime datetime.now() datetime.utcnow() from datetime impor ...
- 【SpringMVC】SpringMVC系列6之@CookieValue 映射请求Cookie 值
6.@CookieValue 映射请求Cookie 值 6.1.示例 @CookieValue 可让处理方法入参绑定某个 Cookie 值,示例如下:
- iOS 中使用类别简化代码开发
最近需要一个函数,把CLLocation对象转化为NSDictionary,按照我以前的想法,我会写一个工具类,之后添加一个函数,类似这样 - (NSDictionary *)turnLocation ...