「LibreOJ NOI Round #2」单枪匹马
嘟嘟嘟
这题没卡带一个\(log\)的,那么就很水了。
然后我因为好长时间没写矩阵优化dp,就只敲了一个暴力分……看来复习还是很关键的啊。
这个函数显然是从后往前递推的,那么令第\(i\)位的分子分母为\(x', y'\),第\(i + 1\)的为\(x, y\),因为\(f(i) = a_i + \frac{1}{f(i + 1)} = \frac{a_i * f(i + 1) + 1}{f(i + 1)}\),所以\(x' = a_i * x + y, y' = x\)。
这样我们把\(x, y\)看成\(f[i][0],f[i][1]\),就很容易构造矩阵了。
然后线段树维护矩阵即可。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<queue>
#include<assert.h>
#include<ctime>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
#define forE(i, x, y) for(int i = head[x], y; ~i && (y = e[i].to); i = e[i].nxt)
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1e6 + 5;
const ll mod = 998244353;
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');
}
In void MYFILE()
{
#ifndef mrclr
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
}
int n, m, N, cnt, T;
In ll inc(ll a, ll b) {return a + b < mod ? a + b : a + b - mod;}
#define LS t[now].ls
#define RS t[now].rs
struct Tree
{
int ls, rs;
ll a[2][2];
In Tree operator + (const Tree& oth)const
{
Tree ret; Mem(ret.a, 0);
for(int i = 0; i < 2; ++i)
for(int j = 0; j < 2; ++j)
for(int k = 0; k < 2; ++k)
ret.a[i][j] = inc(ret.a[i][j], a[i][k] * oth.a[k][j] % mod);
return ret;
}
}t[maxn * 20];
int tcnt = 0, root = 0;
In void insert(int l, int r, int& now, int id, ll d)
{
if(!now) now = ++tcnt;
if(l == r)
{
t[now].a[0][0] = d, t[now].a[1][1] = 0;
t[now].a[1][0] = t[now].a[0][1] = 1;
return;
}
int mid = (l + r) >> 1;
if(id <= mid) insert(l, mid, LS, id, d);
else insert(mid + 1, r, RS, id, d);
int tp1 = LS, tp2 = RS;
t[now] = t[LS] + t[RS];
LS = tp1, RS = tp2;
}
In Tree query(int l, int r, int now, int L, int R)
{
if(l == L && r == R) return t[now];
int mid = (l + r) >> 1;
if(R <= mid) return query(l, mid, LS, L, R);
else if(L > mid) return query(mid + 1, r, RS, L, R);
else return query(l, mid, LS, L, mid) + query(mid + 1, r, RS, mid + 1, R);
}
int main()
{
// MYFILE();
n = read(), m = read(), T = read();
N = n + m, cnt = n;
for(int i = 1; i <= cnt; ++i) insert(1, N, root, i, read());
ll ansX = 0, ansY = 0;
for(int i = 1; i <= m; ++i)
{
int op = read();
if(op == 1)
{
int x = read();
if(T) x ^= ansX ^ ansY;
insert(1, N, root, ++cnt, x);
}
else
{
int L = read(), R = read();
if(T) L ^= ansX ^ ansY, R ^= ansX ^ ansY;
Tree tp = query(1, N, root, L, R);
write(ansX = tp.a[0][0]), space, write(ansY = tp.a[1][0]), enter;
}
}
return 0;
}
「LibreOJ NOI Round #2」单枪匹马的更多相关文章
- 「LibreOJ NOI Round #2」不等关系
「LibreOJ NOI Round #2」不等关系 解题思路 令 \(F(k)\) 为恰好有 \(k\) 个大于号不满足的答案,\(G(k)\) 表示钦点了 \(k\) 个大于号不满足,剩下随便填的 ...
- LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿
二次联通门 : LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿 /* LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿 dp 记录一下前驱 ...
- 「LibreOJ NOI Round #1」验题
麻烦的动态DP写了2天 简化题意:给树,求比给定独立集字典序大k的独立集是哪一个 主要思路: k排名都是类似二分的按位确定过程. 字典序比较本质是LCP下一位,故枚举LCP,看多出来了多少个独立集,然 ...
- #509. 「LibreOJ NOI Round #1」动态几何问题
下面给出部分分做法和满分做法 有一些奇妙的方法可以拿到同样多的分数,本蒟蒻只能介绍几种常见的做法 如果您想拿18分左右,需要了解:质因数分解 如果您想拿30分左右,需要了解:一种较快的筛法 如果您想拿 ...
- #510. 「LibreOJ NOI Round #1」动态几何问题
题目: 题解: 几何部分,先证明一下 \(KX = \sqrt{a},YL = \sqrt{b}\) 设左侧的圆心为 \(O\) ,连接 \(OK\) ,我们有 \(OK = r\). 然后有 \(r ...
- #507. 「LibreOJ NOI Round #1」接竹竿 dp
题目: 题解: 我们考虑把每对花色相同的牌看作区间. 那么如果我们设 \(f_i\) 表示决策在 \([1,i]\) 内的最优答案. 那么有 \(f_i = max\{max\{(f_{j-1}+\s ...
- LOJ#510. 「LibreOJ NOI Round #1」北校门外的回忆(线段树)
题面 传送门 题解 感谢\(@M\_sea\)的代码我总算看懂题解了-- 这个操作的本质就是每次把\(x\)的\(k\)进制最低位乘\(2\)并进位,根据基本同余芝士如果\(k\)是奇数那么最低位永远 ...
- LOJ 510: 「LibreOJ NOI Round #1」北校门外的回忆
题目传送门:LOJ #510. 题意简述: 给出一个在 \(K\) 进制下的树状数组,但是它的实现有问题. 形式化地说,令 \(\mathrm{lowbit}(x)\) 为在 \(K\) 进制下的 \ ...
- LOJ575. 「LibreOJ NOI Round #2」不等关系 [容斥,分治FFT]
LOJ 思路 发现既有大于又有小于比较难办,使用容斥,把大于改成任意减去小于的. 于是最后的串就长成这样:<<?<?<??<<<?<.我们把一段连续的& ...
随机推荐
- js 简单的滑动4
js 简单的滑动教程(四) 作者:Lellansin 转载请标明出处,谢谢 在大概的了解滑动的基本原理和怎么去实现之后,现在我们将更深入的去讨论js的滑动. 相信细心的朋友应该已经发现了,在本教程 ...
- 【面试突击】- SpringMVC那些事(一)
1.什么是Spring MVC ?简单介绍下你对springMVC的理解? Spring MVC是一个基于MVC架构的用来简化web应用程序开发的应用开发框架,它是Spring的一个模块,无需中间整合 ...
- elementui switch 开关,点击确认按钮后在进行开关
<el-table-column label="上头条" align="center"> <template slot-scope=" ...
- iOS进阶之多线程--NSThread详解
NSThread简介 NSThread是苹果官方提供面向对象操作线程的技术,简单方便,可以直接操作线程对象,不过需要自己控制线程的生命周期.在平时使用很少,最常用到的无非就是 [NSThread cu ...
- [破解版]Unity3d引擎最新稳定版本4.5.5下载(官方最新稳定版本)
来源:http://www.unitymanual.com/thread-28912-1-1.html unity4.5.5 Mac版下载地址:http://pan.baidu.com/s/1hqzi ...
- MySQL Binlog--PURGE MASTER LOGS失败
问题背景: 在我们磁盘空间维护策略中,BINLOG的默认保留期限为7天,但当磁盘空间不足时,会根据磁盘空间使用率自动清理超过一定数量的BINLOG. 问题原因: 某服务器上报磁盘空间不足,登录服务器发 ...
- [nginx] nginx源码分析--监控检测模块
描述 HTTP监控检查,是nginx官网推荐使用的第三方模块 https://www.nginx.com/resources/wiki/modules/healthcheck/ https://git ...
- jquery属性文档事件等操作
1.jq方法attr removeAttr script标签大部分都是写在body标签上.下面的情况下$符号是拿不到的. 将它放到上面就能拿到$对象了.但是不能获取body里的元素.因为代码执行顺序从 ...
- 基于k8s集群部署prometheus监控etcd
目录 基于k8s集群部署prometheus监控etcd 1.背景和环境概述 2.修改prometheus配置 3.检查是否生效 4.配置grafana图形 基于k8s集群部署prometheus监控 ...
- Something is already running on port 3000. Would you like to run the app on another port instead?
查看端口sudo lsof -i :3000 删除进程 sudo kill -9 12297[pid]