Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:好吧,我来个线段树版本的吧,勿喷!!!

Posted by zjh461682551 at 2018-12-20 15:53:28 on Problem 1804
In Reply To:好吧,我来个线段树版本的吧,勿喷!!! Posted by:Panamera at 2014-04-18 18:11:25
> #include<stdio.h>
> #include<algorithm>
> #define lson l,m,rt<<1
> #define rson m+1,r,rt<<1|1
> #define MAX_N 1100
> using namespace std;
> int tree[MAX_N<<2],arr[MAX_N],s[MAX_N];
> int query(int val,int l,int r,int rt)
> {
>     ++tree[rt];
>     if(l==r)
>         return 0;
>     int m = l + ( r - l ) / 2 ;
>     return val <= s[m] ? query(val,lson)+tree[rt<<1|1] : query(val,rson);
> }
> int main()
> {
>     int t;
>     scanf("%d",&t);
>     for(int i=1;i<=t;++i)
>     {
>         int n ;
>         scanf("%d",&n);
>         for(int j=0;j<n;++j)
>         {
>             scanf("%d",arr+j);
>             s[j] = arr[j] ;
>         }
>         sort(s,s+n);
>         int len = unique(s,s+n) - s ;
>         int res = 0 ;
>         for(int j=0;j<n;++j)
>             res +=query(arr[j],0,len-1,1);
>         printf("Scenario #%d:\n%d\n\n",i,res);
>         fill(tree,tree+n*4,0);
>     }
>     return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator