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) ...
随机推荐
- xe mysql
[FireDAC][Phys][MySQL]-314. Cannot load vendor library [libmysql.dll or libmysqld.dll]. The specifie ...
- ms-class的进化
ms-class是avalon用得最多的几个绑定之一,也正因为如此其功能一直在扩充中.根据时期的不同,分为旧风格与新风格两种. 旧风格是指正在ms-class后面跟着类外,然后在绑定值中添加表达式,即 ...
- UVALive 5881 Unique Encryption Keys (DP)
Unique Encryption Keys 题目链接: http://acm.hust.edu.cn/vjudge/problem/26633 Description http://7xjob4.c ...
- unigui unidbgrid显示列的合计值
procedure TfrmClient.UniDBGrid1ColumnSummaryResult(Column: TUniDBGridColumn; GroupFieldValue: Varian ...
- D. Green and Black Tea
先搞多的,搞到相等. (tmd上星期+上上星期简直是弱智,怎么也不会写,总是想着各种a/b,,,踢蹬) #include<bits/stdc++.h> #define lowbit(x) ...
- OC:属性的内部实现原理、dealloc内释放实例变量、便利构造器方法的实现原理、collection的内存管理
代码: // // main.m #import <Foundation/Foundation.h> #import "Person.h" #import " ...
- OC: NSString、NSArray、NSNumber
数组参考: 参考1 参考2 参考3 //字符串 //1.获取字符串的长度: //表情符号最少占两个字节 NSString * s = @"中文字符串
- Log设计
Log设计 http://biancheng.dnbcw.info/net/380312.html http://blog.csdn.net/anyqu/article/details/7937378 ...
- 设置AD用户属性
设置AD用户属性proxyaddresses的值 $test01 = [adsi]"LDAP://cn=test01,ou=oo,ou=admins,dc=ddv,dc=com" ...
- 静默安装oracle11G
1.操作系统及Oracle版本 Linux版本:CentOS release 5.5 (Final) Oracle版本:Oracle Database 11g Release 2 (11.2.0.1. ...