BZOJ3813: 奇数国
欧拉函数+线段树
因为只有60个素数,所以把状态压成long long的形式。用线段树维护区间和和区间和中有多少个质数。然后xjb搞搞就行了,具体参见代码。
//BZOJ 3813
//by Cydiater
//2016.10.10
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <ctime>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
#define ll long long
#define up(i,j,n) for(ll i=j;i<=n;i++)
#define down(i,j,n) for(ll i=j;i>=n;i--)
const ll MAXN=1e6+5;
const ll oo=1LL<<60;
const ll mod=19961993;
const ll LIM=1e6;
const ll N=1e5;
inline ll read(){
char ch=getchar();ll x=0,f=1;
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll inv[MAXN],prime[MAXN],cnt=0,T,x,y,k,v;
struct Tree{
ll S,v;
}t[MAXN<<2];
bool vis[MAXN];
namespace solution{
void exgcd(ll a,ll b,ll &x,ll &y){
if(b==0){x=1;y=0;return;}
exgcd(b,a%b,x,y);
ll t=x;x=y;y=t-a/b*y;
}
ll get_inv(ll a,ll b){
ll x,y;
exgcd(a,b,x,y);
while(x<0)x+=b;
return x;
}
ll get_suf(ll S){
ll ans=1;
up(i,0,59)if((1LL<<i)&S)
ans=(ans*(prime[i+1]-1)%mod*inv[i+1]%mod)%mod;
return ans;
}
ll get_two(ll num){
ll S=0;
up(i,1,60)if(num%prime[i]==0)S|=(1LL<<(i-1));
return S;
}
Tree merge(Tree x,Tree y){
x.S|=y.S;
(x.v*=y.v)%=mod;
return x;
}
void pret(){
memset(vis,0,sizeof(vis));
up(i,2,LIM){
if(!vis[i])prime[++cnt]=i;
up(j,1,cnt){
if(prime[j]*i>LIM)break;
vis[i*prime[j]]=1;
if(i%prime[j]==0)break;
}
}
up(i,1,60)inv[i]=get_inv(prime[i],mod);
}
void build(int leftt,int rightt,int root){
if(leftt==rightt){
t[root].S=1<<1;
t[root].v=3;
return;
}
int mid=(leftt+rightt)>>1;
build(leftt,mid,root<<1);
build(mid+1,rightt,root<<1|1);
t[root].S=t[root<<1].S|t[root<<1|1].S;
t[root].v=t[root<<1].v*t[root<<1|1].v%mod;
}
Tree get(int leftt,int rightt,int root){
if(leftt>y||rightt<x) return (Tree){0,1};
if(leftt>=x&&rightt<=y) return t[root];
int mid=(leftt+rightt)>>1;
Tree tmp=merge(get(leftt,mid,root<<1),get(mid+1,rightt,root<<1|1));
return tmp;
}
void updata(int leftt,int rightt,int root){
if(leftt>k||rightt<k) return;
if(leftt==rightt){
t[root].v=v;
t[root].S=get_two(v);
return;
}
int mid=(leftt+rightt)>>1;
updata(leftt,mid,root<<1);
updata(mid+1,rightt,root<<1|1);
t[root]=merge(t[root<<1],t[root<<1|1]);
}
void slove(){
T=read();
while(T--){
ll a=read(),b=read(),c=read();
if(a==0){
x=b;y=c;
Tree tmp=get(1,N,1);
printf("%lld\n",tmp.v*get_suf(tmp.S)%mod);
}else{
k=b;v=c;
updata(1,N,1);
}
}
}
}
int main(){
//freopen("input.in","r",stdin);
using namespace solution;
pret();
build(1,N,1);
slove();
return 0;
}
BZOJ3813: 奇数国的更多相关文章
- [BZOJ3813] 奇数国 - 线段树
3813: 奇数国 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 912 Solved: 508[Submit][Status][Discuss] ...
- [bzoj3813] 奇数国 [线段树+欧拉函数]
题面 传送门 思路 这题目是真的难读......阅读理解题啊...... 但是理解了以后就发现,题目等价于: 给你一个区间,支持单点修改,以及查询一段区间的乘积的欧拉函数值,这个答案对19961993 ...
- 【BZOJ3813】奇数国 线段树+欧拉函数
[BZOJ3813]奇数国 Description 给定一个序列,每次改变一个位置的数,或是询问一段区间的数的乘积的phi值.每个数都可以表示成前60个质数的若干次方的乘积. Sample Input ...
- 【bzoj3813】: 奇数国 数论-线段树-欧拉函数
[bzoj3813]: 奇数国 题意:给定一个序列,每个元素可以分解为最小的60个素数的形式.(x=p1^k1*p2^k2*......p60^k60)(p1=2,p2=3,…,p60=281) 支持 ...
- [BZOJ 3813]奇数国
3813: 奇数国 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 736 Solved: 416[Submit][Status][Discuss] ...
- AC日记——【清华集训2014】奇数国 uoj 38
#38. [清华集训2014]奇数国 思路: 题目中的number与product不想冲: 即为number与product互素: 所以,求phi(product)即可: 除一个数等同于在模的意义下乘 ...
- Bzoj 3813 奇数国 题解 数论+线段树+状压
3813: 奇数国 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 748 Solved: 425[Submit][Status][Discuss] ...
- HYSBZ - 3813 奇数国 欧拉函数+树状数组(线段树)
HYSBZ - 3813奇数国 中文题,巨苟题,巨无敌苟!!首先是关于不相冲数,也就是互质数的处理,欧拉函数是可以求出互质数,但是这里的product非常大,最小都2100000,这是不可能实现的.所 ...
- 【BZOJ3813】【清华集训2014】奇数国 线段树 数学
题目描述 给你一个长度为\(n\)的数列,第\(i\)个数为\(a_i\).每个数的质因子都只有前\(60\)个质数.有\(q\)个询问,每次给你\(l,r\),求\(\varphi(\prod_{i ...
随机推荐
- 基于PHP的AJAX学习笔记(教程)
本文转载自:http://www.softeng.cn/?p=107 这是本人在学习ajax过程所做的笔记,通过本笔记的学习,可以完成ajax的快速入门.本笔记前端分别使用原生态的javascript ...
- Scala入门详解
object作为Scala中的一个关键字,相当于Java中的public static class这样的一个修饰符,也就说object中的成员都是静态的! 所以我们在这个例子中的main方法是静态的, ...
- 流量工程 traffic engineering (TE)
什么是流量工程 流量工程是指根据各种数据业务流量的特性选取传输路径的处理过程.流量工程用于平衡网络中的不同交换机.路由器以及链路之间的负载. [编辑] 流量工程的内容 流量工程在复杂的网络环境中,控制 ...
- Trilateration三边测量定位算法
转载自Jiaxing / 2014年2月22日 基本原理 Trilateration(三边测量)是一种常用的定位算法: 已知三点位置 (x1, y1), (x2, y2), (x3, y3) 已知未知 ...
- JS iframe元素和父页面元素互访
说明:以下内容来自互联网 [1]子页面取得父页面的dom对象 parent.window.$('#id').val(""); [2]父页面取得子页面的对象 $(wind ...
- web单页应用(1)--第一个SPA
<!doctype html> <html> <head> <title>第一个SPA</title> <style type=&qu ...
- zabbix自动发现功能实现批量web url监控
需求: 现在有大量url需要监控,形式如http://www.baidu.com ,要求url状态不为200即报警. 需求详细分析: 大量的url,且url经常变化,现在监控用的是zabbix,如果手 ...
- PHP 解析 ElasticSearch 的 json 方法,有關遍歷所有 json 元素
以下是eleasticsearch返回的json資料:{"took" : 12,"timed_out" : false,"_shards" ...
- 日期处理-将String 转为Date
package com.test; import java.text.DateFormat; import java.text.ParseException; import java.text.Sim ...
- mysql-case ... when...then...else...end处理判断赋值机制
then jrkp else zrspj end ))/(case zrspj then jrkp else zrspj end ) zdf from hqxg order by zdf LIMIT ...