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

  1. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  2. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  3. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  4. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  5. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  6. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  7. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  8. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

  9. Codeforces Beta Round #72 (Div. 2 Only)

    Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...

  10. Codeforces Beta Round #70 (Div. 2)

    Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...

随机推荐

  1. Shiro_认证思路分析

    [认证] 也就是登录. 1.获取当前的subject,调用SecurityUtils.getSubject() 2.测试当前的用户是否已经被认证,即是否登录.调用subject的isAuthentic ...

  2. 【Codeforces 1019A】Elections

    [链接] 我是链接,点我呀:) [题意] 每个人都有自己喜欢的队员 但是如果贿赂他们可以让他们更改自己喜欢的队员 问你最少要花多少钱贿赂队员才能让1号队员严格有最多的人喜欢? [题解] 除了1号之外, ...

  3. Codeforces 121A Lucky Sum

    Lucky Sum Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...

  4. Win32编程API 基础篇 -- 1.入门指南 根据英文教程翻译

    入门指南 本教程是关于什么的 本教程的目的是向你介绍使用win32 API编写程序的基础知识(和通用的写法).使用的语言是C,但大多数C++编译器也能成功编译,事实上,教程中的绝大多数内容都适用于任何 ...

  5. C. Painting Fence 分治

    memory limit per test 512 megabytes input standard input output standard output Bizon the Champion i ...

  6. vue2的简单Popup (Confirm,Alert)组件

    github:  https://github.com/longfei59418888/vui   (记得给一个 start,以后有一起讨论,各种好组件) demo :http://60.205.20 ...

  7. 《WF in 24 Hours》读书笔记 - Hour 1 - Understanding Windows Workflow Foundation

    1.1 Hour 1 - Understanding Windows Workflow Foundation   1.1.1 What workflow is in general A workflo ...

  8. 可恢复的安全rm

    我们常常使用rm去删除一些文件.假设不小手一抖,那么就悲剧了.你们都懂的... 在经历过一次这种慘剧后.决定永远杜绝这种情况.重写写了shell函数.运行安全的rm.这个函数会把要删除的文件按日期备份 ...

  9. 使用Jsoup解析和操作HTML

    jsoup 简单介绍 jsoup 是一款 Java 的HTML 解析器,可直接解析某个URL地址.HTML文本内容.它提供了一套很省力的API,可通过DOM.CSS以及类似于jQuery的操作方法来取 ...

  10. Centos 7 nginx-1.12.0编译安装

    参考:http://www.nginx.cn/install 也不知道我的系统是否有这些依赖包,试试吧?缺少哪些我就装哪些吧,多踏点坑总是能学到点东西的.   获取nginx包 http://ngin ...