2018 Multi-University Training Contest 2(杭电多校2)

G

Swaps and Inversions

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1486    Accepted Submission(s): 539


 

Problem Description

Long long ago, there was an integer sequence a.
Tonyfang think this sequence is messy, so he will count the number of inversions in this sequence. Because he is angry, you will have to pay x yuan for every inversion in the sequence.
You don't want to pay too much, so you can try to play some tricks before he sees this sequence. You can pay y yuan to swap any two adjacent elements.
What is the minimum amount of money you need to spend?
The definition of inversion in this problem is pair (i,j) which 1≤i<j≤n and ai>aj.

 

 

Input

There are multiple test cases, please read till the end of input file.
For each test, in the first line, three integers, n,x,y, n represents the length of the sequence.
In the second line, n integers separated by spaces, representing the orginal sequence a.
1≤n,x,y≤100000, numbers in the sequence are in [−109,109]. There're 10 test cases.

 

 

Output

For every test case, a single integer representing minimum money to pay.

 

 

Sample Input

 

3 233 666 1 2 3 3 1 666 3 2 1

 

 

Sample Output

 

0 3

 

 

Source

2018 Multi-University Training Contest 2

思路:可以想到线段树来维护区间,但如何每个数加到b[i]就会所在区间贡献加一,那么我们自然可以想到区间最小值来减少操作,当我们每次增加区间的值时,我们可以让这段区间最小值减一。当区间最小值减少到零时,我们就找最小值所在的位置,然后给他重新赋值为b[i],并让他所在区间的sum值加一。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;

struct node{
    int mi,add,sum;
}a[N*4];

int n,m,b[N];

void pushup(int rt)        //更新mi和sum 
{
    a[rt].mi = min(a[rt<<1].mi, a[rt<<1|1].mi);
    a[rt].sum = a[rt<<1].sum + a[rt<<1|1].sum;
}
void pushdown(int rt)    //更新add标记 
{
    a[rt<<1].add+=a[rt].add;
    a[rt<<1|1].add+=a[rt].add;
    
    a[rt<<1].mi+=a[rt].add;
    a[rt<<1|1].mi+=a[rt].add;
    a[rt].add=0;					//多组输入,这步不能省。 
}
void build(int l,int r,int rt)
{
    if(l==r)
    {
        a[rt].sum=0;a[rt].add=0;a[rt].mi=b[l];return ;
    }
    int mid=(l+r)>>1;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    pushup(rt);
	a[rt].add=0;
}
void update(int L,int R,int l,int r,int rt,int k)
{
    if(L<=l&&r<=R)
    {
        if(k)
        {
            a[rt].add--;
            a[rt].mi--;
        }
        if(a[rt].mi>0) return ;
        if(l==r)
        {
            if(a[rt].mi==0)
            {
                a[rt].sum++;a[rt].mi=b[l];
            }
            return ;    
        }
        k=0;
    }
    pushdown(rt);
    int mid=(l+r)>>1;
    if(L<=mid) update(L,R,l,mid,rt<<1,k);
    if(R>mid) update(L,R,mid+1,r,rt<<1|1,k);
    pushup(rt);
}
int query(int L,int R,int l,int r,int rt)
{
    if(L<=l&&r<=R) return a[rt].sum;
    int mid=(l+r)>>1,ans=0;
    if(L<=mid) ans+=query(L,R,l,mid,rt<<1);
    if(R>mid) ans+=query(L,R,mid+1,r,rt<<1|1);
    return ans;
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(int i=1;i<=n;i++)scanf("%d",&b[i]);
        build(1,n,1);
        while(m--)
        {
            char s[10];
            int x,y;
            scanf("%s %d %d",s,&x,&y);
            if(s[0]=='q')
            {
                printf("%d\n",query(x,y,1,n,1));
            }
            else
            {
                update(x,y,1,n,1,1);
            }
        }
    }
    return 0;
}

 

Swaps and Inversions

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1513    Accepted Submission(s): 553


 

Problem Description

