Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1770    Accepted Submission(s): 1089

Problem Description

Alice and Bob are playing a game.

The game is played on a set of positive integers from 1 to n.

In one step, the player can choose a positive integer from the set, and erase all of its divisors from the set. If a divisor doesn't exist it will be ignored.

Alice and Bob choose in turn, the one who cannot choose (current set is empty) loses.

Alice goes first, she wanna know whether she can win. Please judge by outputing 'Yes' or 'No'.

Input

There might be multiple test cases, no more than 10. You need to read till the end of input.

For each test case, a line containing an integer n. (1≤n≤500)

Output

A line for each test case, 'Yes' or 'No'.

Sample Input

1

Sample Output

Yes

题意:A和B在一串数字上操作,数字范围为1-n, 每次只能取一个数及其它的所有因子,那个先不能操作,那个先输;

题解:如果存在B胜的状态,那么A也能到达,所以本题对于A来说只有必胜态。

#include<bits/stdc++.h>
#define ios1 ios::sync_with_stdio(0)
#define ios2 cin.tie(0)
#define LL long long
#define INF 0x3f3f3f3f
using namespace std; int main() {
int n;
while(scanf("%d", &n) == 1) {
printf("Yes\n");
}
return 0;
}

Naive Operations

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Others)

Total Submission(s): 1899    Accepted Submission(s): 258

Problem Description

In a galaxy far, far away, there are two integer sequence a and b of length n.

b is a static permutation of 1 to n. Initially a is filled with zeroes.

There are two kind of operations:

1. add l r: add one for al,al+1...ar

2. query l r: query ∑ri=lai/bi

Input

There are multiple test cases, please read till the end of input file.

For each test case, in the first line, two integers n,q, representing the length of a,b and the number of queries.

In the second line, n integers separated by spaces, representing permutation b.

In the following q lines, each line is either in the form 'add l r' or 'query l r', representing an operation.

1≤n,q≤100000, 1≤lrn, there're no more than 5 test cases.

Output

Output the answer for each 'query', each one line.

Sample Input

5 12

1 5 2 4 3

add 1 4

query 1 4

add 2 5

query 2 5

add 3 5

query 1 5

add 2 4

query 1 4

add 2 5

query 2 5

add 2 2

query 1 5

Sample Output

1

1

2

4

4

6

题意:n个数,2种操作,2个数组,a数组初始都为0,然后给了b数组的值,

add 是给l到r都加1,query是查询l到r的

∑ri=⌊ai/bi⌋的和.

思路:我们只需维护b数组的区间最小值就可以了,由于这个是向下取整,因此只有当bi减为0的时候才会对所求的区间有贡献值,所以对a数组的加1的操作,相当于对b数组的减1的操作.

如果区间的最小值min>1,那么min--,否则向下查找;  min>1的子区间继续之前的操作,min==1的让贡献值加1,所属的值变为本来的值

/**
add a b c:把区间[a,b]内的所有数都增加 c
sum a b:查询区间[a,b]的区间和
min a b:查询区间[a,b]的最小值
*/
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long INF = 1LL << 62;
struct Segment_tree {
struct Node {
int l, r;///左右区间
int sum, min, add_lazy;///贡献值, 区间最小值, 标记
} tre[maxn << 2];
int arr[maxn];
inline void push_up(int rt) {
if(tre[rt].l == tre[rt].r) {
return ;
}
tre[rt].sum = tre[rt<<1].sum + tre[rt<<1|1].sum;
tre[rt].min = min(tre[rt<<1].min, tre[rt<<1|1].min);
}
inline void push_down(int rt) {
if(tre[rt].add_lazy) {
tre[rt<<1].add_lazy += tre[rt].add_lazy;
tre[rt<<1].min -= tre[rt].add_lazy;
tre[rt<<1|1].add_lazy += tre[rt].add_lazy;
tre[rt<<1|1].min -= tre[rt].add_lazy;
tre[rt].add_lazy = 0;
}
}
void build(int rt,int l,int r) {
tre[rt].l = l;
tre[rt].r = r;
tre[rt].add_lazy = 0;
if(l == r) {
tre[rt].sum = 0;
tre[rt].min = arr[l];
return ;
}
int mid = (l + r) >> 1;
build(rt<<1,l,mid);
build(rt<<1|1,mid+1,r);
push_up(rt);
}
void update1(int rt,int l,int r) { ///add
push_down(rt);
if(l == tre[rt].l && tre[rt].r == r && tre[rt].min > 1) {
tre[rt].add_lazy += 1;
tre[rt].min -= 1;
return ;
}
if(tre[rt].l == tre[rt].r) {
tre[rt].add_lazy += 1;
tre[rt].min -= 1;
if(tre[rt].min <= 0) {
tre[rt].min = arr[l];
tre[rt].sum += 1;
}
return ;
}
int mid = (tre[rt].l + tre[rt].r) >> 1;
if(r <= mid) {
update1(rt<<1,l,r);
} else if(l > mid) {
update1(rt<<1|1,l,r);
} else {
update1(rt<<1,l,mid);
update1(rt<<1|1,mid+1,r);
}
push_up(rt);
}
int query1(int rt,int l,int r) { ///sum
push_down(rt);
if(l == tre[rt].l && tre[rt].r == r) {
return tre[rt].sum;
}
int mid = (tre[rt].l + tre[rt].r) >> 1;
if(r <= mid) {
return query1(rt<<1,l,r);
} else if(l > mid) {
return query1(rt<<1|1,l,r);
} else {
return query1(rt<<1,l,mid) + query1(rt<<1|1,mid+1,r);
}
}
} S; int main() {
int n, q;
while(cin >> n >> q) {
for(int i = 1; i <= n; i++) {
scanf("%d", &S.arr[i]);
}
S.build(1, 1, n);
string s;
int l, r;
while(q--) {
cin >> s >> l >> r;
if(s == "add") {
S.update1(1, l, r);
}
else {
cout << S.query1(1, l, r) << endl;
}
}
}
return 0;
}

