9.26 杂题选讲

这次是真的难度良心了。

T1

由于太水了,直接放个代码。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=1000100;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(register int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(register int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	char ch=getchar();int x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
struct item{
	int v,p;
	bool operator<(const item &i)const{return v<i.v;}
}it[maxn];
int n,a[maxn],sz,bit[33],bl;
ll b[maxn];
__int128 ans;
void update(int p,ll v){
	while(p<=sz) b[p]+=v,p+=p&-p; 
}
ll query(int p){
	ll s=0;
	while(p) s+=b[p],p-=p&-p;
	return s;
}
void print(__int128 x){
	if(!x) return void(puts("0"));
	bl=0;
	while(x) bit[++bl]=x%10,x/=10;
	while(bl) putchar(bit[bl--]+'0');
}
int main(){
	n=read();
	FOR(i,1,n) it[i]=(item){a[i]=read(),i};
	sort(it+1,it+n+1);
	FOR(i,1,n){
		if(i==1 || it[i].v!=it[i-1].v) sz++;
		a[it[i].p]=sz;
	}
	ROF(i,n,1){
		ans+=(__int128)query(a[i]-1)*i;
		update(a[i],n-i+1);
	}
	print(ans);
}

T2

这里

看到这里的 dalao 们,求证明复杂度……

T3

这里

T4

之前写过。

一开始写了个不完全正确的做法,现在改了。

T5

在路上了。

posted @ 2019-09-26 21:19  ATS_nantf  阅读(155)  评论(0编辑  收藏  举报