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的更多相关文章

  1. Codeforces Round #247 (Div. 2) ABC

    Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431  代码均已投放:https://github.com/illuz/Wa ...

  2. Codeforces Round #366 Div.2[11110]

    这次出的题貌似有点难啊,Div.1的Standing是这样的,可以看到这位全站排名前10的W4大神也只过了AB两道题. A:http://codeforces.com/contest/705/prob ...

  3. Codeforces Round #313 (Div. 2) ABC

    A http://codeforces.com/contest/560/problem/A 推断给出的数能否组成全部自然数. 水题 int a[1010]; bool b[1000010]; int ...

  4. Codeforces Round #366 (Div. 2)

    CF 复仇者联盟场... 水题 A - Hulk(绿巨人) 输出love hate... #include <bits/stdc++.h> typedef long long ll; co ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #366 (Div. 2) B 猜

    B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #366 (Div. 2) A

    A. Hulk time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  9. 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 ...

随机推荐

  1. 前端小菜鸟的Mobile之旅---开篇

          背景:前段时间有幸参与了公司一个基于H5的手机APP项目,(我们用的React+ES6+Webpack+Cordova开发),由此开始接触一些关于H5开发手机APP方面的知识,下面Shar ...

  2. struts2基础学习--环境配置(*原创)

    1) -->下载开发包,网址:http://struts.apache.org/download.cgi 本文使用的是struts-2.5.2-all开发包 2) -->导入jar包,具体 ...

  3. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  4. [No00008F]PLSQL自动登录,记住用户名密码&日常使用技巧

    配置启动时的登录用户名和密码 这是个有争议的功能,因为记住密码会给带来数据安全的问题. 但假如是开发用的库,密码甚至可以和用户名相同,每次输入密码实在没什么意义,可以考虑让PLSQL Develope ...

  5. 安全测试 - SQL注入

    1. 工具测试: 使用SQLMAP进行扫描 2. 手工测试: 观察参数的值value是否为数字型.如果是数字型进行数字型测试,否则跳到第4步进行字符型测试(例如如果出现a那说明是字符型,如果出现2则将 ...

  6. Android中基于CGroup的memory子系统HAL层分析-lmkd

    Android在内存管理上于Linux有些小的区别,其中一个就是引入了lowmemorykiller.从lowmemorykiller.c位于drivers/staging/android也可知道,属 ...

  7. 基于modelsim-SE的专业进阶仿真流程

    基于modelsim-SE的专业进阶仿真流程 通过<基于modelsim-SE的简单仿真流程>和<调用altera IP核的仿真流程>是否感受到仿真流程中的繁琐步骤,特别是在m ...

  8. python入门

    输出用print 注释用# rang() >>> range(1,5) #代表从1到5(不包含5) [1, 2, 3, 4] >>> range(1,5,2) #代 ...

  9. ASP.NET WEB API 帮助文档引用单独项目中的DTO,见面上不显示字段注释问题解决办法

    StackOverFlow上的解决办法: 问题地址

  10. windows多线程编程

    进程共同实现某个任务或者共享计算机资源, 它们之间存在两种关系: 1.同步关系, 指为了完成任务的进程之间, 因为需要在某些位置协调它们的执行顺序而等待, 传递消息产生的制约关系. 2.互斥关系, 进 ...