链接

vijos

思路

虽然询问1e7,但他询问很有意思,所以最多修改1e5个。

先把他们修改的点缩小到1e5之内并没有什么影响。

然后维护mul和add。不修改很好弄,修改的点可以弄点式子加加减减弄出来,逆元线性推也是可以的。

总的复杂度\(O(qlogq+tq+mod)\)

总结

我考场上连\(O(n^3)\)都写不对,回来不到一个小时就A了?浮躁!

其实已经写了三遍了、、码力急需加强

代码

#include <bits/stdc++.h>
#define debug(x) cerr << x << " "
using namespace std;
const int N = 1e5 + 7, mod = 1e7 + 19;
int read() {
int x = 0, f = 1; char s = getchar();
for (; s > '9' || s < '0'; s = getchar()) if(s == '-') f = -1;
for (; s >= '0' && s <= '9'; s = getchar()) x = x * 10 + s - '0';
return x * f;
}
int n, q, t, a[107], b[107];
struct QUERY {
int opt, id, val;
} Q[N];
map<int, int> Hash;
int lsh_cnt, inv[N*100], stak[N], top;
struct node {
int val, add, mul;
node() {val = -1, add = 0,mul = 1;}
void clear() {val = -1, add = 0, mul = 1;}
} las[N];
int main() {
// freopen("data.in", "r", stdin);
n = read(), q = read();
for (int i = 1; i <= q; ++i) {
Q[i].opt = read();
if (Q[i].opt == 1) Q[i].id = read(), Q[i].val = read();
if (Q[i].opt == 2 || Q[i].opt == 3 || Q[i].opt == 4) Q[i].val = read();
if (Q[i].opt == 5) Q[i].id = read();
if (Q[i].id && !Hash.count(Q[i].id)) Hash[Q[i].id] = ++lsh_cnt;
while (Q[i].val < 0) Q[i].val += mod;
Q[i].val %= mod;
}
for (int i = 1; i <= q; ++i)
if (Q[i].opt == 1 || Q[i].opt == 5)
Q[i].id = Hash[Q[i].id];
inv[1] = 1;
for (int i = 2; i < mod; ++i)
inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
t = read();
for (int i = 1; i <= t; ++i) a[i] = read(), b[i] = read();
// cerr << "read is ok\n";
int ans = 0, tot = 0, add = 0, mul = 1, init = 0;
for (int i = 1; i <= t; ++i) {
for (int j = 1; j <= q; ++j) {
int x = (a[i] + 1LL * j * b[i]) % q + 1;
// cout<<x<<"\n";
// debug(Q[x].opt),debug(Q[x].id),debug(Q[x].val);cerr<<"\n";
if (Q[x].opt == 1) {
if (las[Q[x].id].val == -1) {
tot = ((tot - (1LL * init * mul % mod + add) % mod) %mod + mod) % mod;
stak[++top] = Q[x].id;
} else {
int now_mul = 1LL * mul * inv[las[Q[x].id].mul] % mod;
int now_add = ((add - 1LL * las[Q[x].id].add * now_mul % mod) % mod + mod) % mod;
tot = ((tot - (1LL * las[Q[x].id].val * now_mul % mod + now_add) % mod) % mod + mod) % mod;
}
tot = (tot + Q[x].val) % mod;
las[Q[x].id].val = Q[x].val;
las[Q[x].id].add = add;
las[Q[x].id].mul = mul;
}
if (Q[x].opt == 2) {
add = (add + Q[x].val) % mod;
tot = (tot + 1LL * Q[x].val * n % mod) % mod;
}
if (Q[x].opt == 3) {
add = 1LL * add * Q[x].val % mod;
mul = 1LL * mul * Q[x].val % mod;
tot = 1LL * tot * Q[x].val % mod;
}
if (Q[x].opt == 4) {
while (top) las[stak[top--]].clear();
init = Q[x].val, add = 0, mul = 1;
tot = 1LL * Q[x].val * n % mod;
}
if (Q[x].opt == 5) {
if (las[Q[x].id].val == -1) {
ans = ((ans + (1LL * init * mul % mod + add) % mod) %mod + mod) % mod;
} else {
int now_mul = 1LL * mul * inv[las[Q[x].id].mul] % mod;
int now_add = ((add - 1LL * las[Q[x].id].add * now_mul % mod) % mod + mod) % mod;
ans = ((ans + (1LL * las[Q[x].id].val * now_mul % mod + now_add) % mod) % mod + mod) % mod;
}
}
if (Q[x].opt == 6) ans = (ans + tot) % mod;
}
}
printf("%lld\n", ans);
return 0;
}
/*
5 5
6
6
3 4
1 3 8
5 5
1
8062 15996
*/

