前言

巨佬说:要有线段树,于是蒟蒻就开始打线段树。

蒟蒻只能拿之前0分的板子题开刀了QAQ。

题解

一开始我以为插入操作不带取模,于是打了下面这个弱智玩意

下面的代码是会WA的

#include <cstdio>
#include <algorithm>
#define ll long long using namespace std; ll read(){
ll x = 0; int zf = 1; char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
} ll s[800005];
ll _max[800005], cnt[800005];
int m, d, pos = 1;
const int MAXM = 200001; pair<ll, ll> query(int pos, int l, int r, int x, int y){
if (x <= l && r <= y)
return make_pair(cnt[pos], _max[pos]);
pair<ll, ll> ans = make_pair(-(1ll << 62), -(1ll << 62));
int mid = (l + r) >> 1;
if (x <= mid)
ans = max(ans, query(pos << 1, l, mid, x, y));
if (mid < y)
ans = max(ans, query(pos << 1 | 1, mid + 1, r, x, y));
return ans;
} void add(int pos, int l, int r, int x, ll val){
if (l == r){
s[pos] += val, cnt[pos] += s[pos] / d; s[pos] %= d;
_max[pos] = s[pos];
return ;
}
int mid = (l + r) >> 1;
if (x <= mid)
add(pos << 1, l, mid, x, val);
else if (mid < x)
add(pos << 1 | 1, mid + 1, r, x, val);
s[pos] = (s[pos << 1] + s[pos << 1 | 1]) % d;
if (cnt[pos << 1] > cnt[pos << 1 | 1])
_max[pos] = _max[pos << 1], cnt[pos] = cnt[pos << 1];
else if (cnt[pos << 1] < cnt[pos << 1 | 1])
_max[pos] = _max[pos << 1 | 1], cnt[pos] = cnt[pos << 1 | 1];
else{
cnt[pos] = cnt[pos << 1];
_max[pos] = max(_max[pos << 1], _max[pos << 1 | 1]);
}
} int main(){
m = read(), d = read(); char op[1]; ll t = 0;
while (m--){
scanf("%s", op); int n = read();
if (op[0] == 'Q')
printf("%lld\n", t = query(1, 1, MAXM, pos - n + 1, pos).second);
else if (op[0] == 'A')
add(1, 1, MAXM, ++pos, n + t);
}
return 0;
}

一波上交WA 0。

然后一看不对啊,样例都过不了啊(我自信的没测样例)。

仔细看了一下题目,发现插入操作带取模。QAQ

简直有毒。

然后一遍过...

#include <cstdio>
#include <algorithm>
#define ll long long using namespace std; ll read(){
ll x = 0; int zf = 1; char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
} ll s[800005];
ll _max[800005];
int m, d, pos = 1;
const int MAXM = 200001; ll query(int pos, int l, int r, int x, int y){
if (x <= l && r <= y)
return _max[pos];
ll ans = -(1ll << 62);
int mid = (l + r) >> 1;
if (x <= mid)
ans = max(ans, query(pos << 1, l, mid, x, y));
if (mid < y)
ans = max(ans, query(pos << 1 | 1, mid + 1, r, x, y));
return ans;
} void add(int pos, int l, int r, int x, ll val){
if (l == r){
(s[pos] += val) %= d, _max[pos] = s[pos];
return ;
}
int mid = (l + r) >> 1;
if (x <= mid)
add(pos << 1, l, mid, x, val);
else if (mid < x)
add(pos << 1 | 1, mid + 1, r, x, val);
s[pos] = (s[pos << 1] + s[pos << 1 | 1]) % d;
_max[pos] = max(_max[pos << 1], _max[pos << 1 | 1]);
} int main(){
m = read(), d = read(); char op[1]; ll t = 0;
while (m--){
scanf("%s", op); int n = read();
if (op[0] == 'Q')
printf("%lld\n", t = query(1, 1, MAXM, pos - n + 1, pos));
else if (op[0] == 'A')
add(1, 1, MAXM, ++pos, (n + t) % d);
}
return 0;
}

