博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2011 Michigan Invitational Programming Contest
阅读量:7292 次
发布时间:2019-06-30

本文共 1959 字,大约阅读时间需要 6 分钟。

Crossings

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100463

Description

Given a permutation P of {0, 1, ..., n − 1}, we define the crossing number of it as follows. Write the sequence 0, 1, 2, . . . , n − 1 from left to right above the sequence P(0), P(1), . . . , P(n − 1). Draw a straignt line from 0 in the top line to 0 in the bottom line, from 1 to 1, and so on. The crossing number of P is the number of pairs of lines that cross. For example, if n = 5 and P = [1, 3, 0, 2, 4], then the crossing number of P is 3, as shown in the figure below. !""""#""""
""""""""&" In this problem a permutation will be specified by a tuple (n, a, b), where n is a prime and a and b are integers (1 ≤ a ≤ n − 1 and 0 ≤ b ≤ n − 1). We call this permutation Perm(n, a, b), and the ith element of it is a ∗ i + b mod n (with i in the range [0, n − 1]). So the example above is specified by Perm(5, 2, 1).

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

给你三个数n,a,b

满足第i个数等于(a*i+b)%n,然后问你逆序数是多少

这个n有1e6呢,所以树状数组和归并都能解决这个题吧

#include
using namespace std;typedef long long ll;const int N=1e6+10;int d[N];ll n,a,b;void update(int x,int y) { while(x<=n) { d[x]+=y; x+=x&-x; }}int sum(int x) { int s=0; while(x>0) { s+=d[x]; x-=x&-x; } return s;}int main() { int k=1; while(~scanf("%lld%lld%lld",&n,&a,&b)) { if(!n&&!a&&!b) break; memset(d,0,sizeof(d)); ll ans=0; for(int i=0; i

 

转载于:https://www.cnblogs.com/BobHuang/p/7258369.html

你可能感兴趣的文章
Java豆瓣电影爬虫——抓取电影详情和电影短评数据
查看>>
如何让程序在后台执行
查看>>
bzoj3296[USACO2011 Open] Learning Languages*
查看>>
关于浮动元素对父元素高度的影响
查看>>
Mysql 关键字的优先级 分组 多表联查
查看>>
java 调用js
查看>>
iOS开发UI篇—Quartz2D使用(图形上下文栈)
查看>>
Oracle迁移MySQL笔记
查看>>
Building a Pub/Sub Message Bus with Wcf,Msmq,IIS
查看>>
Mybatis实现批量删除
查看>>
【leetcode】995. Minimum Number of K Consecutive Bit Flips
查看>>
【洛谷 P4886】 快递员 (点分治)
查看>>
在Ajax中将数组转换成字符串(0517-am)
查看>>
hive字符串函数
查看>>
【erlang ~ 4 days】 Day # 1.2 Sequential Programming
查看>>
HDFS Erasure Coding介绍
查看>>
abstract vs interface
查看>>
egret 游戏优化文档
查看>>
蚂蚁金服研发面经
查看>>
xmanagr 注册机执行ubuntu 桌面程序,ubuntu无需安装 桌面环境
查看>>