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. 在做nios ii uart232 实验时出现undefined reference to `fclose'等错误。

    程序如下 #include<stdio.h> #include<string.h> #include "system.h"   int main () { ...

  2. 3.5寸1.44M软盘结构

    结构: 划分: 簇:磁盘驱动器在向磁盘读取和写入数据时,要以扇区为单位.在磁盘上,DOS操作系统是以“簇”为单位为文件分配磁盘空间的.硬盘的簇通常为多个扇区,与磁盘的种类.DOS 版本及硬盘分区的大小 ...

  3. Protocol Buffers学习笔记

    Protocol Buffers学习笔记 1. 简介 Protocol Buffers是google发明的一种数据交换格式,独立于语言,独立于平台.与其他的数据交换格式有所不同,Protocol Bu ...

  4. 以太坊geth区块链私链建立

      以太坊geth区块链私链建立 geth的github https://github.com/ethereum/go-ethereum 下载最新(1.8)的geth,windows下安装很简单 关于 ...

  5. python笔记5 接口类抽象类 封装 反射 设计模式 模块 :random随机数 josn shelve持久化存储

    接口类抽象类 接口类:接口类就是制定一个规则,让其他人按照我的规则去写程序. #!/usr/bin/env python from abc import ABCMeta,abstractmethod ...

  6. 数据分析 - sql 业务相关练习题

    数据库    userinfo , orderinfo 表 两个 userId 彼此对应 题目 解题 不同月份的下单人数 用户在同一个月份会下多个单,这里进行去重 未支付的脏数据去除 统计用户三月份的 ...

  7. spring data jpa实现多条件查询(分页和不分页)

    目前的spring data jpa已经帮我们干了CRUD的大部分活了,但如果有些活它干不了(CrudRepository接口中没定义),那么只能由我们自己干了.这里要说的就是在它的框架里,如何实现自 ...

  8. 如何不让Excel图表随源数据改变而改变

    如何不让Excel图表随源数据改变而改变 一般我们在用Excel时,经常会碰到一些问题,比如,如何才能不让Excel图表随源数据改变而改变呢,下面就谈一下,一般在默认情况下,Excel的图表在一个区域 ...

  9. delphi7 treeview + 数据库 实现动态节点维护

    首先说下树节点对应的表的基本结构,必需要有的字段(节点编号,父节点编号,节点名称),其他字段根据你开发的需要添加从添加节点开始,一开始就取出表中最大节点编号,每次添加节点的时候,该节点编号增加1;添加 ...

  10. OnPreInit,OnInit ,OnInitComplete ,OnPreLoad ,Page_Load等执行顺序

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...