Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2)
A I hate that I love that I hate it水题
#I hate that I love that I hate it
n = int(raw_input())
s = ""
a = ["I hate that ","I love that ", "I hate it","I love it"]
for i in range(n-1):
s+=a[i%2]
s += a[(n-1)%2 +2]
print s
B 有若干堆物体,每堆物体由若干个物体组成,一次操作可以把一堆物体分成两堆。两个人轮流操作,看谁赢。现在一开始没有物体,每次增加一个含有a[i]物体的堆,每次都要问现在这种情况下谁赢。
解:一堆含有x个东西的物体肯定要被切x-1刀,直接算出总共要被切断刀数然后模2就好了。
n = int(raw_input())
a = map(int, raw_input().split())
can_be_cut = 0
for i, x in zip(range(n), a):
can_be_cut += x - 1
print ((can_be_cut % 2)^1) + 1
C 30W个应用,30W条事件。事件有三种。
第一种,x应用发了一个推送。
第二种,查看x应用发的所有推送。
第三种,查看最老的t个推送。(不管有没有读过,都算在t里面,并不是只读最老的t个未读)
每条事件,要输出未读消息数。
解:
就是想办法让它不会到O(n^2),想办法让它每个推送我们只扫一次,不多扫。
首先推送我们全部按顺序记到数组里,各自有读没读过标记read[i]。
我用一个before[i]记录这个位置的推送所属的应用的上一个推送在哪个位置。再用一个last[x]记录每个应用最后一个推送到位置,再用一个already[x]记录每个应用上次全看一遍的时候最后推送到位置。这样,每次第二种操作,我就只用从last[x]一路 before[i]扫到already[x],每个推送最多只扫到一次,总复杂度O(n)。
然后考虑第三种操作,简单的一比,记一个变量firstT用来记之前的第三种操作最多包括到第几个推送。每次只从firstT开始扫,也是每个推送最多扫一遍。和上面的合起来,O(n+n) 还是 O(n)。
(我看错题,以为first t 是指最上面的t个推送,可恶,居然是最老的t个,我的锅)
代码:
//#pragma comment(linker, "/STACK:102400000,102400000")
/**Header!**/ //{
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std; #define MZ(array) memset(array, 0, sizeof(array))
#define MF1(array) memset(array, -1, sizeof(array))
#define MINF(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define ROF(i,x,y) for(i=(x);i>=(y);i--)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define MP make_pair
#define PB push_back
#define PF push_front
#define PPF pop_front
#define PPB pop_back
#define lowbit(x) ((x)&(-x))
#define cindiao ios_base::sync_with_stdio(0)
#define fcout(x,y) cout << fixed << setprecision(x) << (y) << endl
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
template<class T>inline void OA(const T &a,const int &st,const int &ed) {
if(ed>=st)cout<<(a[st]);
int i;
FOR(i,st+,ed)cout<<' '<<(a[i]);
puts("");
}
inline void RDQ(int &x){
char c;
while(!isdigit(c=getchar()));
x=c - '';
while(isdigit(c=getchar())) x = x* +c-'';
}
inline void WIQ(const int &x) {
if(x>=)WIQ(x/);
putchar(x% + '');
} template <class T> inline T quickPow(T p,T e,const T &M) {
LL ret = ;
for(; e > ; e >>= ) {
if(e & ) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T> inline T gcd(const T &a,const T &b) {
return (b==) ? a : gcd(b,a%b);
}
template <class T> inline T niyuan(const T &a, const T &M) {
return quickPow(a,M-,M);
}
template <class T> inline T exgcd(const T &a,const T &b,T &x,T &y) {
if (!b) {
x=,y=;
return a;
}
T ret=exgcd(b,a%b,x,y), t;
t=x,x=y,y=t-a/b*y;
return ret;
}
template <class T> inline T niyuanex(const T &a, const T &M) {
T x,y;
exgcd(a,M,x,y);
return (x+M)%M;
}
inline LL calC(const int &n,int m,const LL &MOD) {
m=(n-m>m)?m:(n-m);
LL up=,down=;
int i;
for(i=; i<=m; i++) {
down*=i;
down%=MOD;
up*=(n-i+);
up%=MOD;
}
return (up*niyuanex(down, MOD))%MOD;
}
inline LL Lucas(const int &n,const int &m, const int &MOD) {
if(m==)return ;
return (1LL * Lucas(n/MOD, m/MOD, MOD)*calC(n%MOD, m%MOD, MOD))%MOD;
}
const int gx[] = {-,,,};
const int gy[] = {,,,-};
const double PI=acos(-1.0);
//}
const double EPS=1e-;
inline int sgn(double &x) {
if(fabs(x) < EPS)return ;
if(x < )return -;
else return ;
}
const int INF=0x3f3f3f3f;
const int NINF=0x80000001;
const int MAXN=;
const int MAXM=;
const int MOD = <<; int n,q;
int before[MAXN],last[MAXN],already[MAXN];
bool read[MAXN];
int unread;
int cnt;
int firstT;
inline int farm(const int &no, const int &type, const int &xx) {
int k;
if(type==) {
before[cnt]=last[xx];
last[xx]=cnt;
unread++;
cnt++;
} else if(type==) {
already[xx] = max(already[xx], firstT-);
for(int i=last[xx]; i>already[xx]; i=before[i]) {
if(!read[i]) {
unread --;
read[i]=true;
}
}
already[xx] = max(already[xx], last[xx]);
} else if(type==) {
int i;
int ed = min(cnt-, xx-);
FOR(i,firstT,ed) {
if(!read[i]) {
unread--;
read[i]=true;
}
}
firstT = max(firstT, ed+);
}
return unread;
} inline void init() {
MF1(last);
MF1(already);
before[] = -;
firstT=;
cnt = ;
unread=;
} int main() {
int i,t,x;
init();
RD2(n,q);
REP(i,q) {
RDQ(t);
RDQ(x);
WIQ(farm(i,t,x));
puts("");
}
return ;
}
Codeforces Round #366 (Div. 2) ABC的更多相关文章
- Codeforces Round #247 (Div. 2) ABC
Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431 代码均已投放:https://github.com/illuz/Wa ...
- Codeforces Round #366 Div.2[11110]
这次出的题貌似有点难啊,Div.1的Standing是这样的,可以看到这位全站排名前10的W4大神也只过了AB两道题. A:http://codeforces.com/contest/705/prob ...
- Codeforces Round #313 (Div. 2) ABC
A http://codeforces.com/contest/560/problem/A 推断给出的数能否组成全部自然数. 水题 int a[1010]; bool b[1000010]; int ...
- Codeforces Round #366 (Div. 2)
CF 复仇者联盟场... 水题 A - Hulk(绿巨人) 输出love hate... #include <bits/stdc++.h> typedef long long ll; co ...
- Codeforces Round #366 (Div. 2) B
Description Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a ...
- Codeforces Round #366 (Div. 2) C 模拟queue
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #366 (Div. 2) B 猜
B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #366 (Div. 2) A
A. Hulk time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Codeforces Round #366 (Div. 2) C Thor(模拟+2种stl)
Thor 题意: 第一行n和q,n表示某手机有n个app,q表示下面有q个操作. 操作类型1:app x增加一条未读信息. 操作类型2:一次把app x的未读信息全部读完. 操作类型3:按照操作类型1 ...
随机推荐
- YII2 载入默认值 loadDefaultValues
本人很懒,所以喜欢找现成的东西来用,所以在载入默认值的时候我直接就选择了Yii2 自带的loadDefaultValues 问题来了,我提交的时候发现我在rules里面设置的default没有工作 [ ...
- Python导出Excel为Lua/Json/Xml实例教程(二):xlrd初体验
Python导出Excel为Lua/Json/Xml实例教程(二):xlrd初体验 相关链接: Python导出Excel为Lua/Json/Xml实例教程(一):初识Python Python导出E ...
- 3.raid基础应用
raid分为软备份和硬备份 软备份主要用来实验 应备份用于生产环境 raid0(带区卷) 具有很高的数据传输率,没有数据的冗余 1块磁盘 raid1(镜像卷) 提供数据冗余,利用率低 2块 ...
- WinXP/Win7/Win8本地用户配置文件迁移至域用户
一.概述 最近在进行加域的工作,PC大部分是Win7,使用过微软USMT 4.0和5.0工具进行迁移,但命令行报错,目前还没找到好的文章研究. 本文迁移方法很特殊,利用的是Windows默认配置文件. ...
- 《明解c语言》已看完,练习代码此奉上
2016年9月20日至2016年11月12日,从学校图书馆借来的<明解c语言>看完了. 大三第一个学期,前8周,有c语言程序设计的课.课本是学校里的老师编写出版的,为了压缩空间,减少页面, ...
- 项目自动化建构工具gradle 入门4——javaWeb在浏览器中显示helloWorld
在java应用中,其实做的最多的还是java web应用.所以现在我们做的就是用gradle构建一个简单的web项目,简单点,直接上代码吧. 1.进入目录D:\work\gradle\web,新建文件 ...
- mysql语句查询练习
1.创建students表mysql> create table ...
- java程序设计之循环链表
照例来说点废话,愿自己生一颗温柔细腻的心,这样女朋友也许一个眼神,一个微笑,我就知道如何做,可惜内心与外表一样粗糙,这一生有幸认识她,愿天下有情人终成眷属. 循环链表,顾名思义循环就好了,所以建一个线 ...
- jQuery获取margin-top和padding-top的值
var bordT = $('img').outerWidth() - $('img').innerWidth(); var paddT = $('img').innerWidth() - $('i ...
- flexbox布局神器
前言 2009年,W3C提出了一种新的方案----Flexbox布局(弹性布局),可以简便.完整.响应式地实现各种页面布局.Flex布局模型不同于块和内联模型布局,块和内联模型的布局计算依赖于块和内联 ...