ODT(主要特征就是推平一段区间)

其实就是用set来维护三元组,因为数据随机所以可以证明复杂度不超过O(NlogN),其他的都是暴力维护

主要操作是split,把区间分成两个,用lowerbound,

有两点需要注意1.set里的东西不能改,所以变成了mutable(可改的const),2.s.insert返回pair类型,first是插入点的迭代器

= =sort里的比较函数ll没开wa了好久

精简版:

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
//inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=200000+10,maxn=50000+10,inf=0x3f3f3f3f; struct ODT{
struct node{
int l,r;mutable ll val;
node(int _l,int _r = -1,ll _val = 0):l(_l),r(_r),val(_val){}
bool operator <(const node&rhs)const{
return l<rhs.l;
}
};
set<node>s;
typedef set<node>::iterator sit;
void ins(int l,int r,ll val){s.insert(node(l,r,val));}
sit split(int pos)
{
sit p=s.lower_bound(node(pos));
if(p != s.end() && pos == p->l)return p;
p--;node te=*p;
s.erase(p);
s.insert(node(te.l,pos-1,te.val));
return s.insert(node(pos,te.r,te.val)).fi;
}
void add(int l,int r,ll v)
{
sit x=split(l),y=split(r+1);
for(;x!=y;x++)x->val += v;
}
void color(int l,int r,ll val)
{
sit x= split(l),y=split(r+1);
s.erase(x,y);
s.insert(node(l,r,val));
}
void kth(int l,int r,ll k)
{
sit x = split(l),y = split(r+1);
vector<pli>v;
for(;x!=y;x++)
v.pb(mp(x->val,x->r - x->l + 1));
sort(v.begin(),v.end(),[](pli a,pli b){return a.fi>b.fi;});
for(int i=(int)v.size()-1;i>=0;i--)
{
if(k<=v[i].se)
{
printf("%lld\n",v[i].fi);
return ;
}
k-=v[i].se;
}
}
void sum(int l,int r,ll a,ll b)
{
sit x = split(l),y=split(r+1);
ll ans=0;
for(;x!=y;x++)
{
ans+=1ll*qp(x->val % b,a,1ll*b)*(x->r - x->l + 1)%b;
if(ans>=b)ans-=b;
}
printf("%lld\n",ans);
}
void debug()
{
for(auto x:s)
printf("%d %d %d\n",x.l,x.r,x.val);
puts("");
}
}o;
ll n,m,seed,vmax,a[N];
ll rnd()
{
ll ret = seed;
seed = (seed * 7ll + 13)%1000000007;
return ret;
}
int main()
{
// o.ins(1,1,3);o.ins(2,2,4),o.ins(3,5,6);
// o.add(2,3,2);
// o.debug();
scanf("%lld%lld%lld%lld",&n,&m,&seed,&vmax);
for(int i=1;i<=n;i++)
{
a[i] = (rnd()%vmax) + 1;
o.ins(i,i,a[i]);
}
o.ins(n+1,n+1,0);
int res=0;
for(int i=1;i<=m;i++)
{
int op = (rnd()%4) + 1;
int l = (rnd()%n) + 1;
int r = (rnd()%n) + 1;
ll x,y;
if (l > r)swap(l, r);
if (op == 3)x = (rnd()%(r - l + 1)) + 1;
else x = (rnd()%vmax) + 1;
if (op == 4)y = (rnd()%vmax) + 1;
if(op==1)o.add(l,r,x);
else if(op==2)o.color(l,r,x);
else if(op==3)o.kth(l,r,x);
else o.sum(l,r,x,y);
// o.debug();
// printf("%d %d %d %d %d\n",op,l,r,x,y);
}
return 0;
}
/******************** ********************/

