标签:input sed inpu struct ext play namespace com eof
此题一开始我竟然没想到怎么做,二维树状数组开不下,而且只有询问没有修改很浪费,
看了题解之后恍然大悟,题解只有一句话,x坐标排序,y坐标上离散化以后树状数组(而且还可以不用离散化)。
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<cstdlib> 7 #include<vector> 8 using namespace std; 9 typedef long long ll; 10 typedef long double ld; 11 typedef pair<int,int> pr; 12 const double pi=acos(-1); 13 #define rep(i,a,n) for(int i=a;i<=n;i++) 14 #define per(i,n,a) for(int i=n;i>=a;i--) 15 #define Rep(i,u) for(int i=head[u];i;i=Next[i]) 16 #define clr(a) memset(a,0,sizeof(a)) 17 #define pb push_back 18 #define mp make_pair 19 #define fi first 20 #define sc second 21 #define pq priority_queue 22 #define pqb priority_queue <int, vector<int>, less<int> > 23 #define pqs priority_queue <int, vector<int>, greater<int> > 24 #define vec vector 25 ld eps=1e-9; 26 ll pp=1000000007; 27 ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;} 28 ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;} 29 void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); } 30 //void add(int x,int y,int z){ v[++e]=y; next[e]=head[x]; head[x]=e; cost[e]=z; } 31 int dx[5]={0,-1,1,0,0},dy[5]={0,0,0,-1,1}; 32 ll read(){ ll ans=0; char last=‘ ‘,ch=getchar(); 33 while(ch<‘0‘ || ch>‘9‘)last=ch,ch=getchar(); 34 while(ch>=‘0‘ && ch<=‘9‘)ans=ans*10+ch-‘0‘,ch=getchar(); 35 if(last==‘-‘)ans=-ans; return ans; 36 } 37 #define N 10000000 38 #define N_ 500005 39 int T[N+5],ans[N_][5]; 40 struct node{ 41 int x,y,id,f; 42 }a[N_+N_+N_+N_+N_+N_]; 43 #define lowbit(i) (i&(-i)) 44 void add(int x,int v){ 45 for (int i=x;i<=N+1;i+=lowbit(i)) T[i]+=v; 46 } 47 int sum(int x){ 48 int Sum=0; 49 for (int i=x;i>0;i-=lowbit(i)) Sum+=T[i]; 50 return Sum; 51 } 52 bool cmp(node a,node b){ 53 return a.x<b.x||(a.x==b.x&&a.f<b.f); 54 } 55 int main() 56 { 57 int n=read(),m=read(); 58 for (int i=1;i<=n;i++) a[i].x=read(),a[i].y=read(); 59 int e=n; 60 for (int i=1;i<=m;i++){ 61 int a_=read(),b_=read(),c_=read(),d_=read(); 62 a[++e].x=a_-1; a[e].y=b_-1; a[e].f=1; a[e].id=i; 63 a[++e].x=a_-1; a[e].y=d_; a[e].f=2; a[e].id=i; 64 a[++e].x=c_; a[e].y=b_-1; a[e].f=3; a[e].id=i; 65 a[++e].x=c_; a[e].y=d_; a[e].f=4; a[e].id=i; 66 } 67 sort(a+1,a+e+1,cmp); 68 for (int i=1;i<=e;i++){ 69 if (!a[i].f) add(a[i].y+1,1); 70 else { 71 ans[a[i].id][a[i].f]=sum(a[i].y+1); 72 } 73 } 74 for (int i=1;i<=m;i++){ 75 printf("%d\n",ans[i][4]-ans[i][3]-ans[i][2]+ans[i][1]); 76 } 77 return 0; 78 }
BZOJ1935: [Shoi2007]Tree 园丁的烦恼
标签:input sed inpu struct ext play namespace com eof
原文地址:http://www.cnblogs.com/SXia/p/6786181.html