标签:sam 方式 ble double ase split note tput void
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1004 Accepted Submission(s): 356
1 #include <iostream> 2 #include <string> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 #include <climits> 7 #include <cmath> 8 #include <vector> 9 #include <queue> 10 #include <stack> 11 #include <set> 12 #include <map> 13 using namespace std; 14 typedef long long LL ; 15 typedef unsigned long long ULL ; 16 const int maxn = 1e5 + 10 ; 17 const int inf = 0x3f3f3f3f ; 18 const int npos = -1 ; 19 const int mod = 1e9 + 7 ; 20 const int mxx = 100 + 5 ; 21 const double eps = 1e-6 ; 22 const double PI = acos(-1.0) ; 23 24 struct node{ 25 int a, c, d, cnt; 26 bool operator < (const node &r)const{ 27 if(a!=r.a) return a>r.a; 28 else if(c!=r.c) return c>r.c; 29 else return d>r.d; 30 } 31 bool operator == (const node &r)const{ 32 return (a==r.a)&&(c==r.c)&&(d==r.d); 33 } 34 }; 35 node e[maxn]; 36 int T, n, m, u, v, w, cnt, tot; 37 int a[maxn], c[maxn], d[1000+5][1000+5]; 38 int lowbit(int x){ 39 return x&(-x); 40 } 41 void update(int x, int y, int z){ 42 for(int i=x;i>0;i-=lowbit(i)) 43 for(int j=y;j>0;j-=lowbit(j)) 44 d[i][j]+=z; 45 } 46 int quary(int x, int y){ 47 int res=0; 48 for(int i=x;i<=1e3;i+=lowbit(i)) 49 for(int j=y;j<=1e3;j+=lowbit(j)) 50 res+=d[i][j]; 51 return res; 52 } 53 int main(){ 54 // freopen("in.txt","r",stdin); 55 // freopen("out.txt","w",stdout); 56 while(~scanf("%d",&T)){ 57 for(int kase=1;kase<=T;kase++){ 58 cnt=0; 59 tot=0; 60 memset(a,0,sizeof(a)); 61 memset(c,0,sizeof(c)); 62 memset(d,0,sizeof(d)); 63 scanf("%d %d",&n,&m); 64 for(int i=1;i<=n;i++){ 65 scanf("%d %d",&u,&v); 66 if(a[v]<u) 67 a[v]=u, c[v]=1; 68 else if(a[v]==u) 69 c[v]++; 70 } 71 for(int i=1;i<=m;i++){ 72 scanf("%d %d %d",&u,&v,&w); 73 if(a[w]) 74 e[cnt++]=(node){a[w],u,v,c[w]}; 75 } 76 sort(e,e+cnt); 77 for(int i=1;i<cnt;i++) 78 if(e[tot]==e[i]) 79 e[tot].cnt+=e[i].cnt; 80 else 81 e[++tot]=e[i]; 82 LL ans=0LL; 83 for(int i=0;i<=tot;i++){ 84 if(!quary(e[i].c,e[i].d)) 85 ans+=e[i].cnt; 86 update(e[i].c,e[i].d,1); 87 } 88 printf("Case #%d: %lld\n",kase,ans); 89 } 90 } 91 return 0; 92 }
标签:sam 方式 ble double ase split note tput void
原文地址:http://www.cnblogs.com/edward108/p/7642649.html