ARC072
C - Sequence
直接认为一个数是正的,或者第一个数是负的,每次将不合法的负数前缀和改成+1正数前缀和改成-1
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int64 a[MAXN],s[MAXN];
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) read(a[i]);
int64 tmp = 0,ans = 1e18;
for(int i = 1 ; i <= N ; ++i) {
s[i] = s[i - 1] + a[i];
if(i & 1) {
if(s[i] >= 0) {tmp += s[i] + 1;s[i] = -1;}
}
else {
if(s[i] <= 0) {tmp += 1 - s[i];s[i] = 1;}
}
}
ans = min(ans,tmp);
tmp = 0;
for(int i = 1 ; i <= N ; ++i) {
s[i] = s[i - 1] + a[i];
if(i & 1) {
if(s[i] <= 0) {tmp += 1 - s[i];s[i] = 1;}
}
else {
if(s[i] >= 0) {tmp += s[i] + 1;s[i] = -1;}
}
}
ans = min(ans,tmp);
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
D - Alice&Brown
做atc的博弈论就像挖金子,你挖到了之后才知道它埋得有多浅,而你挖到之前,都刨过好几个天坑了= =
必败策略就是\(X\)和\(Y\)相差不超过1!!!
其余都必胜
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int64 X,Y;
void Solve() {
read(X);read(Y);
if(abs(X - Y) <= 1) {
puts("Brown");
}
else {
puts("Alice");
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
E - Alice in linear land
我们按照序列递推一遍,得到每个初始指令进行后这个位置的值,询问一个p,设某个位置的值是\(f[p]\),我们就找一个小于等于\(f[p - 1]\)的值,使得\(p + 1,N\)里剩下的数无法使这个数到达终点
反着递推就很简单了,设\(b[i]\)为后i个位置保证\(1 - b[i]\)可以达到的最大\(b[i]\),那么新加一个数\(a[i - 1]\),我们得到\([a[i - 1] - b[i],a[i - 1] + b[i] ]\)都是可以到达的,我们只要满足\(b[i] + 1 >= a[i - 1] - b[i]\),我们就可以用\(a[i - 1] + b[i]\)来更新\(b[i - 1]\)了
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 500005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,D,Q;
int a[MAXN],b[MAXN],f[MAXN];
void Solve() {
read(N);read(D);
for(int i = 1 ; i <= N ; ++i) read(a[i]);
for(int i = N ; i >= 1 ; --i) {
if(a[i] - b[i + 1] <= b[i + 1] + 1) b[i] = a[i] + b[i + 1];
else b[i] = b[i + 1];
}
f[0] = D;
for(int i = 1 ; i <= N ; ++i) {
f[i] = min(abs(f[i - 1] - a[i]),f[i - 1]);
}
read(Q);
int p;
for(int i = 1 ; i <= Q ; ++i) {
read(p);
if(f[p - 1] > b[p + 1]) puts("YES");
else puts("NO");
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
F - Dam
把一个点转化为一个向量\((v_i,t_i \times v_i)\)
然后就变成了每次在队列后加一个向量,不断删前面的序列使得向量的终点的x = L
然后从新加的点开始两两合并向量直到形成一个凸包
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 500005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
struct Point {
double x,y;
Point(double _x = 0,double _y = 0) {
x = _x;y = _y;
}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x + b.x,a.y + b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x - b.x,a.y - b.y);
}
friend double operator * (const Point &a,const Point &b) {
return a.x * b.y - a.y * b.x;
}
}que[MAXN];
int N,ql,qr;
double L,sum;
void Solve() {
read(N);scanf("%lf",&L);
double t,v;
for(int i = 1 ; i <= N ; ++i) {
scanf("%lf%lf",&t,&v);
que[++qr] = Point(v,t * v);
sum += t * v;
double dec = 0;
if(i != 1) {
while(1) {
if(dec >= v) break;
if(que[ql].x <= v - dec) {
dec += que[ql].x;
sum -= que[ql].y;
++ql;
}
else {
sum -= que[ql].y;
que[ql].y -= que[ql].y / que[ql].x * (v - dec);
que[ql].x -= v - dec;
sum += que[ql].y;
break;
}
}
}
printf("%.7lf\n",sum / L);
while(ql <= qr - 1) {
if(que[qr] * que[qr - 1] >= -1e-8) {
que[qr - 1] = que[qr] + que[qr - 1];
--qr;
}
else break;
}
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}