Japan
Input
Output
Test case (case number): (number of crossings)
Sample Input
1
3 4 4
1 4
2 3
3 2
3 1
Sample Output
Test case 1: 5
- #include"iostream"
- #include"algorithm"
- #include"cstring"
- #include"cstdio"
- using namespace std;
- structxy
- {
- int x,y;
- }a[1000010];
- int c[1005];
- //long long int max;
- int cmp(const xy&a,const xy&b)
- {
- if(a.x!=b.x)
- return a.x<b.x;
- else
- return a.y<b.y;
- }
- int lowbit(int x)
- {
- return x&(-x);
- }
- void updata(int x,int d,int max)
- {
- while(x<=max)
- {
- c[x]+=d;
- x+=lowbit(x);
- }
- }
- long long int getsum(int x)
- {
- long long int res=0;
- while(x>0)
- {
- res+=c[x];
- x-=lowbit(x);
- }
- return res;
- }
- int main()
- {
- int i,t,p=0;
- scanf("%d",&t);
- while(t--)
- {
- int n,m,k,max;
- memset(c,0,sizeof(c));
- max=0;
- scanf("%d%d%d",&n,&m,&k);
- for(i=0;i<k;i++)
- {
- scanf("%d%d",&a[i].x,&a[i].y);
- if(a[i].y>max)
- max=a[i].y;
- }
- sort(a,a+k,cmp);
- long long int sum=0;
- updata(a[0].y,1,max);
- for(i=1;i<k;i++)
- {
- sum+=getsum(max)-getsum(a[i].y);
- updata(a[i].y,1,max);
- }
- printf("Test case %d: %lld\n",++p,sum);
- }
- return 0;
- }
Japan的更多相关文章
- POJ 3067 Japan(树状数组)
Japan Time Limit: 10 ...
- POJ 3067 Japan
Japan Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25489 Accepted: 6907 Descriptio ...
- cdoj 383 japan 树状数组
Japan Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/383 Descrip ...
- Day 3 @ RSA Conference Asia Pacific & Japan 2016 (morning)
09.00 – 09.45 hrs Tracks Cloud, Mobile, & IoT Security A New Security Paradigm for IoT (Inter ...
- Day 4 @ RSA Conference Asia Pacific & Japan 2016
09.00 – 09.45 hrs Advanced Malware and the Cloud: The New Concept of 'Attack Fan-out' Krishna Naraya ...
- POJ 3067 - Japan - [归并排序/树状数组(BIT)求逆序对]
Time Limit: 1000MS Memory Limit: 65536K Description Japan plans to welcome the ACM ICPC World Finals ...
- poj3067 Japan(树状数组)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=3067">http://poj.org/problem? id=3067 Descri ...
- Japan POJ - 3067 转化思维 转化为求逆序对
Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Jap ...
- cdojR - Japan
地址:http://acm.uestc.edu.cn/#/contest/show/95 题目: R - Japan Time Limit: 3000/1000MS (Java/Others) ...
随机推荐
- AndroidStudio debug
1. view as text
- Accessor Search Implementation Details
[Accessor Search Implementation Details] Key-value coding attempts to use accessor methods to get an ...
- Determining Equality of Objects
[Determining Equality of Objects] If you need to determine whether one object is the same as another ...
- Struts ForwardAction Example
In Struts MVC model, you have to go thought the Action Controller to get a new view page. In some ca ...
- 使用UIGestureRecognizer监听屏幕事件
转载自 http://blog.csdn.net/samguoyi/article/details/7911499 如果只是想获取屏幕点击事件有一个最简单的办法,就是写一个透明的uibutton覆盖 ...
- 队列与DelphiXe新语法
好久没写代码了,更久没上博客园的博客了,无聊写几行试一下新语法. 1 unit Main; interface uses Winapi.Windows, Winapi.Messages, System ...
- Linux /proc 的意义
/proc 是个虚拟文件系统.也就是.重新引导后修改会被重新初始化 提供了进程信息.内存资源.硬件设备.内核内存等信息 比如: 网卡:/proc/sys/vm/ipv4/ip_ ...
- String.Format格式说明(转)
C#格式化数值结果表 字符 说明 示例 输出 C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0 ...
- hdoj 5335 Walk Out
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5335 #include<stdio.h> #include<cstring> ...
- 实现jsp网站添加到收藏夹
var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd': 'CTRL'; ...