pair-pair
输入文件:pair-pair.in
输出文件:pair-pair.out
简单对比
时间限制:7 s 内存限制:64 MB
Time Limit : 7000 MS
Memory Limit : 65536 KB
Pair-Pair
Bobo is tired of all kinds of hard LIS (Longest Increasing Subsequence) problems, so he decides to make himself some easier one.
Bobo has n pairs (a1,b1),(a2,b2),…,(an,bn) where 1≤ai,bi≤m holds for all i. He defines f(i,j) be the length of longest increasing subsequence of sequence {ai,bi,aj,bj}.
It's clear that 1≤f(i,j)≤4. Bobo would like to know g(k) which is the number of pairs (i,j) where f(i,j)=k.
Note that a sequence labeled with {i1,i2,…,ik} is an increasing subsequence of {a1,a2,…,an} only if:
1≤i1 Input The first line contains 2 integers n,m (1≤n≤105,1≤m≤103). The i-th of the following n lines contains 2 integers ai,bi (1≤ai,bi≤m). Output For each set, 4 integers g(1),g(2),g(3),g(4). Sample Input 2 4 1 2 3 4 2 1 1 1 1 1 Sample Output 0 3 0 1 4 0 0 0 注意各种特判就好了。 有时间再更新题解吧…… rt[last];
94
95 tmp+=Query(rt[0],rt[p[i].a-1],1,m,p[i].b,m);
96
97 a[3]+=tmp;tot-=tmp;
98
99 Insert(rt[last],rt[p[i].a],1,m,p[i].b,1);
100
101 last=p[i].a;a[2]+=tot;
102
103 Bit_Add(b1,p[i].a,1);Bit_Add(b2,p[i].b,1);
104 }
105 else{
106 tmp=Bit_Query(b3,p[i].b)+Bit_Query(b4,m)-Bit_Query(b4,p[i].a-1);
107 a[1]+=tmp;tot-=tmp;
108
109 tmp=Bit_Query(b1,m)-Bit_Query(b1,p[i].b)+Bit_Query(b2,p[i].a-1);
110 a[3]+=tmp;tot-=tmp;
111
112 a[2]+=tot;
113 Bit_Add(b3,p[i].a,1);Bit_Add(b4,p[i].b,1);
114 }
115 }
116
117 for(int i=1;i<=n;i++){
118 if(p[i].a!=p[i].b)a[2]+=1;
119 else a[1]+=1;
120 }
121 printf("%lld %lld %lld %lld\n",a[1],a[2],a[3],a[4]);
122 }
123 return 0;
124 } 1 #include