ARC069

C - Scc Puzzle

……不说了

#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 1005
//#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 N,M;
void Solve() {
read(N);read(M);
if(N * 2 >= M) {out(M / 2);enter;}
else {out(N + (M - N * 2) / 4);enter;}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

D - Menagerie

容易发现固定两位后可以推出所有,枚举一下前两位是啥就行

#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;
char s[MAXN];
int num[MAXN];
void Solve() {
read(N);
scanf("%s",s);
for(int i = 0 ; i <= 1 ; ++i) {
for(int j = 0 ; j <= 1 ; ++j) {
num[0] = i;num[1] = j;
for(int k = 2 ; k < N ; ++k) {
num[k] = (s[k - 1] == 'x') ^ num[k - 2] ^ num[k - 1];
}
int t0 = num[N - 1] ^ num[1] ^ num[0] ^ (s[0] == 'x');
int tN = num[0] ^ num[N - 2] ^ num[N - 1] ^ (s[N - 1] == 'x');
if(t0 == 0 && tN == 0) {
for(int i = 0 ; i < N ; ++i) {
if(num[i] == 0) putchar('S');
else putchar('W');
}
enter;
return;
}
}
}
puts("-1");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

E - Frequency

显然只有前缀最大值改变的位置会被统计

统计的方法是若从a变到b,我把b及以后所有的数大于a的全削成a是b的次数,统计起来可以直接把大于a的数全削成a,减去下一个位置大于b的数全削成b的次数

#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],b[MAXN],pre[MAXN],ans[MAXN];
map<int,int64> zz,num;
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {read(a[i]);b[i] = a[i];ans[1] += a[i];}
sort(b + 1,b + N + 1);
for(int i = N ; i >= 1 ; --i) { if(b[i] != b[i + 1]) {
num[b[i]] += N - i;
zz[b[i]] += zz[b[i + 1]];
}
num[b[i]]++;
zz[b[i]] += b[i];
}
int pos = 1;
for(int i = 1 ; i <= N ; ++i) {
if(a[i] > pre[i - 1] && i != 1) {
ans[i] += zz[pre[i - 1]] - pre[i - 1] * num[pre[i - 1]];
ans[pos] -= ans[i];
pos = i;
}
pre[i] = max(pre[i - 1],a[i]);
}
for(int i = 1 ; i <= N ; ++i) {
out(ans[i]);enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

F - Flags

大意是N个旗子可以放两个位置,设d是旗子之间最小的间距,d最大是多少

很套路。。。直接线段树优化建图跑2-SAT

#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);
}
struct tr_node {
int l,r,lc,rc;
}tr[MAXN * 10];
struct node {
int to,next;
}E[MAXN * 100];
int sumE,head[MAXN * 10];
int Ncnt,N;
pii val[MAXN * 2];
int p[MAXN][2],pos[MAXN],rt,x[MAXN][2],tot;
void add(int u,int v) {
E[++sumE].to = v;
E[sumE].next = head[u];
head[u] = sumE;
}
void build(int &u,int l,int r) {
u = ++Ncnt;
tr[u].l = l;tr[u].r = r;
if(l == r) {pos[l] = u;return;}
int mid = (l + r) >> 1;
build(tr[u].lc,l,mid);
build(tr[u].rc,mid + 1,r);
add(u,tr[u].lc);add(u,tr[u].rc);
} void Add_Range(int u,int l,int r,int v) {
if(l > r) return;
if(tr[u].l == l && tr[u].r == r) {add(v,u);return;}
int mid = (tr[u].l + tr[u].r) >> 1;
if(r <= mid) Add_Range(tr[u].lc,l,r,v);
else if(l > mid) Add_Range(tr[u].rc,l,r,v);
else {Add_Range(tr[u].lc,l,mid,v);Add_Range(tr[u].rc,mid + 1,r,v);}
}
int findL(int v) {
int l = 1,r = tot;
while(l < r) {
int mid = (l + r) >> 1;
if(x[val[mid].fi][val[mid].se] >= v) r = mid;
else l = mid + 1;
}
return l;
}
int findR(int v) {
int l = 1,r = tot;
while(l < r) {
int mid = (l + r + 1) >> 1;
if(x[val[mid].fi][val[mid].se] <= v) l = mid;
else r = mid - 1;
}
return l;
}
int dfn[MAXN * 10],low[MAXN * 10],sta[MAXN * 10],top,col[MAXN * 10],idx,instack[MAXN * 10],cor;
void Tarjan(int u) {
dfn[u] = low[u] = ++idx;
sta[++top] = u;
instack[u] = 1;
for(int i = head[u] ; i ; i = E[i].next) {
int v = E[i].to;
if(!dfn[v]) {
Tarjan(v);
low[u] = min(low[u],low[v]);
}
else if(instack[v] == 1) {
low[u] = min(low[u],dfn[v]);
}
}
if(low[u] == dfn[u]) {
++cor;
while(1) {
int x = sta[top--];
col[x] = cor;
instack[x] = 2;
if(x == u) break;
}
}
}
bool check(int d) {
Ncnt = 0,sumE = 0;
memset(head,0,sizeof(head));
build(rt,1,tot);
for(int i = 1 ; i <= tot ; ++i) {
int u = pos[i];
p[val[i].fi][val[i].se ^ 1] = u;
}
for(int i = 1 ; i <= tot ; ++i) {
int a,b;
a = findL(x[val[i].fi][val[i].se] - d + 1);
b = findR(x[val[i].fi][val[i].se] + d - 1);
Add_Range(1,a,i - 1,p[val[i].fi][val[i].se]);
Add_Range(1,i + 1,b,p[val[i].fi][val[i].se]);
}
idx = 0;top = 0;cor = 0;
memset(dfn,0,sizeof(dfn));memset(low,0,sizeof(low));
memset(col,0,sizeof(col));memset(instack,0,sizeof(instack));
for(int i = 1 ; i <= N ; ++i) {
if(!dfn[i]) Tarjan(i);
}
for(int i = 1 ; i <= N ; ++i) {
if(col[p[i][0]] == col[p[i][1]]) return false;
}
return true;
}
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {
read(x[i][0]);read(x[i][1]);
val[++tot] = mp(i,0);val[++tot] = mp(i,1);
}
sort(val + 1,val + tot + 1,[](pii a,pii b){return x[a.fi][a.se] < x[b.fi][b.se];});
int l = 0,r = 1000000000;
while(l < r) {
int mid = (l + r + 1) >> 1;
if(check(mid)) l = mid;
else r = mid - 1;
}
out(l);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

【AtCoder】ARC069的更多相关文章

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. About Grisha N. ( URAL - 2012 )

    Problem Grisha N. told his two teammates that he was going to solve all given problems at the subreg ...

  2. scrapy框架之shell

    scrapy shell scrapy shell是一个交互式shell,您可以在其中快速调试 scrape 代码,而不必运行spider.它本来是用来测试数据提取代码的,但实际上您可以使用它来测试任 ...

  3. 感知机与BP神经网络的简单应用

    感知机与神经元 感知机(Perceptron)由两层神经元组成(输入层.输出层),输入层接收外界输入信号后传递给输出层,输出层是M-P神经元,亦称“阈值逻辑单元”(threshold logic un ...

  4. XMLHttpRequest Level2 新功能

    XMLHttpRequest是浏览器的接口,使得javascript可以进行HTTP(S)通信: 2008年2月,就提出了XMLHttpRequest Level 2 草案. 这个XMLHttpReq ...

  5. es搭建过程会存在的问题 针对6.x

    常见的四个基本错误 错误1 can not run elasticsearch as root 解决方案: 因为安全问题elasticsearch 不让用root用户直接运行,所以要创建新用户 第一步 ...

  6. js闭包小实验

    js闭包小实验 一.总结 一句话总结: 闭包中引用闭包外的变量会使他们常驻内存 function foo() { var i=0; return function () { console.log(i ...

  7. 五一 DAY 5

    五一  DAY 5 V  点  1----n E  边 /* Given a graph with N nodes and M unidirectional edges. Each edge e_i ...

  8. UML期末复习题——2.8:UML Design Class Diagram(DCD)

    第八题:设计类图 重要概念: 1. 类图(Class Diagram): 类图是面向对象系统建模中最常用和最重要的图,是定义其它图的基础.类图主要是用来显示系统中的类.接口以及它们之间的静态结构和关系 ...

  9. Node.js与VUE安装及环境配置之Windows篇

    Node.js安装及环境配置之Windows篇 https://www.cnblogs.com/zhouyu2017/p/6485265.html Node.js安装及环境配置之Windows篇htt ...

  10. 西湖论剑2019部分writeup

    做了一天水了几道题发现自己比较菜,mfc最后也没怼出来,被自己菜哭 easycpp c++的stl算法,先读入一个数组,再产生一个斐波拉契数列数组 main::{lambda(int)#1}::ope ...