A
不会
B
两两组合4种情况.
C
应该可以容斥.
但是还是状压
D
P
DP
DP比较好写.
定义
0
0
0表示1,定义
9
9
9表示2,其他表示
0
0
0.
然后数组开
f
[
n
]
[
4
]
f[n][4]
f[n][4]…
D
比较sb的背包,菜逼我想歪了很久.
直接定义
f
[
i
]
]
[
j
]
f[i]][j]
f[i]][j]表示前
i
i
i个数和为
j
j
j就行.
E
扫描线sb做法.
直接按
x
x
x排一下序,然后
y
y
y离散化一下.
用树状数组维护一个正反最大值即可.
#include<bits/stdc++.h>
#define fi first
#define se second
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define IT iterator
#define vi vector<int>
#define TP template<class o>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20,mod=(int)1e9+7,inf=2e9;
//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
char c=gc; x=0; int f=1;
while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
while(isdigit(c)) x=x*10+c-'0',c=gc;
x*=f;
}
template<class o> void qw(o x) {
if(x/10) qw(x/10);
putchar(x%10+'0');
}
template<class o> void pr1(o x) {
if(x<0)x=-x,putchar('-');
qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
if(x<0)x=-x,putchar('-');
qw(x); putchar('\n');
}
int n;
ll ans;
ll power(ll a,ll b=mod-2) {
ll c=1;
while(b) {
if(b&1) c=c*a%mod;
b /= 2; a=a*a%mod;
}
return c;
}
void ad(ll &x,ll y) {x=(x+y)%mod;}
struct rec {
int x,y;
bool operator <(rec b) const {return x<b.x;}
} a[N];
struct BIT {
ll c[N];
BIT() {memset(c,-63,sizeof c);}
void add(int x,ll y) {for( ;x<=n;x+=x&-x) c[x]=max(c[x],y);}
ll ask(int x) {ll y=c[0]; for( ;x;x-=x&-x) y=max(y,c[x]);return y; }
} u,v;
int y[N];
int find(int x) {return lower_bound(y+1,y+n+1,x)-y;}
int main() {
qr(n);
for(int i=1;i<=n;i++) {
qr(a[i].x); qr(a[i].y);
y[i]=a[i].y;
}
sort(y+1,y+n+1);
sort(a+1,a+n+1);
for(int i=1;i<=n;i++) {
int x=a[i].x,y=a[i].y,id=find(y);
ans=max(ans,u.ask(id)+y+x);
ans=max(ans,v.ask(n-id+1)-y+x);
u.add(id,-x-y);
v.add(n-id+1,-x+y);
}
pr2(ans);
return 0;
}
其实
x
,
y
x,y
x,y正负各两种情况,我们维护4种情况的最值即可.
总复杂度
O
(
n
)
O(n)
O(n).
F
直接
r
e
v
e
r
s
e
reverse
reverse一下
b
b
b.
那么可能有一段
b
b
b和
a
a
a相同.
这个时候只要尽量把其他位置的交换进来即可.
正确性证明:
外面的两个位置再交换不一定合法.
所以我们只用考虑把内部交换到外面.
int n,a[N],b[N],cnt,tot;
int main() {
qr(n);
for(int i=1;i<=n;i++) qr(a[i]);
for(int i=1;i<=n;i++) qr(b[n-i+1]);
int l=1,r=n,st=0,ed=-1;
for(int i=1;i<=n;i++)
if(a[i]==b[i]) {
if(!st) st=i;
ed=i;
}
for(int j=st;j<=ed;j++) {
if(a[l]^b[j]&&b[l]^b[j]) swap(b[j],b[l++]);
else if(a[r]^b[j]&&b[r]^b[j]) swap(b[j],b[r--]);
else puts("No"),exit(0);
}
puts("Yes");
for(int i=1;i<=n;i++) pr1(b[i]);
return 0;
}