[Codeforces]Codeforces Round #489 (Div. 2)
Nastya and an Array
输出有几种不同的数字
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} int p[], q[]; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n, x;
cin >> n;
int ans = ;
for (int i = ; i < n; i++) {
cin >> x;
if (x > ) {
if (!p[x]) ans++;
p[x] = true;
}
if (x < ) {
if (!q[-x]) ans++;
q[-x] = true;
}
}
cout << ans << endl;
return ;
}
Nastya Studies Informatics
把y/x分解质因数,a和b各自占有一部分且不重复
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} bool f[];
int p[]; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
memset(f, true, sizeof(f));
f[] = f[] = false;
for (int i = ; i < ; i++) {
for (int j = i + i; j < ; j += i) f[j] = false;
}
int l, r, x, y;
cin >> l >> r >> x >> y;
if (y % x != ) {
cout << << endl;
return ;
}
int m = y / x, sz = ;
for (int i = ; i < ; i++) {
if (m == ) break;
if (!f[i]) continue;
if (m % i == ) {
int tmp = ;
while (m % i == ) {
m /= i;
tmp *= i;
}
p[sz++] = tmp;
}
}
if (m != ) p[sz++] = m;
m = y / x;
int ans = ;
for (int i = ; i < ( << sz); i++) {
int a = , b;
for (int j = ; j < sz; j++) {
if (i & ( << j)) a *= p[j];
}
b = m / a;
if (l <= a * x && a * x <= r && l <= b * x && b * x <= r) ans++;
}
cout << ans << endl;
return ;
}
Nastya and a Wardrobe
每次x2-0.5
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} inline lint pow(lint a, lint b, lint p) {
lint rtn = ;
while (b) {
if (b & ) rtn = rtn * a % p;
a = a * a % p;
b >>= ;
}
return rtn;
} int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
lint x, k;
cin >> x >> k;
lint p = ;
if (k == ) {
cout << (x * % p) << endl;
return ;
}
if (x == ) {
cout << << endl;
return ;
}
lint a = pow(, k, p) * (x % p) % p, b = pow(, k - , p);
//a-b+0.5->2a-2b+1
cout << (( * a - * b + ) % p + p) % p << endl;
return ;
}
/*
2(2x - 0.5) - 0.5
2x - 0.5 1
4x - 1.5 2
8x - 3.5 4
16x - 7.5 8
32x - 15.5 16
*/
Nastya and a Game
枚举左端点然后依次往右找,对于一段连续的1可以根据范围直接判断。因为S的最大值不超过2*10^18,所以向右找的次数不超过120次。
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} lint a[], s[];
int r[];
double ln[];
double inf = log(1LL << ); int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n, k;
cin >> n >> k;
s[] = ;
for (int i = ; i <= n; i++) {
cin >> a[i];
s[i] = s[i - ] + a[i];
ln[i] = log(a[i]);
}
for (int i = n; i >= ; i--) {
if (a[i] == ) {
if (a[i + ] == ) r[i] = r[i + ];
else r[i] = i;
}
}
lint ans = ;
if (k == ) ans = n;
for (int i = ; i <= n; i++) {
int j = i + ;
lint m = a[i];
double p = ln[i];
while (j <= n) {
if (a[j] == ) {
if (m % k == ) {
lint tmp = m / k;
if (s[j] - s[i - ] <= tmp && tmp <= s[r[j]] - s[i - ]) ans++;
}
j = r[j] + ;
} else {
if (p + ln[j] >= inf) break;
p += ln[j];
m *= a[j];
if (m == (s[j] - s[i - ])*k) ans++;
j++;
}
}
}
cout << ans << endl;
return ;
}
Nastya and King-Shamans
两个线段树,一个维护sum,一个维护max。对每个询问,如果a[1]=0直接输出1,否则令m=1,显然此时[1,m]里没有萨满王。对于m之后的,想成为萨满王其能力值至少为sum(1,m),找到第一个满足条件的萨满p,判断p是不是萨满王,如果不是则令m=p,直到找到或确定没有。
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} lint a[];
int n, q;
template <typename T> class SegmentTree {
/*
type:
0:sum
1:max
*/
private:
T *data, *lazy;
int type;
void pushup(int rt) {
if (type == )
data[rt] = data[rt << ] + data[rt << | ];
else if (type == )
data[rt] = max(data[rt << ], data[rt << | ]);
}
void pushdown(int rt, T m) {
if (lazy[rt] == ) return;
lazy[rt << ] += lazy[rt];
lazy[rt << | ] += lazy[rt];
if (type == ) {
data[rt << ] += (m - (m >> )) * lazy[rt];
data[rt << | ] += (m >> ) * lazy[rt];
} else if (type == ) {
data[rt << ] += lazy[rt];
data[rt << | ] += lazy[rt];
}
lazy[rt] = ;
}
public:
SegmentTree(int n, int t) : data((T *)malloc((n << ) * sizeof(T))), lazy((T *)malloc((n << ) * sizeof(T))), type(t) {}
void Build(T * base, int l, int r, int rt) {
lazy[rt] = ;
if (l == r) data[rt] = base[l];
else {
int mid = (l + r) >> ;
Build(base, l, mid, rt << );
Build(base, mid + , r, rt << | );
pushup(rt);
}
}
void Modify(int l, int r, int rt, int L, int R, T v) {
if (L <= l && R >= r) {
lazy[rt] += v;
if (type == )
data[rt] += v * (r - l + );
else if (type == )
data[rt] += v;
return;
}
pushdown(rt, r - l + );
int mid = (l + r) >> ;
if (L <= mid)
Modify(l, mid, rt << , L, R, v);
if (R > mid)
Modify(mid + , r, rt << | , L, R, v);
pushup(rt);
}
T QueryPoint(int l, int r, int rt, int val) {
if (l == r) return data[rt];
pushdown(rt, r - l + );
int mid = (l + r) >> ;
T ret = ;
if (val <= mid) ret = QueryPoint(l, mid, rt << , val);
else ret = QueryPoint(mid + , r, rt << | , val);
pushup(rt);
return ret;
}
T QuerySegment(int l, int r, int rt, int L, int R) {
pushdown(rt, r - l + );
if (L == l && R == r) return data[rt];
int mid = (l + r) >> ;
if (R <= mid) return QuerySegment(l, mid, rt << , L, R);
if (mid < L) return QuerySegment(mid + , r, rt << | , L, R);
if (type == )
return QuerySegment(l, mid, rt << , L, mid) + QuerySegment(mid + , r, rt << | , mid + , R);
else if (type == )
return max(QuerySegment(l, mid, rt << , L, mid), QuerySegment(mid + , r, rt << | , mid + , R));
}
int find(int l, int r, int rt, int p, T x) {
if (r <= p) return -;
if (data[rt] < x) return -;
if (l == r) return l;
int mid = (l + r) >> ;
if (l > p) {
if (data[rt << ] >= x) return find(l, mid, rt << , p, x);
else return find(mid + , r, rt << | , p, x);
}
int rtn = find(l, mid, rt << , p, x);
if (rtn != -) return rtn;
return find(mid + , r, rt << | , p, x);
}
};
SegmentTree<lint> Tsum(, ), Tmax(, ); int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
cin >> n >> q;
for (int i = ; i <= n; i++) cin >> a[i];
Tsum.Build(a, , n, );
Tmax.Build(a, , n, );
while (q--) {
int p;
lint x;
cin >> p >> x;
Tsum.Modify(, n, , p, p, x - a[p]);
Tmax.Modify(, n, , p, p, x - a[p]);
a[p] = x;
if (a[] == ) {
cout << << endl;
continue;
}
int m = ;
while () {
lint sum = Tsum.QuerySegment(, n, , , m);
int nex = Tmax.find(,n,,m,sum);
if (nex == -) {
cout << - << endl;
break;
}
if (a[nex] == Tsum.QuerySegment(, n, , , nex - )) {
cout << nex << endl;
break;
}
m = nex;
}
}
return ;
}
[Codeforces]Codeforces Round #489 (Div. 2)的更多相关文章
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
- Codeforces Beta Round #70 (Div. 2)
Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...
随机推荐
- Java基础学习总结(84)——Java面向对象六大原则和设计模式
面向对象六大原则 在此之前,有一点需要大家知道,熟悉这些原则并不是说你写出的程序就一定灵活.清晰,只是为你优秀的代码之路铺上了一层栅栏,在这些原则的指导下,你才能避免陷入一些常见的代码泥沼,从而让你写 ...
- Ural 1091 Tmutarakan Exams
Tmutarakan Exams Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Origi ...
- 轰炸III(codevs 1830)
题目背景 一个大小为N*M的城市遭到了X次轰炸,每次都炸了一个每条边都与边界平行的矩形. 题目描述 在轰炸后,有Y个关键点,指挥官想知道,它们有没有受到过轰炸,如果有,被炸了几次,最后一次是第几轮. ...
- 1154 能量项链 2006年NOIP全国联赛提高组 codevs
1154 能量项链 2006年NOIP全国联赛提高组 codevs 题目描述 Description 在Mars星球上,每个Mars人都随身佩带着一串能量项链.在项链上有N颗能量珠.能量珠是一颗有头 ...
- 使用Vundle管理配置Vim的插件
1.介绍: 安装需要Git,触发git clone,默认将每一个指定特定格式插件的仓库复制到~/.vim/bundle/. 搜索需要Curl支持. Windows用户请直接访问Windows setu ...
- Linux: 删除当前目录下的所有__pycache__子目录
find . -name '__pycache__' -type d -exec rm -rf {} \;
- CentOS和Window互相远程桌面方法
1)VNC服务器配置 (CentOS 5.x安装GNOME桌面环境) # yum groupinstall "GNOME Desktop Environment(CentOS 6.x安装G ...
- Python3基础(六) 深入list列表
正如Python FAQ1附录中说的, Python中任何值都是一个对象,所以任何类型(int.str.list-)都是一个类.而类就必然有它的方法或属性,我们要记下这么多类的所有方法显然是不可能的, ...
- HTTP 错误 404.15 - Not Found 请求筛选模块被配置为拒绝包含的查询字符串过长的请求。
HTTP 错误 404.15 - Not Found 请求筛选模块被配置为拒绝包含的查询字符串过长的请求. 2018-04-20 14:00 by 码农小周, 21 阅读, 2 评论, 收藏, 编辑 ...
- MySQL中採用类型varchar(20)和varchar(255)对性能上的影响
1.MySQL建立索引时假设没有限制索引的大小,索引长度会默认採用的该字段的长度.也就是说varchar(20)和varchar(255)相应的索引长度分别为20*3(utf-8)(+2+1),255 ...