码迷,mamicode.com
首页 > 其他好文 > 详细

A1487. 分配游戏(王康宁)

时间:2015-12-04 14:40:34      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

  把题目所给的三元组看成三维空间里的点坐标,记录下来每个点在每个坐标平面上的映射,对于每一个询问,查询每个面上分别有多少个点在该点的映射与原点所组成的矩形内部

  原先想到二维树状数组,然而老爷吃着鸡块说了一句空间炸了,,,于是炸了

  然后发现其实还是在树状数组上lg,但是要把插入和询问和(huo)在一起,按其中一维排序,先询问后查询

  膜一下fatheryoung,码代码神快,神稳

  风格分不及格,,,贴代码好方

技术分享
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef pair<int,int>pii;
 4 typedef pair<pii,pii>haha;
 5 #define maxn 1000005
 6 #define maxm 200005
 7 #define rep(i) for(int i=0;i<3;i++)
 8 #define mp make_pair
 9 #define fir first
10 #define sec second
11 int hh,n,m,t,a[3],ans[maxm],hash[maxn*6],BIT[3][maxn*6];
12 haha poi[3][maxm];
13 int read(){
14     char ch=0;
15     int tmp=0;
16     while(!isdigit(ch))ch=getchar();
17     while(isdigit(ch)){
18         tmp=tmp*10+ch-0;
19         ch=getchar();
20     }
21     return tmp;
22 }
23 inline void in_hash(){
24     rep(i)hash[++hh]=a[i];
25 }
26 void insert(int p,int x){
27     x=lower_bound(hash+1,hash+1+hh,x)-hash;
28     for(int i=x;i<=hh;i+=i&-i)//
29         BIT[p][i]++;
30 }
31 int query(int p,int x){
32     x=lower_bound(hash+1,hash+1+hh,x)-hash - 1;
33     int sum=0;
34     for(int i=x;i>=1;i-=i&-i)
35         sum+=BIT[p][i];
36     return sum;
37 }
38 int main(){
39     n=read();m=read();t=read();
40     for(int i=1;i<=m;i++){
41         a[0]=read();a[1]=read();a[2]=read();
42         in_hash();
43         rep(j)
44             for(int k=j+1;k<3;k++){
45                 int ord=j+k-1;
46                 poi[ord][i]=mp(mp(a[j],1),mp(a[k],i));
47             }
48     }
49     for(int i=1;i<=t;i++){
50         a[0]=read();a[1]=read();a[2]=read();
51         in_hash();
52         rep(j)
53             for(int k=j+1;k<3;k++){
54                 int ord=j+k-1;
55                 poi[ord][i+m]=mp(mp(a[j],0),mp(a[k],i));//
56             }
57     }
58     sort(hash+1,hash+1+hh);
59     hh=unique(hash+1,hash+1+hh)-(hash+1);
60     rep(i)sort(poi[i]+1,poi[i]+1+m+t);
61     n=m+t;
62     rep(i)
63         for(int j=1;j<=n;j++){
64             int id=poi[i][j].sec.sec;
65             int op=poi[i][j].fir.sec;
66             int val=poi[i][j].sec.fir;
67             if(op==1)insert(i,val);
68             else ans[id]+=query(i,val);
69         }
70     for(int i=1;i<=t;i++)printf("%d\n",ans[i]);
71     return 0;
72 }
View Code

 

A1487. 分配游戏(王康宁)

标签:

原文地址:http://www.cnblogs.com/Ngshily/p/5019022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!