[JSOI2008]最大数 题解的更多相关文章

  1. BZOJ1012:[JSOI2008]最大数——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=1012 https://www.luogu.org/problemnew/show/P1198 现在 ...

  2. 【题解】[JSOI2008]最大数

    [题解][P1198 JSOI2008]最大数 正难则反,意想不到. 这道题是动态让你维护一个数列,已经在数列里面的数据不做改变,每次在最后加上一个数,强制在线. 既然正着做很难,考虑如果时间倒流,不 ...

  3. 洛谷P1198 [JSOI2008]最大数

    P1198 [JSOI2008]最大数 267通过 1.2K提交 题目提供者该用户不存在 标签线段树各省省选 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 WA80的戳这QwQ BZOJ都 ...

  4. [JSOI2008]最大数maxnumber

    [JSOI2008]最大数maxnumber 标签: 线段树 单独队列 题目链接 题解 线段树裸题. 如果一直RE可能是你用的cin/cout. Code #include<cstdio> ...

  5. 洛谷 P1198 [JSOI2008]最大数

    洛谷 P1198 [JSOI2008]最大数 题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. ...

  6. BZOJ 1012: [JSOI2008]最大数maxnumber 单调队列/线段树/树状数组/乱搞

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 4750  Solved: 2145[Submi ...

  7. bzoj1012: [JSOI2008]最大数maxnumber(貌似是道线段树喔)

    1012: [JSOI2008]最大数maxnumber 题目:传送门 题解: 发现自己空了一道水题... 1~210000建线段树,其实就是一道裸题... 单点修改+区间查询...1A~ 代码: # ...

  8. P1198 [JSOI2008]最大数(线段树基础)

    P1198 [JSOI2008]最大数 题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制: ...

  9. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

随机推荐

  1. 11.metasploit辅助模块----基本Exp----ARP欺骗中间人MITM----WordPress破解

    metasploit辅助模块 信息收集 auxiliary scanners 使用metasploitable靶机 桥接 同一局域网 msfconsole nmap -sT 靶机IP nmap -sS ...

  2. lograte切割tengine日志

    记录 /srv/logs/nginx/*log { create 0644 nobody nobody daily rotate 10 missingok notifempty compress sh ...

  3. python字符串-方法

    一.1. upper()作用:将字符串中字符转换为大写 In [17]: spam Out[17]: 'hello,world' In [18]: print(spam.upper()) HELLO, ...

  4. 红帽学习笔记[RHCSA] 第四课[用户相关、破解root密码]

    第四课 关于Linux 的用户 用户分类: # UID 是用户ID ​ UID 0分配给超级用户(root) ​ UID 1-200 是一系列的 系统用户 静态分配给红帽的系统进程 ​ UID 201 ...

  5. 小油2018 win7旗舰版64位GHOST版的,安装telnet客户端时,提示:出现错误。并非所有的功能被成功更改。

    win7旗舰版64位GHOST版的,安装telnet客户端时,提示:出现错误.并非所有的功能被成功更改. 从安装成功的电脑上拷贝ghost版本缺少的文件,然后再安装telnet客户端,我已打包 链接: ...

  6. 各类最新Asp .Net Core 项目和示例源码

    1.网站地址:http://www.freeboygirl.com2.网站Asp .Net Core 资料http://www.freeboygirl.com/blog/tag/asp%20net%2 ...

  7. mui前端框架下拉刷新分页加载数据

    前台 mui.init(); (function($) { //阻尼系数 var deceleration = mui.os.ios?0.003:0.0009; $('.mui-scroll-wrap ...

  8. 02:django model数据库操作

    Django其他篇 目录: 1.1 Django中使用MySQL 1.2 创建表 1.3 Django一对多表结构操作 1.4 Django多对多表结构操作 1.5 一大波Model操作 1.6 Mo ...

  9. 关系型数据库为什么喜欢使用B+树作为索引结构? (转)

    问题1. 数据库为什么要设计索引? 图书馆存了1000W本图书,要从中找到<架构师之路>,一本本查,要查到什么时候去? 于是,图书管理员设计了一套规则: (1)一楼放历史类,二楼放文学类, ...

  10. django中的FBV和CBV??

    django中请求处理方式有2种:FBV 和 CBV 一.FBV FBV(function base views) 就是在视图里使用函数处理请求. 看代码: urls.py from django.c ...