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

2299 自己试数据都过,为什么Wrong Answer???(代码比较痴,理解理解)

Posted by 20131518wh at 2011-10-04 17:39:48 on Problem 2299
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<memory>
using namespace std;
long long sum[500100],b[500100],t,cnt;
struct node
{
	int i;
	int z;
}a[500100];
void in()
{
	for(int i=1;i<=t;i++)
	{
		cin>>a[i].z;
		a[i].i=i;
	}
}

int lowbit(int i)
{
	return i&-i;
}
int kk(node x,node y)
{
	return x.z<y.z;
}
void cl()
{
	sort(a+1,a+t+1,kk);
	for(int	ls=1;ls<=t;ls++)
	b[ls]=a[ls].i;
}

void ans()
{
	for(int ls=1;ls<=t;ls++)
	{for(int i=b[ls]-lowbit(b[ls]);i>=1;i-=lowbit(i))
	sum[b[ls]]+=sum[i];
	sum[b[ls]]+=1;
	for(int i=b[ls]+lowbit(b[ls]);i<=t;i+=lowbit(i))
	sum[i]+=1;
	cnt+=(b[ls]-sum[b[ls]]);}
	cout<<cnt<<endl;
	cnt=0;
}

void qk()
{
	memset(sum, 0, sizeof(sum));
	memset(b, 0, sizeof(b));
	memset(a, 0, sizeof(a));
}

int main()
{
	cin>>t;
	while(t!=0)
	{
		in();
		cl();
		ans();
		qk();
		cin>>t;
	}
	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