嘟嘟嘟

半年不写splay,一写就半年……
辛亏我长精神头复习了一下,要不然考场上遇到平衡树的题肯定废了。

这道题,无非就让你求这么几个事儿:
1.区间加。
2.区间乘。
3.区间向后移一位。
4.代数求和。

对于查询操作,因为最多不超过10次,所以单次\(O(nlogn)\)暴力就好了。

前两个操作不说了。

对于第三个操作,要动一点脑子:相当于把第\(L\)位清零,\([L + 1, R - 1]\)向右移一位,最后第\(R + 1\)位加上第\(R\)位的值。
于是我一直在想,怎么实现区间平移的操作。后来发现只要在\(L\)之前插入一个权值为0的节点就完事了,同时处理了清零和平移一位的操作。
然后就是单点加和删除节点了。
不过第三个操作整体很坑。细节比较麻烦:插入完节点后,第\(R\)位就变成了第\(R + 1\)位,所以应该删的是\(R + 1\),不是\(R\)。
代码中懒得写垃圾回收了,索性开了二倍的空间。
然后因为没有告诉最高次项,所以又开了个变量Max维护最高次。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1e5 + 5;
const ll mod = 20130426;
inline ll read()
{ll ans = 0;char ch = getchar(), last = ' ';while(!isdigit(ch)) last = ch, ch = getchar();while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();if(last == '-') ans = -ans;return ans;
}
inline void write(ll x)
{if(x < 0) x = -x, putchar('-');if(x >= 10) write(x / 10);putchar(x % 10 + '0');
}char s[10];
int n, Max = 0;
struct Tree
{int ch[2], fa, siz;ll val, add, mul;
}t[maxn << 1];
int root, tcnt = 0;In ll mul(ll a, ll b) {return a * b % mod;}
In ll inc(ll a, ll b) {return a + b >= mod ? a + b - mod : a + b;}In ll quickpow(ll a, ll b)
{ll ret = 1;for(; b; b >>= 1, a = a * a % mod)if(b & 1) ret = ret * a % mod;return ret;
}In void c_mul(int now, ll d)
{t[now].val = mul(t[now].val, d);t[now].mul = mul(t[now].mul, d); t[now].add = mul(t[now].add, d);
}
In void c_add(int now, ll d)
{t[now].val = inc(t[now].val, d);t[now].add = inc(t[now].add, d);
}
In void pushdown(int now)
{if(t[now].mul ^ 1){if(t[now].ch[0]) c_mul(t[now].ch[0], t[now].mul);if(t[now].ch[1]) c_mul(t[now].ch[1], t[now].mul);t[now].mul = 1;}if(t[now].add){if(t[now].ch[0]) c_add(t[now].ch[0], t[now].add);if(t[now].ch[1]) c_add(t[now].ch[1], t[now].add);t[now].add = 0;      }
}
In void pushup(int now)
{t[now].siz = t[t[now].ch[0]].siz + t[t[now].ch[1]].siz + 1;
}
In void rotate(int x)
{int y = t[x].fa, z = t[y].fa, k = (t[y].ch[1] == x);t[z].ch[t[z].ch[1] == y] = x, t[x].fa = z;t[y].ch[k] = t[x].ch[k ^ 1], t[t[y].ch[k]].fa = y;t[x].ch[k ^ 1] = y, t[y].fa = x;pushup(y), pushup(x);
}
In void splay(int x, int s)
{while(t[x].fa ^ s){int y = t[x].fa, z = t[y].fa;if(z ^ s) rotate(((t[y].ch[0] == x) ^ (t[z].ch[0] == y)) ? x : y);rotate(x);}if(!s) root = x;
}In void _PrintTr(int now)
{ if(!now) return;pushdown(now);printf("now:%d val:%lld ls:%d rs:%d\n", now, t[now].val, t[now].ch[0], t[now].ch[1]);_PrintTr(t[now].ch[0]), _PrintTr(t[now].ch[1]);
}In int build(int L, int R, int _f)
{if(L > R) return 0;int mid = (L + R) >> 1, now = ++tcnt;if(_f) t[now].fa = _f;t[now].siz = 1;t[now].val = (mid == 1 || mid == maxn - 2) ? -INF : 0;t[now].add = 0, t[now].mul = 1;t[now].ch[0] = build(L, mid - 1, now);t[now].ch[1] = build(mid + 1, R, now);pushup(now);return now;
}In int find(int k)
{int now = root;while("ACAC!"){pushdown(now);if(t[t[now].ch[0]].siz >= k) now = t[now].ch[0];else if(t[t[now].ch[0]].siz + 1 == k) return now;else k -= (t[t[now].ch[0]].siz + 1), now = t[now].ch[1];}
}
In void split(int L, int R)
{int a = find(L), b = find(R + 2);splay(a, 0), splay(b, a);pushdown(root), pushdown(t[root].ch[1]);
}In void change(int L, int R)
{int a = find(L), b = find(L + 1);splay(a, 0), splay(b, a);pushdown(root), pushdown(t[root].ch[1]);int now = t[root].ch[1], p = ++tcnt;t[now].ch[0] = p;t[p].fa = now, t[p].siz = 1;t[p].add = t[p].val = 0, t[p].mul = 1;splay(p, 0);split(R + 1, R + 1);now = t[root].ch[1], p = t[now].ch[0];t[now].val = inc(t[now].val, t[p].val);--t[now].siz;t[now].ch[0] = 0, t[p].fa = 0;splay(now, 0);
}In ll query(int x)
{int a = find(x + 1); splay(a, 0);return t[root].val;
}int main()
{//  freopen("ha.in", "r", stdin);//  freopen("ha.out", "w", stdout);n = read();root = build(1, maxn - 2, 0);for(int i = 1; i <= n; ++i){scanf("%s", s);if(s[3] == 'x'){int L = read() + 1, R = read() + 1;change(L, R);Max = max(Max, R + 1);}else if(s[0] == 'a'){int L = read() + 1, R = read() + 1, d = read();Max = max(Max, R);split(L, R), c_add(t[t[root].ch[1]].ch[0], d);}else if(s[0] == 'm'){int L = read() + 1, R = read() + 1, d = read();Max = max(Max, R);split(L, R), c_mul(t[t[root].ch[1]].ch[0], d);}else{ll d = read(), ans = 0;for(int j = 1; j <= Max; ++j)ans = inc(ans, mul(query(j), quickpow(d, j - 1)));write(ans), enter;}}return 0;
}

