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. PostgreSQL-PL/pgSQL-cursor,loop

    将spam_keyword表word字段的字符全部拆分,只是利用过程语言完成循环的操作而已. create or replace function proc1() returns setof text ...

  2. java正则表达式

    java正则表达式 1.Java正则表达式的语法与示例:  http://baike.xsoftlab.net/view/207.html 2.Java 正则表达式:  http://www.runo ...

  3. Apache主配置文件httpd.conf 详解

    Apache的主配置文件:/etc/httpd/conf/httpd.conf 默认站点主目录:/var/www/html/ Apache服务器的配置信息全部存储在主配置文件/etc/httpd/co ...

  4. 如果layer层在iframe下不居中滚动

    需要在layer前面加上parent.layer. 2.运用layer层的步骤: 1.引入1.8版本以上的jquery文件 <script type="text/javascript& ...

  5. plain framework 1 一款主要用于网络(游戏)开发的C/C++开源框架 安装篇 updated

    上次介绍了一下plain framework的基础相关资料,今天该框架正式开源发布.项目的地址托管于github上,我相信大多数朋友都应该知道.今天要介绍的是该框架的目录基本结构,以及分别在linux ...

  6. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. C#中ToString()格式详解

    以下内容均摘自博客园,仅供资料查询. ToString格式化 在很多对象显示为字符串的时候都会使用到ToString中的格式化,由于以前没怎么注意到这个问题,想总结一下各个基础结构对象的格式化,以便后 ...

  8. [LeetCode] Matchsticks to Square 火柴棍组成正方形

    Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...

  9. [LeetCode] Line Reflection 直线对称

    Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given ...

  10. 在WPF程序中打开网页:使用代理服务器并可进行JS交互

    本项目环境:使用VS2010(C#)编写的WPF程序,通过CefSharp在程序的窗体中打开网页.需要能够实现网页后台JS代码中调用的方法,从网页接收数据,并能返回数据给网页.运行程序的电脑不允许上网 ...