前言

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

蒟蒻只能拿之前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. linux常用终端指令+如何用vim写一个c程序并运行

    在装好ubuntu之后今天学习了一些linux的一些基础知识: windows里面打开命令窗口是win+r,在linux系统里面,ctrl+alt+t打开终端,今天的一些指令都是围绕终端来说的 首先s ...

  2. mysql的my.sock不存在问题

    因为是初步学习Linux,所以为了对其更加了解,没有使用yum对mysql进行安装,而是使用xftp6的方式上传然后解压安装 1.在安装过程中,好像如果不安装在usr/local目录下会存在不能启动的 ...

  3. 创建React脚手架

    node版本10.14.2 下载地址 如果是其版本的话会出错 css-loader 会不兼容 主要是8.x的版本不兼容 npm install -g create-react-app 全局安装 cre ...

  4. CentOS下搭建docker+.net core

    运行环境: CentOS 7.0 容器:Docker 1.13.1 .Net Core版本: .NET Core 2.1,安装详见 CentOS 7 下安装.NET Core SDK 2.1 1.安装 ...

  5. 小白如何入门 Python 爬虫?

    本文针对初学者,我会用最简单的案例告诉你如何入门python爬虫! 想要入门Python 爬虫首先需要解决四个问题 熟悉python编程 了解HTML 了解网络爬虫的基本原理 学习使用python爬虫 ...

  6. 探索ASP.Net Core 3.0系列二:聊聊ASP.Net Core 3.0 中的Startup.cs

    原文:探索ASP.Net Core 3.0系列二:聊聊ASP.Net Core 3.0 中的Startup.cs 前言:.NET Core 3.0 SDK包含比以前版本更多的现成模板. 在本文中,我将 ...

  7. 2019 红帽杯 Re WP

    0x01 xx 测试文件:https://www.lanzous.com/i7dyqhc 1.准备 获取信息 64位文件 2.IDA打开 使用Findcrypt脚本可以看到 结合文件名是xx,因此猜测 ...

  8. C#批量将数据插入SQLServer数据库

    Database db = CreateDatabase();                var varConnnection = db.CreateConnection();     //获取连 ...

  9. 当页面完全加载完成后执行一个JS函数

    方法1.如下程序,当页面完全加载后执行openTheIndexPage()方法  <html>  <head>  <meta http-equiv="Conte ...

  10. Django之AJAX请求

    ---恢复内容开始--- 一.choices字段  1.实列  前端代码 <div class='container'> <div class="row"> ...