自已刚开始意淫的一个写法:

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=200000+10,maxn=50000+10,inf=0x3f3f3f3f; struct ODT{
struct node{
int l,r;mutable ll val;
bool operator <(const node&rhs)const{
return l<rhs.l || l==rhs.l&&r<rhs.r;
}
};
set<node>s;
void split(int pos)
{
if(pos<=0)return ;
auto p=s.upper_bound(node{pos,inf,INF});
if(p==s.begin())return ;
p--;
// printf("--------%d %d %d\n",p->l,p->r,p->val);
if(pos < p->l || pos >= p->r)return ;
node te=*p;
s.erase(te);
s.insert({te.l,pos,te.val});
s.insert({pos+1,te.r,te.val});
}
void add(int l,int r,ll v)
{
split(l-1),split(r);
auto x=s.lower_bound(node{l,-inf,-INF});
auto y=s.lower_bound(node{r,inf,INF});
for(;x!=y;x++)x->val += v;
}
void color(int l,int r,ll val)
{
split(l-1);split(r);
auto x=s.lower_bound(node{l,-inf,-INF});
auto y=s.lower_bound(node{r,inf,INF});
// printf("%d %d %d %d\n",x->l,x->r,y->l,y->r);
s.erase(x,y);
s.insert({l,r,val});
}
void kth(int l,int r,ll k)
{
split(l-1);split(r);
auto x=s.lower_bound(node{l,-inf,-INF});
auto y=s.lower_bound(node{r,inf,INF});
vector<pli>v;
for(;x!=y;x++)
v.pb(mp(x->val,x->r - x->l + 1));
sort(v.begin(),v.end(),[](pli a,pli b){return a.fi>b.fi;});
for(int i=(int)v.size()-1;i>=0;i--)
{
if(k<=v[i].se)
{
printf("%lld\n",v[i].fi);
return ;
}
k-=v[i].se;
}
}
void sum(int l,int r,ll a,ll b)
{
split(l-1);split(r);
auto x=s.lower_bound(node{l,-inf,-INF});
auto y=s.lower_bound(node{r,inf,INF});
ll ans=0;
for(;x!=y;x++)
{
ans+=1ll*qp(x->val % b,a,1ll*b)*(x->r - x->l + 1)%b;
if(ans>=b)ans-=b;
}
printf("%lld\n",ans);
}
void debug()
{
for(auto x:s)
printf("%d %d %d\n",x.l,x.r,x.val);
puts("");
}
}o;
ll n,m,seed,vmax,a[N];
ll rnd()
{
ll ret = seed;
seed = (seed * 7ll + 13)%1000000007;
return ret;
}
int main()
{
scanf("%lld%lld%lld%lld",&n,&m,&seed,&vmax);
for(int i=1;i<=n;i++)
{
a[i] = (rnd()%vmax) + 1;
o.s.insert({i,i,a[i]});
}
// o.debug();
for(int i=1;i<=m;i++)
{
int op = (rnd()%4) + 1;
int l = (rnd()%n) + 1;
int r = (rnd()%n) + 1;
ll x,y;
if (l > r)swap(l, r);
if (op == 3)x = (rnd()%(r - l + 1)) + 1;
else x = (rnd()%vmax) + 1;
if (op == 4)y = (rnd()%vmax) + 1;
if(op==1)o.add(l,r,x);
else if(op==2)o.color(l,r,x);
else if(op==3)o.kth(l,r,x);
else o.sum(l,r,x,y);
// o.debug();
// printf("%d %d %d %d %d\n",op,l,r,x,y);
}
return 0;
}
/******************** ********************/