转载于:https://www.cnblogs.com/mrclr/p/10479094.html

[SCOI2013]多项式的运算相关推荐

  1. BZOJ3323: [Scoi2013]多项式的运算

    题解: 直接splay就好了 这题最大的亮点是 区间平移 我们可以通过把r和r+1节点合并 然后在l-1加上一个节点实现 #include <bits/stdc++.h> const in ...

  2. BZOJ 3323: [Scoi2013]多项式的运算

    Description 某天,mzry1992 一边思考着一个项目问题一边在高速公路上骑着摩托车.一个光头踢了他一脚,摩托车损坏,而他也被送进校医院打吊针.现在该项目的截止日期将近,他不得不请你来帮助 ...

  3. bzoj3323【scoi2013】多项式的运算

    3323: [Scoi2013]多项式的运算 Time Limit: 12 Sec  Memory Limit: 64 MB Submit: 232  Solved: 69 [Submit][Stat ...

  4. matlab多项式加法运算,matlab多项式运算与代数方程求解解析.ppt

    * 多项式运算与代数方程求解 数学软件 Matlab Matlab基础及应用 * 多项式转化为符号表达式:poly2sym 四则运算:conv.deconv 导数与积分:ployder.polyint ...

  5. matlab多项式及其运算

    0 创建多项式 多项式的一般形式如下: 我们可以使用它的系数向量来表示, matlab中,提供了poly2sym函数实现多项式的构造. r = poly2sym(c):c为多项式的系数向量 r = p ...

  6. [题解] BZOJ 3323 多项式的运算

    BZOJ 3323 多项式的运算 题目描述 Description 某天,mzry1992一边思考着一个项目问题一边在高速公路上骑着摩托车.一个光头踢了他一脚,摩托车损坏,而他也被送进校医院打吊针.现 ...

  7. 【SCOI2013】【BZOJ3323】多项式的运算

    Description 某天,mzry1992 一边思考着一个项目问题一边在高速公路上骑着摩托车.一个光头踢了他一脚,摩托车损坏,而他也被送进校医院打吊针.现在该项目的截止日期将近,他不得不请你来帮助 ...

  8. 快速数论变换与多项式常用运算

    导入 一般来说,我们需要进行的操作是在模意义下的. 此时我们就无法使用单位根和实数意义下的FFT了. 我们的解决办法是: 原根 我们选择单位根是因为其具有良好的性质可以被我们利用. 如果我们在模意义下 ...

  9. matlab实现多项式的运算,Matlab 多项式运算

    一.多项式的表示方法 1.系数向量直接输入法 例1: >> p = [1 -5 6 -33]; >> poly2sym(p) ans = x^3 - 5*x^2 + 6*x – ...

最新文章

  1. 使用C++实现一套简单的状态机模型——实例
  2. 清华大学朱文武团队夺冠AAAI 2021国际深度元学习挑战赛
  3. ELMo:基于上下文的语言模型,5分钟构建语义搜索引擎代码实战
  4. 步子太快容易牺牲精度,梯度下降复杂度这一简单道理,获严格数学证明
  5. Navicat 9如何连接ORACLE10G数据库
  6. Linux / offsetof 和 container_of
  7. android xml 解析天气,Retrofit2解析天气API XML接口
  8. linux如何开启sni服务,Nginx开启单IP多SSL证书支持-TLS SNI support
  9. Flink的scala+python的shell模式实验记录汇总
  10. Spring 常见的一些面试题整理
  11. leetcode力扣12. 整数转罗马数字
  12. C++ STL 数据结构与算法 —— 排序
  13. python注册登录代码_python基础--注册和登录功能 代码
  14. android tf卡 修复工具,SD卡恢复修复工具RecoveRx 3.2中文免费版
  15. 《Multi-Stream Gated and Pyramidal Temporal Convolutional Neural Networksfor Audio-Visual Speech Se》
  16. 计算机系单身率排行榜,2020中国高校单身率排行榜出炉!附:单身率特别高的专业...
  17. 操作系统课设——Windows 进程管理
  18. WPS格式的文件如何转换为word格式
  19. 盘点各大互联网公司2017中秋月饼设计,你最喜欢哪一个?
  20. 按月显示的万年历(含农历)网页代码

热门文章

  1. 论 ACM 与泡妞 (转载)
  2. Oracle分析函数三——SUM,AVG,MIN,MAX,COUNT
  3. 关于db link权限分配的苦旅(一)
  4. 金山称清理专家遭微软误杀:正积极协商解决
  5. Java社区目前的现状——交易
  6. 用两种不同的方法导出ORACLE 查询数据为CSV 文件 (python 代码 与 使用 utl_file 包)
  7. 人类大脑每日24小时工作节奏表
  8. Android下EditText中的字体不统一问题
  9. WinLaucher启动
  10. android WebView的简单使用