2018 Multi-University Training Contest 2(部分题解)的更多相关文章

  1. 2018 Multi-University Training Contest 3(部分题解)

    Problem F. Grab The Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Ja ...

  2. 2018 Multi-University Training Contest 1(部分题解)

    Maximum Multiple Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. 2018 Multi-University Training Contest - Team 1 题解

    Solved A HDU 6298 Maximum Multiple Solved B HDU 6299 Balanced Sequence Solved C HDU 6300 Triangle Pa ...

  4. 2018 Nowcoder Multi-University Training Contest 2

    目录 Contest Info Solutions A. run D. monrey G. transform H. travel I. car J. farm Contest Info Practi ...

  5. 2016 Multi-University Training Contest 3 部分题解

    1001,只要枚举区间即可.签到题,要注意的是输入0的话也是“TAT”.不过今天补题的时候却WA了好几次,觉得奇怪.原来出现在判断条件那里,x是一个int64类型的变量,在进行(x<65536* ...

  6. 2016 Multi-University Training Contest 1 部分题解

    第一场多校,出了一题,,没有挂零还算欣慰. 1001,求最小生成树和,确定了最小生成树后任意两点间的距离的最小数学期望.当时就有点矛盾,为什么是求最小的数学期望以及为什么题目给了每条边都不相等的条件. ...

  7. 2016 Multi-University Training Contest 4 部分题解

    1001,官方题解是直接dp,首先dp[i]表示到i位置的种类数,它首先应该等于dp[i-1],(假设m是B串的长度)同时,如果(i-m+1)这个位置开始到i这个位置的这一串是和B串相同的,那么dp[ ...

  8. 2018 Nowcoder Multi-University Training Contest 1

    Practice Link J. Different Integers 题意: 给出\(n\)个数,每次询问\((l_i, r_i)\),表示\(a_1, \cdots, a_i, a_j, \cdo ...

  9. 2018 Nowcoder Multi-University Training Contest 5

    Practice Link A. gpa 题意: 有\(n\)门课程,每门课程的学分为\(s_i\),绩点为\(c_i\),要求最多删除\(k\)门课程,使得gpa最高. gpa计算方式如下: \[ ...

随机推荐

  1. vue中使用vue-amap(高德地图)

    因为项目要求调用高德地图,就按照官方文档按部就班的捣鼓,这一路上出了不少问题. 前言: vue-cli,node环境什么的自己安装设置推荐一个博客:https://blog.csdn.net/wula ...

  2. mybatis学习笔记(三)

    mybatis增删改 概念: 功能:从应用程序角度出发,软件具有哪些功能: 业务:完成功能时的逻辑,对应service的一个方法: 事务:从数据库角度出发,完成业务时需要执行的SQL集合,统称一个事务 ...

  3. MySQL一键生成实体文件的神器-ginbro

    Java转过来的同学对Mybatis的使用肯定不陌生,特别是对一堆表去生成相应的dao和entity的时候使用Mybatis generator所带来的感触,无比深刻.前面我们也讲过原生的数据库使用, ...

  4. koa2图片上传成功后返回服务器地址,实时显示服务器图片

    版本:node(8.5.0); koa(2.4.1); koa-router(7.3.0); koa-body(2.5.0); koa-static(4.0.2); 代码实现 const fs = r ...

  5. 趣味CSS3效果挑战小汇总

    众所周知,在CSS3中产生了诸多优秀的特性,现在就来分享一下我这段时间对于这些特性的效果实践,希望对大家有所启发. 挑战1: 画一个对话框 要画一个对话框,首先来学习做一个三角形.其实非常的简单. & ...

  6. Java 在spring cloud中使用Redis,spring boot同样适用

    1.本地安装redis服务,官网下载. 2.在开发中要使用redis,首先要启动本地redis服务,启动后页面如下: 3.在spring boot项目pom.xml文件中添加Redis需要的依赖包,可 ...

  7. 并发模型与IO模型梳理

    并发模型 常见的并发模型一般包括3类,基于线程与锁的内存共享模型,actor模型和CSP模型,其中尤以线程与锁的共享内存模型最为常见.由于go语言的兴起,CSP模型也越来越受关注.基于锁的共享内存模型 ...

  8. 简单了解一下事件循环(Event Loop)

    关于我 一个有思想的程序猿,终身学习实践者,目前在一个创业团队任team lead,技术栈涉及Android.Python.Java和Go,这个也是我们团队的主要技术栈. Github:https:/ ...

  9. 教你如何认识人脸识别开发套件中的双目摄像、3D结构光摄像头、单目摄像头的区别及详细讲解

    深圳市宁远电子提供的人脸识别模组可支持双目摄像头和3D结构光摄像头,在客户咨询中经常有被问到双目的为什么会比单目的成本高,区别在哪里,他们的适用于哪些场景呢?在此,深圳市宁远电子技术工程师就为大家详细 ...

  10. Code signing is required for product type 'Unit Test Bundle' in SDK 'iOS 11.0.1'

    Code signing is required for product type 'Unit Test Bundle' in SDK 'iOS 11.0.1' 进入 projects and lis ...