标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 23111 | Accepted: 6232 |
Description
Input
Output
Sample Input
1 3 4 4 1 4 2 3 3 2 3 1
Sample Output
Test case 1: 5
Source
1 /************************************************************************* 2 > File Name: code/poj/3067.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年08月04日 星期二 10时49分06秒 6 ************************************************************************/ 7 8 #include<iostream> 9 #include<iomanip> 10 #include<cstdio> 11 #include<algorithm> 12 #include<cmath> 13 #include<cstring> 14 #include<string> 15 #include<map> 16 #include<set> 17 #include<queue> 18 #include<vector> 19 #include<stack> 20 #define y0 abc111qqz 21 #define y1 hust111qqz 22 #define yn hez111qqz 23 #define j1 cute111qqz 24 #define tm crazy111qqz 25 #define lr dying111qqz 26 using namespace std; 27 #define REP(i, n) for (int i=0;i<int(n);++i) 28 typedef long long LL; 29 typedef unsigned long long ULL; 30 const int inf = 0x7fffffff; 31 const int N=1E3+5; 32 33 int n,m,k; 34 int t[N*N/2]; 35 struct R 36 { 37 int x,y; 38 }r[N*N/2]; 39 40 bool cmp(R a,R b) 41 { 42 if (a.x<b.x) return true; 43 if (a.x==b.x&&a.y<b.y) return true; 44 return false; 45 } 46 int lowbit(int x) 47 { 48 return x&(-x); 49 } 50 void update (int x,int c) 51 { 52 for ( int i = x ; i < N ; i = i + lowbit(i)) 53 { 54 t[i] = t[i] + c; 55 } 56 } 57 LL sum ( int x) 58 { 59 int res = 0 ; 60 for ( int i = x ; i >= 1 ; i = i - lowbit(i)) 61 { 62 res = res + t[i]; 63 } 64 return res; 65 } 66 int main() 67 { 68 int T; 69 cin>>T; 70 LL ans ; 71 int cas = 0; 72 while (T--) 73 { 74 memset(t,0,sizeof(t)); 75 memset(r,0,sizeof(r)); 76 ans = 0 ; 77 cas++; 78 scanf("%d %d %d",&n,&m,&k); 79 for ( int i = 0 ; i < k ; i ++ ) 80 { 81 scanf("%d %d",&r[i].x,&r[i].y); 82 } 83 sort(r,r+k,cmp); 84 for ( int i = 0 ; i < k; i ++ ) //起点终点相同不算crossing 85 { 86 // update(r[i].x,1); 87 // if (r[i].x==r[i-1].x||r[i].y==r[i-1].y) continue; 88 ans = ans +i- sum(r[i].y); //求y的逆序对数,好好理解这行代码! 89 // cout<<"ans:"<<ans<<endl; 90 update(r[i].y,1); 91 } 92 printf("Test case %d: %lld\n",cas,ans); 93 94 } 95 return 0; 96 }
标签:
原文地址:http://www.cnblogs.com/111qqz/p/4701640.html