Codeforces Round #449 (Div. 1)C - Willem, Chtholly and Seniorious的更多相关文章

  1. Codeforces Round #449 (Div. 2)

    Codeforces Round #449 (Div. 2) https://codeforces.com/contest/897 A #include<bits/stdc++.h> us ...

  2. Codeforces Round #449 (Div. 1) Willem, Chtholly and Seniorious (ODT维护)

    题意 给你一个长为 \(n\) 的序列 \(a_i\) 需要支持四个操作. \(1~l~r~x:\) 把 \(i \in [l, r]\) 的 \(a_i\) 加 \(x\) . \(2~l~r~x: ...

  3. Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】

    B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)

    A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #449 (Div. 2) D. Ithea Plays With Chtholly

    题目链接 交互题. 题意:给你三个数n,m,k.让你完成至多m次互动,每次给你一个q,让你从n个位置选一个位置放这个数,覆盖已经放过的数.让你再m次使得n个位置的数不递减,达到直接退出. 解法:暴力, ...

  6. CF&&CC百套计划1 Codeforces Round #449 B. Ithea Plays With Chtholly

    http://codeforces.com/contest/896/problem/B 题意: 交互题 n张卡片填m个1到c之间的数,1<=n*ceil(c/2)<=m 最后填出一个单调非 ...

  7. Codeforces Round #449 (Div. 2)ABCD

    又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. Codeforces Round #449 (Div. 2) A. Scarborough Fair【多次区间修改字符串】

    A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #449 Div. 2 A B C (暂时)

    A. Scarborough Fair 题意 对给定的长度为\(n\)的字符串进行\(m\)次操作,每次将一段区间内的某一个字符替换成另一个字符. 思路 直接模拟 Code #include < ...

随机推荐

  1. js 内置对象和方法 示例

    JS内置函数不从属于任何对象,在JS语句的任何地方都可以直接使用这些函数.JS中常用的内置函数如下: 1.eval(str)接收一个字符串形式的表达式,并试图求出表达式的值.作为参数的表达式可以采用任 ...

  2. Linux中编写Bash脚本的10个技巧

    Shell 脚本编程 是你在 Linux 下学习或练习编程的最简单的方式.尤其对 系统管理员要处理着自动化任务,且要开发新的简单的实用程序或工具等(这里只是仅举几例)更是必备技能. 本文中,我们将分享 ...

  3. python之路----进程(一)

    一.理论知识1.操作系统发展简介 1.没有操作系统 —— 穿孔卡片 2.批处理系统 —— 串行 ,速度块 联机批处理 读磁带的时候速度快 脱机批处理 读磁带和cpu工作并发 3.多道程序系统 —— 并 ...

  4. Python3 解决 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte

    Python3 解决 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte 一.问题 request.Reque ...

  5. 20145313张雪纯exp7

    问题 (1)通常在什么场景下容易受到DNS spoof攻击 处于局域网中的时候,例如连接了学校/公司/餐厅wifi. (2)在日常生活工作中如何防范以上两攻击方法 不要轻易点开未知网址.鼠标在链接处停 ...

  6. Linux内存管理--虚拟地址、逻辑地址、线性地址和物理地址的区别(二)【转】

    本文转载自:http://blog.csdn.net/yusiguyuan/article/details/9668363 这篇文章中介绍了四个名词的概念,下面针对四个地址的转换进行分析 CPU将一个 ...

  7. loj 诗歌

    链接 链接 思路 好久之前的考试题了吧,之前貌似抄的题解 现在理解了怕忘了,就写个题解记录一下吧,题目还是不错的 枚举中间点j \[H_{i}-H_{j}=H_{j}-H_{k}\] \[H_{k}+ ...

  8. 平衡树之伸展树(Splay Tree)题目整理

    目录 前言 练习1 BZOJ 3224 普通平衡树 练习2 BZOJ 3223 文艺平衡树 练习3 BZOJ 1588 [HNOI2002]营业额统计 练习4 BZOJ 1208 [HNOI2004] ...

  9. 【详解】Dubbo的原理以及详细原理、配置

    Dubbo的背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. Dubbo的应用 用于大规模 ...

  10. C#调用系统蜂鸣(需要发出警告时挺好用的 即使没有声卡)

    http://heavenslv.iteye.com/blog/1033870 // 声明 public class BeepUp { /// <param name="iFreque ...