hdu多校 2

。。。 后面四个小时都在挂机很难受。

1010

裸的逆序对

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
inline void sub(ll &a,ll b){a-=b;if(a<)a+=mod;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll qp(ll a,ll b){ll ans=;while(b){if(b&)ans=ans*a%mod;a=a*a%mod,b>>=;}return ans;} using namespace std; const double eps=1e-;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=+,maxn=+,inf=0x3f3f3f3f; struct BIT{
ll sum[N];
void add(int i,int v)
{
for(;i<N;i+=i&(-i))sum[i]+=v;
}
ll query(int i)
{
ll ans=;
for(;i;i-=i&(-i))ans+=sum[i];
return ans;
}
}b;
int Hash[N],a[N];
int main()
{
int n,x,y;
while(~scanf("%d%d%d",&n,&x,&y))
{
memset(b.sum,,sizeof b.sum);
int cnt=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
Hash[cnt++]=a[i];
}
sort(Hash,Hash+cnt);
cnt=unique(Hash,Hash+cnt)-Hash;
ll ans=;
for(int i=;i<=n;i++)
{
a[i]=lower_bound(Hash,Hash+cnt,a[i])-Hash+;
// printf("%d ",a[i]);
b.add(a[i],);
ans+=b.query(cnt+)-b.query(a[i]);
}
// puts("");
printf("%lld\n",ans*min(x,y));
}
return ;
}
/******************** ********************/

1004

因为1的存在所以先手必胜

1007

因为序列b为 1, 2, 3, 4, 5, 6 .... n, 所以所有点的更新次数不超过 m/1 + m/2 + m/3 .... + m/n = mlogm,

所以就是暴力扣出要更新的点更新就好啦。 天天写搓lazy,反思一下。。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = 1e5 + ;
const int M = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; int n, q, b[N], mx[N << ], lazy[N << ], stk[N], tot;
char s[N]; struct BIT {
int a[N];
void init() {
memset(a, , sizeof(a));
}
void modify(int x, int v) {
for(int i = x; i <= n; i += i & -i)
a[i] += v;
}
int query(int x) {
int ans = ;
for(int i = x; i; i -= i & -i)
ans += a[i];
return ans;
}
} bit; void build(int l, int r, int rt) {
lazy[rt] = ;
if(l == r) {
mx[rt] = -b[l];
return;
} int mid = l + r >> ;
build(l, mid, rt << );
build(mid + , r, rt << | );
mx[rt] = max(mx[rt << ], mx[rt << | ]);
} void pushdown(int rt) {
if(lazy[rt] != ) {
lazy[rt << ] += lazy[rt];
lazy[rt << | ] += lazy[rt];
mx[rt << ] += lazy[rt];
mx[rt << | ] += lazy[rt];
lazy[rt] = ;
}
} void update(int L, int R, int v, int l, int r, int rt) {
if(l >= L && r <= R) {
lazy[rt] += v;
mx[rt] += v;
return;
} int mid = l + r >> ; pushdown(rt); if(L <= mid) update(L, R, v, l, mid, rt << );
if(R > mid) update(L, R, v, mid + , r, rt << | ); mx[rt] = max(mx[rt << ], mx[rt << | ]);
} void solve(int l, int r, int rt) {
if(mx[rt] < ) return;
if(l == r) {
stk[tot++] = l;
return;
} int mid = l + r >> ;
pushdown(rt); solve(l, mid, rt << );
solve(mid + , r, rt << | ); } int main() { while(scanf("%d%d", &n, &q) != EOF) {
bit.init();
for(int i = ; i <= n; i++) {
scanf("%d", &b[i]);
}
build(, n, ); while(q--) {
int l, r;
scanf("%s%d%d", s, &l, &r);
if(s[] == 'a') {
update(l, r, , , n, );
tot = ;
solve(, n, ); for(int i = ; i < tot; i++) {
update(stk[i], stk[i], -b[stk[i]], , n, );
bit.modify(stk[i], );
} } else {
printf("%d\n", bit.query(r) - bit.query(l - ));
}
}
}
return ;
} /*
*/

补题-----------------------------------------------------------------

1005

比赛的时候一直构造不出来。。 很神奇的构造方法。。。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = + ;
const int M = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; int a[N][N]; int main() { int p = ;
for(int i = ; i < p; i++) {
for(int j = ; j < p; j++) {
for(int k = ; k < p; k++) {
a[i * p + j][k * p + (j * k + i) % p] = ;
}
}
} puts("");
for(int i = ; i < ; i++) {
for(int j = ; j < ; j++) {
printf("%d", a[i][j]);
}
puts("");
}
return ;
} /*
*/

1003

后面一直在写这个题, 构造虚拟点,去掉多余的边,方法都想出来了,可能是对欧拉回路不够了解,一直没a,后来队友补了。

上一篇:Mysql安装(绿色版安装)


下一篇:Bug跟踪方法