可惜没如果=_=
时光的河入海流
Problem 2134 上车

Accept: 218    Submit: 280
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

有N个人排成一队按顺序上车,座位在前排并且排在队伍前面的人上车后会对座位在后面并且排他在后面的人造成阻碍。现给出每个人坐在第几排,假设这辆车有100排,每一排有100个座位。定义每个人的上车困难度为比这个人先上车并且座位在其前排的人数。问N个人的上车困难度之和。

Input

第一行一个整数T(T<=100),表示有T组数据。

 

每组数据先输入一行一个整数N(1<=N<=100),表示人数,接下来一行输入N个不超过100的正整数,输入的第i个数Ai表示第i个上车的人的座位是第Ai排。

Output

每组数据对应一行输出,即N个人上车的困难度之和。

Sample Input

3 3 1 2 3 3 3 2 1 3 1 2 2

Sample Output

3 0 2 
并不知道刷水题有什么用ovo
 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 typedef long long LL;
 4 const int MAX=105;
 5 int cas;
 6 int n;
 7 int c[MAX];
 8 void add(int x,int y){for (;x<=MAX;c[x]+=y,x+=(x&-x));}
 9 int search(int x){int an(0);for (;x>0;an+=c[x],x-=(x&-x));return an;}
10 int main(){
11     freopen ("bus.in","r",stdin);
12     freopen ("bus.out","w",stdout);
13     int i,j,k;
14     scanf("%d",&cas);
15     while (cas--){
16         int ans(0);
17         scanf("%d",&n);
18         memset(c,0,sizeof(c));
19         for (i=1;i<=n;i++){
20             scanf("%d",&k);
21             ans+=search(k-1);
22             add(k,1);
23         }
24         printf("%d\n",ans);
25     }
26     return 0;
27 }
看吧看吧,反正是水题

 

posted on 2016-11-12 18:13  珍珠鸟  阅读(215)  评论(0编辑  收藏  举报