SDOI2019快速查询的更多相关文章

  1. [SDOI2019]快速查询——模拟

    题目链接: [SDOI2019]快速查询 对于整个序列维护一个标记$(k,b)$表示序列的每个数的真实值为$k*a_{i}+b$(注意要实时维护$k$的逆元),并记录序列的和. 对于单点修改,将$a_ ...

  2. [SDOI2019]快速查询

    [SDOI2019]快速查询 [题目链接] 链接 [思路要点] 据说是 \(\text{SDOI2019}\) 最水的题 操作次数为 \(1e7\) 范围,显然要求每次操作 \(\mathcal{O} ...

  3. luogu P5358 [SDOI2019]快速查询【模拟(?)】

    把有单点修改和查询的点离散进一个数组,然后单点修改直接改,记录一个修改时间t,维护一个sm表示这些离散的点的和,val表示出了离散点其他点的值,因为都是一样的所以只记录这一个值即可,记录ljlc为加法 ...

  4. vijos2051 SDOI2019 快速查询

    题目链接 吐槽 竟然让\(nlog\)的做法卡过去了.. 思路 因为\(1 \le q \le 10^5\),所以可以先对每个标准操作,所操作的位置进行重标号.这样所有的下标都是在\(10^5\)以内 ...

  5. 【题解】Luogu P5358 [SDOI2019]快速查询

    原题传送门 神鱼说这道题是强制离线(smog 我们珂以把被单点修改,单点查询的点单独拿出来处理,把每个数表示成\(mul*x+plus\) 初始状态下\(mul=1,plus=0\) 操作1:在总和中 ...

  6. 【洛谷5358】[SDOI2019] 快速查询(模拟)

    点此看题面 大致题意: 有单点赋值.全局加法.全局乘法.全局赋值.单点求值.全局求和\(6\)种操作.现在给出操作序列,以及\(t\)对正整数\(a_i,b_i\).让你处理\(t*q\)次操作,每次 ...

  7. P5358 [SDOI2019]快速查询

    思路:...乱搞数据结构?? 提交:1次 题解: 观察到除了单点就是全局操作,所以我们维护一个全局加法标记add和乘法标记mul和答案sum. 单点修改时,比如我们要把 \(pos\) 位置改成 \( ...

  8. 快速查询Python脚本语法

    /********************************************************************* * 快速查询Python脚本语法 * 说明: * Char ...

  9. 一种快速查询多点DS18B20温度的方法(转)

    源:http://hi.baidu.com/james_xiao/item/79b961c90623093e45941623 一种快速查询多点DS18B20温度的方法 引言      为了满足实时性要 ...

随机推荐

  1. router单页面多个标签tags的用法<router-view></router-view>

    <keep-alive><router-view :key="path" /></keep-alive>

  2. vue.js 实现粒子特效之插件( vue-particles )

    首先先一张效果图 图上那些类似于星座图的点和线,是由vue-particles生成的,不仅自己动,而且能与用户鼠标事件产生互动. 使用教程: npm install vue-particles --s ...

  3. 49.react中使用less

    1.安装less:npm install less less-loader --save 2.webpack.config.js中配置: oneOf: [ {   test: /\.less$/,   ...

  4. Java 数据类型 & 变量与常量 & 注释

    一.数据类型 1.数据类型分类 Java 的数据类型分为两大类: 基本数据类型:整数.浮点数.字符型.布尔型 引用数据类型(对象类型):类.数组,字符串.接口等. 2.基本数据类型 四类八种基本数据类 ...

  5. JavaScript 数组(三)数组方法

    常用方法及案例参考这篇:数组对象及常用方法

  6. Python人工智能常用库Numpy使用入门

    第一章 jupyter notebook简单教程 命令模式按键esc开启 Enter : 转入编辑模式 Shift-Enter : 运行本单元,选中下个单元 Ctrl-Enter : 运行本单元 Al ...

  7. 安卓样式Style和主题Theme

    1. 区别 不过style是针对view来说的,比如TextView和EditText这些:而Theme必须针对整个activity或者整个application 2. 样式 创建一个样式,根元素 & ...

  8. SAP CDS重定向视图和直接读这两者场景的性能比较

    A very rough performance comparison is performed in ER9/001. Comparison scenario The two below opera ...

  9. Ubuntu 18.04 + Gtx 1660 安装Nvidia 显卡驱动

    1.UEFI禁用secure boot(我的系统是win10主系统,引导ubuntu,安装驱动前电脑存在win10 uefi引导问题) Make sure the "OS Type" ...

  10. 记一次wxpy开发经历

    常在河边走,哪有不湿鞋,没想到搞这个花了半天时间.