pkusc2015
Mex
题目大意:给出一个序列\(a\),定义\(f(l,r)\)为集合{\(a_l, a_{l+1}, …, a_r\)}的sg值,求\(\sum_i \sum_{j(i\leq j)} f(i,j)\)的值。
问题的关键(突破口):假设对于一个固定的\(p\),我们求出了对于所有\(j\)的\(f(p,j)\),现在考虑\(p\)增加一,思考对于所有\(j\)的\(f(p+1,j)\)的值与\(f(p,j)\)有什么变化。
兔子与寿司
据说这题是原创题?以至于我找不到提交的地方。
这题很容易想到枚举第一只兔子的吃的最大的美味值x,然后显然把a小于等于x的篮子分给第一只兔子,现在考虑剩下的篮子。
我们可以用线段树维护,线段树的下标y是篮子的b值,存的值表示第二只兔子吃的最大美味小于等于y时,后面两只兔子最大的美味值的和最小是多少。
modseq
这题当时我记得旁边的人都刷刷地秒了,我这个逗比不会做。。。。
其实这个关系到鸽巢原理,当序列的长度大于\(p\)时,显然答案就是0嘛!我记得我以前看过!
忍不住贴个代码(事实上并没有多大意义)。
#include <cstdio>
#include <stack>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = (int) 2e5 + 3;
int n;
int a[MAXN];
struct s_node {
long long sum;
int mini, maxi;
int mark;
};
s_node t[1 << 19];
void update(int idx) {
int idxl = idx << 1;
int idxr = idxl | 1;
t[idx].sum = t[idxl].sum + t[idxr].sum;
t[idx].mini = min(t[idxl].mini, t[idxr].mini);
t[idx].maxi = max(t[idxl].maxi, t[idxr].maxi);
}
void build(int idx, int L, int R, int sg[]) {
t[idx].mark = -1;
if (L == R) {
t[idx].mini = t[idx].maxi = sg[L];
t[idx].sum = sg[L];
return;
}
int M = (L + R) >> 1;
build(idx << 1, L, M, sg);
build(idx << 1 | 1, M + 1, R, sg);
update(idx);
}
int posi[MAXN];
void analyse() {
static int next[MAXN];
fill(next, next + 1 + n, -1);
for (int i = n - 1; i >= 0; i--) {
if (next[a[i]] == -1) posi[i] = -1;
else posi[i] = next[a[i]];
next[a[i]] = i;
}
static int sg[MAXN], cnt[MAXN];
fill(cnt, cnt + n + 1, 0);
int num = 0;
for (int i = 0; i < n; i++) {
cnt[a[i]]++;
while (cnt[num]) num++;
sg[i] = num;
}
build(1, 0, n - 1, sg);
}
void setLazy(int idx, int L, int R, int x) {
t[idx].mini = t[idx].maxi = x;
t[idx].sum = (long long) x * (R - L + 1);
t[idx].mark = x;
}
void modify(int idx, int L, int R, int l, int r, int x) {
if (t[idx].maxi <= x) return;
if (t[idx].mini >= x && l <= L && r >= R) {
setLazy(idx, L, R, x);
return;
}
int M = (L + R) >> 1;
if (-1 != t[idx].mark) {
setLazy(idx << 1, L, M, t[idx].mark);
setLazy(idx << 1 | 1, M + 1, R, t[idx].mark);
t[idx].mark = -1;
}
if (l <= M) modify(idx << 1, L, M, l, r, x);
if (r > M) modify(idx << 1 | 1, M + 1, R, l, r, x);
update(idx);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
while (scanf("%d", &n) == 1) {
if (n == 0) break;
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
a[i] = min(a[i], n);
}
analyse();
long long ans = t[1].sum;
for (int i = 0; i + 1 < n; i++) {
int p = a[i];
modify(1, 0, n - 1, i, i, 0);
if (posi[i] == -1) {
modify(1, 0, n - 1, i + 1, n - 1, p);
}
else {
if (i + 1 <= posi[i] - 1)
modify(1, 0, n - 1, i + 1, posi[i] - 1, p);
}
ans += t[1].sum;
}
cout << ans << endl;
}
return 0;
}
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = (int) 1e5 + 3;
struct s_blanket {
int a, b, c;
};
int n;
s_blanket x[MAXN];
int idx_value[MAXN];
bool cmp(const s_blanket &p, const s_blanket &q) {
return p.a < q.a;
}
struct s_node {
int maxi, lazy;
int value;
};
s_node t[1 << 18];
void setLazy(int idx, int v, int L) {
t[idx].maxi = v;
t[idx].lazy = v;
t[idx].value = v + idx_value[L];
}
void build(int idx, int L, int R) {
if (L == R) {
t[idx].value = idx_value[L];
return;
}
int M = (L + R) >> 1;
build(idx << 1, L, M);
build(idx << 1 | 1, M + 1, R);
t[idx].value = min(
t[idx << 1].value,
t[idx << 1 | 1].value);
}
void dfs(int idx, int L, int R, int y, int v, bool ok) {
if (L > y) return;
if (t[idx].maxi >= v) return;
if (L == R) {
if (v > t[idx].maxi) {
t[idx].maxi = v;
t[idx].value = idx_value[L] + v;
}
return;
}
int M = (L + R) >> 1;
int idxl = idx << 1;
int idxr = idxl | 1;
if (t[idx].lazy) {
setLazy(idxl, t[idx].lazy, L);
setLazy(idxr, t[idx].lazy, M + 1);
t[idx].lazy = 0;
}
if (ok && R <= y) {
setLazy(idx, v, L);
return;
}
if (ok) {
dfs(idxl, L, M, y, v, ok);
dfs(idxr, M + 1, R, y, v, ok);
}
else {
if (t[idxl].maxi < v) {
dfs(idxl, L, M, y, v, false);
dfs(idxr, M + 1, R, y, v, true);
}
else {
dfs(idxr, M + 1, R, y, v, false);
}
}
t[idx].maxi = min(t[idxl].maxi, t[idxr].maxi);
t[idx].value = min(t[idxl].value, t[idxr].value);
}
void insert(s_blanket item) {
int posi = lower_bound(idx_value, idx_value + n, item.b) - idx_value;
dfs(1, 0, n - 1, posi - 1, item.c, false);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
scanf("%d", &n);
for (int i = 0; i <= n; i++) {
if (i < n)
scanf("%d%d%d", &x[i].a, &x[i].b, &x[i].c);
idx_value[i] = x[i].b;
}
n++;
sort(idx_value, idx_value + n);
sort(x, x + n, cmp);
int ans = 0x3f3f3f3f;
build(1, 0, n - 1);
for (int i = n - 1; i >= 0; i--) {
ans = min(ans, x[i].a + t[1].value);
insert(x[i]);
}
printf("%d\n", ans);
return 0;
}
#include <cstdio>
int main() {
int n, m;
static int a[100001];
while (scanf("%d%d", &n, &m) == 2) {
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 0; i < m; i++) {
int l, r, p;
scanf("%d%d%d", &l, &r, &p);
if (r - l + 1 > p) {
printf("0\n");
continue;
}
int ans = 0x3f3f3f3f;
for (int x = l; x <= r; x++) {
int sum = 0;
for (int y = x; y <= r; y++) {
sum = (sum + a[y]) % p;
if (sum < ans) ans = sum;
}
}
printf("%d\n", ans);
}
}
return 0;
}
pkusc2015的更多相关文章
- PKUSC2015总结
突然发现这是自己第100篇博客...写下总结庆祝一下好啦 首先就是..D类狗果真没人权啊啊啊.考的辛辛苦苦结果因为D类拿不到一个好协议真的是哭瞎辣QAQ 然后就是..自己真的是太弱啊啊啊..各种傻逼题 ...
- 【POJ 1113】Wall
http://poj.org/problem?id=1113 夏令营讲课时的求凸包例题,据说是PKUSC2015的一道题 我WA两次错在四舍五入上了(=゚ω゚)ノ #include<cmath& ...
随机推荐
- linux date -d 的一些使用方法
date命令中格式输出类型字符含义例如以下: %% 一个文字的 % %a 当前locale 的星期名缩写(比如: 日,代表星期日) %A 当前locale 的星期名全称 (如:星期日) %b 当前lo ...
- CodeIgniter框架开发的统计程序源代码开放
文章来源: PHP开发学习门户 自己初学php时,用CodeIgniter框架开发的后台统计程序源代码 程序部分页面如图: 具体配置及下载源代码:http://bbs.phpthinking.com/ ...
- POJ1363:Rails
Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...
- C++内联函数与宏定义
用内联取代宏: 1.内联可调试: 2.可进行类型安全检查或自动类型转换: 3.可访问成员变量. 另外,定义在类声明中的成员函数自动转化为内联函数. 文章(一) 内联函数与宏定义 在C中,常用预处理语句 ...
- OpenGL: 环境配置和图元的绘制
前言 距离上一篇博客已经过去一个半月了,这段时间过得确实充实,虽然一大段时间泡在图书馆复习,但至少也能学到点东西.跨年晚和元旦一整天,全身心投入图形学小课设的编程,终于实现了老师要求的所有功能,回想起 ...
- .net format 中 大括号{}处理
1.string string.format(string format,object arg0) 错误:因为方法中使用{n}做占位符号了,所以其他需要括号{}的地方,就需要{{}}
- GC算法之串行并行并发
串行收集器: 用单线程处理所有垃圾回收工作,因为无需多线程交互,所以效率比较高.但是,也无法使用多处理器的优势,所以此收集器适合单处理器机器.当然,此收集器也可以用在小数据量(100M左右)情况下的多 ...
- 如何管理安卓android手机下google(谷歌)的通讯录联系人账户
andorid手机都自带通讯录备份功能,但是如何管理,一直是一些人头疼的问题.经常在手机备份还原之后发现很多联系人都有重复. 1.打开 :https://mail.google.com/ 用你的谷歌账 ...
- JS声明语句提升与作用域
<!DOCTYPE html><html><head></head><body><script>//-------------- ...
- 盛希泰:办公室就像男人的春药——人的一生的精力是有限的,你把有限的时间分配给谁决定你的成败——你有N多选择,你人生的积累就是N多选择加起来的结果
欢迎关注“创事记”的微信订阅号:sinachuangshiji 创事记注:12月22日晚上,盛希泰在清华大学旧经管报告厅面对清华师生讲了一堂<创业引导课>.本文由洪泰帮根据课堂录音整理完成 ...