Long long ago, there was an integer sequence a.
Tonyfang think this sequence is messy, so he will count the number of inversions in this sequence. Because he is angry, you will have to pay x yuan for every inversion in the sequence.
You don't want to pay too much, so you can try to play some tricks before he sees this sequence. You can pay y yuan to swap any two adjacent elements.
What is the minimum amount of money you need to spend?
The definition of inversion in this problem is pair (i,j) which 1≤i<j≤n and ai>aj.

 

 

Input

There are multiple test cases, please read till the end of input file.
For each test, in the first line, three integers, n,x,y, n represents the length of the sequence.
In the second line, n integers separated by spaces, representing the orginal sequence a.
1≤n,x,y≤100000, numbers in the sequence are in [−109,109]. There're 10 test cases.

 

 

Output

For every test case, a single integer representing minimum money to pay.

 

 

Sample Input

 

3 233 666 1 2 3 3 1 666 3 2 1

 

 

Sample Output

 

0 3

 

 

其实就是求逆序数然后乘上min(x,y)。这里用树状数组求得逆序数。

树状数组求逆序数真是妙啊。

大概就是按照给的顺序插入到一个序列,边插入边找比当前元素大的数的个数。

因为数据太大需要离散化,重新编号,注意相同的数字编号相同。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll lowbit(ll x)
{
	return x&-x;
}
ll min(ll x,ll y)
{
	if(x<y) return x;return y;
}
ll n;
ll a[1000006];
ll num=0;
ll add(ll x,ll k)
{
	while(x<=n)
	{
		a[x]+=k;
		x+=lowbit(x);
	}
}
ll Sum(ll x)
{
	ll sum=0;
	while(x>0)
	{
		sum+=a[x];
		x-=lowbit(x);
	}
	return sum;
}
struct node{
	ll pos,val;
}b[1000006];
ll cmp(node q,node w)
{
	return q.val<w.val;
}
ll l[1000006];
int main()
{
	ll x,y;
	while(~scanf("%lld %lld %lld",&n,&x,&y))
	{
		memset(a,0,sizeof(a));
		memset(l,0,sizeof(l));
		num=0;
		for(ll i=1;i<=n;i++)
		{
			ll p;
			scanf("%lld",&b[i].val);b[i].pos=i;
		}
		sort(b+1,b+n+1,cmp);
		int cnt=0;
		for(ll i=1;i<=n;i++)
		{
			if(b[i].val!=b[i-1].val)
			l[b[i].pos]=++cnt;
			else l[b[i].pos]=cnt;
		}
		for(ll i=1;i<=n;i++)
		{
			num+=(i-Sum(l[i])-1);			//统计当前序列大于l[i]的元素。 
			add(l[i],1);
		}
		printf("%lld\n",num*min(x,y));
	}
	return 0;
}

 

内容概要:本文档详细介绍了Analog Devices公司生产的AD8436真均方根-直流(RMS-to-DC)转换器的技术细节及其应用场景。AD8436由三个独立模块构成:轨到轨FET输入放大器、高动态范围均方根计算内核和精密轨到轨输出放大器。该器件不仅体积小巧、功耗低,而且具有广泛的输入电压范围和快速响应特性。文档涵盖了AD8436的工作原理、配置选项、外部组件选择(如电容)、增益调节、单电源供电、电流互感器配置、接地故障检测、三相电源监测等方面的内容。此外,还特别强调了PCB设计注意事项和误差源分析,旨在帮助工程师更好地理解和应用这款高性能的RMS-DC转换器。 适合人群:从事模拟电路设计的专业工程师和技术人员,尤其是那些需要精确测量交流电信号均方根值的应用开发者。 使用场景及目标:①用于工业自动化、医疗设备、电力监控等领域,实现对交流电压或电流的精准测量;②适用于手持式数字万用表及其他便携式仪器仪表,提供高效的单电源解决方案;③在电流互感器配置中,用于检测微小的电流变化,保障电气安全;④应用于三相电力系统监控,优化建立时间和转换精度。 其他说明:为了确保最佳性能,文档推荐使用高质量的电容器件,并给出了详细的PCB布局指导。同时提醒用户关注电介质吸收和泄漏电流等因素对测量准确性的影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值