标签:tle title date mis BMI url field case contains
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9118 Accepted Submission(s): 3840
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define LL long long 4 #define inf 0x3f3f3f3f 5 #define pb push_back 6 #define mid ((L+R)>>1) 7 const int maxn=100010; 8 int a[maxn],root[maxn],N,tot; 9 int l[maxn],r[maxn],h[maxn]; 10 vector<int>vi; 11 struct node{int lc,rc,sum;}T[maxn*40]; 12 int getid(int x){return lower_bound(vi.begin(),vi.end(),x)-vi.begin()+1;} 13 void update(int &x,int y,int L,int R,int d){ 14 T[++tot]=T[y],T[tot].sum++,x=tot; 15 if(L==R)return; 16 if(d<=mid) update(T[x].lc,T[y].lc,L,mid,d); 17 else update(T[x].rc,T[y].rc,mid+1,R,d); 18 } 19 int query(int x,int L,int R,int d){ 20 if(L==R) return T[x].sum; 21 if(d<=mid) return query(T[x].lc,L,mid,d); 22 else return T[T[x].lc].sum+query(T[x].rc,mid+1,R,d); 23 } 24 int main(){ 25 int t,q,cas=0; 26 cin>>t; 27 while(t--){ 28 tot=0; 29 vi.clear(); 30 scanf("%d%d",&N,&q); 31 for(int i=1;i<=N;++i) scanf("%d",a+i),vi.pb(a[i]); 32 printf("Case %d:\n",++cas); 33 for(int i=1;i<=q;++i){ 34 scanf("%d%d%d",l+i,r+i,h+i); 35 vi.pb(h[i]); 36 } 37 sort(vi.begin(),vi.end()),vi.erase(unique(vi.begin(), vi.end()),vi.end()); 38 for(int i=1;i<=N;++i) update(root[i],root[i-1],1,N+q,getid(a[i])); 39 for(int i=1;i<=q;++i) h[i]=getid(h[i]),printf("%d\n",query(root[r[i]+1],1,N+q,h[i])-query(root[l[i]],1,N+q,h[i])); 40 } 41 return 0; 42 }
标签:tle title date mis BMI url field case contains
原文地址:https://www.cnblogs.com/zzqc/p/9381408.html