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. eclipse如何能快速找到某个文件夹或者文件

    eclipse如何能快速找到某个文件夹或者文件 直接在editor中右键 Show in -> Package Explorer 在package explore 中选中link就可以了 (魔芋 ...

  2. Shell中的循环语句实例

    1.for循环语句实例1.1 最基本的for循环 #!/bin/bash for x in one two three four do     echo number $x done 注:" ...

  3. 用Windows自带DOS命令提示符 制作U盘启动盘

    Windows & DOS命令提示符 & U盘 & 启动盘 用Windows自带DOS命令提示符 制作U盘启动盘.docx http://xgqfrms.blog.163.co ...

  4. 如何将jsp后缀重写为html

    公司有时候要写一些小的项目,而用java搭建web的一个缺(特)陷(征)就是动态网页的后缀名.jsp.没办法啊,就是不能以.jsp结尾,原因有几个:隐藏服务端技术:吸引爬虫:对用户更友好:等等.如果全 ...

  5. Ubuntu 16.04安装VMware-Workstation-12

    1.下载: https://download3.vmware.com/software/wkst/file/VMware-Workstation-Full-12.1.1-3770994.x86_64. ...

  6. Nexus设备升级5.0方法

    1. 从该页面为您的设备下载适当的系统映像.然后将它解压缩到一个安全的文件夹. 2. 通过 USB 连接到您的计算机. 3. 使用下列的方法,在fastboot mode下启动设备: 使用 adb   ...

  7. VM Workstation 虚拟机安装Ghost XP教程

    1 工具和软件准备 VM Workstation虚拟机软件(必须) http://pan.baidu.com/share/link?shareid=304385&uk=637999033   ...

  8. 为XCode 6 加入新建类模板

    用XCode 6在改动之前用XCode 5 的代码的时候突然间发现 XCode 6已经把新建带有 .xib 类的模板给删去了.而项目的新需求中又要用到新建带有 .xib 的类(用惯了~),全部不得不又 ...

  9. HDU 1241 Oil Deposits (DFS)

    题目链接:Oil Deposits 解析:问有多少个"@"块.当中每一个块内的各个"@"至少通过八个方向之中的一个相邻. 直接从"@"的地方 ...

  10. python hehe

    键盘监听事件 标签: 键盘监听python 2016-08-22 14:36 226人阅读 评论(0) 收藏 举报  分类: 其他(33)  本文以一段简单的监听鼠标.键盘事件的程序,实现获取用户的输 ...