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. Greenplum 源码安装教程 —— 以 CentOS 平台为例

    Greenplum 源码安装教程 作者:Arthur_Qin 禾众 Greenplum 主体以及orca ( 新一代优化器 ) 的代码以可以从 Github 上下载.如果不打算查看代码,想下载编译好的 ...

  2. 15天玩转redis —— 第九篇 发布/订阅模式

    本系列已经过半了,这一篇我们来看看redis好玩的发布订阅模式,其实在很多的MQ产品中都存在这样的一个模式,我们常听到的一个例子 就是邮件订阅的场景,什么意思呢,也就是说100个人订阅了你的博客,如果 ...

  3. chkconfig

    chkconfig的级别: 0:关机 1:单用户模式 2:无网络支持的多用户模式 3:有网络支持的多用户模式 4:保留,未使用 5:有网络支持有X-Windows(图形界面)支持的多用户模式 6:重新 ...

  4. Windows10上安装EDEM2.7

    这次我们来安装EDEM2.7. 安装软件来自于互联网,本文仅作学习交流之用,工程应用请购买正版. 1 软件准备 从网上找到EDEM2.7安装包,解压后里面包含两个文件,如下图所示. 2 软件安装 鼠标 ...

  5. iOS开发常用代码块(第二弹)

    GCD定时器 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ); dispat ...

  6. 复选框checkbox选中个数限制

    今天遇到一个问题:就是项目里有用到限制 checkbox框选中个数,看起来很简单,但是确实花了点时间才弄清楚,废话不多说,上代码 <!DOCTYPE html> <html lang ...

  7. webapi frombody fromuri的参数绑定规则

    在WebAPI中,请求主体(HttpContent)只能被读取一次,不被缓存,只能向前读取的流. 举例子说明: 1. 请求地址:/?id=123&name=bob 服务端方法: void Ac ...

  8. [LeetCode] Strobogrammatic Number III 对称数之三

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  9. [LeetCode] Candy 分糖果问题

    There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...

  10. IOS跑马灯效果,实现文字水平无间断滚动

    ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController{ NSTimer ...