没有联通门 : Codeforces G. Periodic RMQ Problem

/*

    Codeforces G. Periodic RMQ Problem

    MMP
什么动态开点线段树啊 。。。
YY了个非常可行的做法
码完后交一下发现RE了几个点。。 就思考哪里有问题 突然之间, 老泪纵横。。 MMP 我写了这是个什么玩意啊 仔细想想我TM不就是写了个全空间的主席树吗。。。。脑子有病啊。。
静言思之, 躬自悼矣。。反是不思,亦已焉哉 不写啦!
*/
#include <cmath>
#include <cstdio> #define Max 100008
#define INF 1e8 void read (int &now)
{
now = ;
register char word = getchar ();
bool temp = false;
while (word < '' || word > '')
{
if (word == '-')
temp = true;
word = getchar ();
}
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
if (temp)
now = -now;
} inline int min (int a, int b)
{
return a < b ? a : b;
} inline int max (int a, int b)
{
return a > b ? a : b;
} int N, K; int number[Max]; struct Segment_Tree_Date
{
Segment_Tree_Date *Left, *Right; int l, r; int Mid;
int key;
int Flandre;
Segment_Tree_Date ()
{
Left = NULL;
Right = NULL;
key = ;
Flandre = ;
}
}; Segment_Tree_Date *Root; int Size; class Segment_Tree_Type
{
public : void Build (Segment_Tree_Date *&now, int l, int r, int k)
{
if (l == r)
{
now->key = number[l - (k - ) * N];
return;
}
now->Mid = l + r >> ;
Build (now->Left, l, now->Mid, k);
Build (now->Right, now->Mid + , r, k);
now->key = min (now->Left->key, now->Right->key);
} void Whole_Updata (Segment_Tree_Date *&now, int l, int r)
{
if (now->l == now->r)
return ;
if (now->Flandre)
{
now->Left->key = now->Flandre;
now->Right->key = now->Flandre; now->Left->Flandre = now->Flandre;
now->Right->Flandre = now->Flandre; now->Flandre = ;
}
Whole_Updata (now->Left, l, now->Mid);
Whole_Updata (now->Right, now->Mid + , r);
now->key = min (now->Left->key, now->Right->key);
} int Query (Segment_Tree_Date *&now, int l, int r)
{
if (l <= now->l && now->r <= r)
return now->key;
if (now->Flandre)
{
now->Left->key = now->Flandre;
now->Right->key = now->Flandre; now->Left->Flandre = now->Flandre;
now->Right->Flandre = now->Flandre; now->Flandre = ;
}
now->key = min (now->Left->key, now->Right->key);
int res = INF;
if (l <= now->Mid)
res = Query (now->Left, l, min (now->Mid, r));
if (r > now->Mid)
res = min (res, Query (now->Right, max (now->Mid + , l), r));
return res;
} void Change_Section_Maxn (Segment_Tree_Date *&now, int l, int r, int to)
{
if (l <= now->l && now->r <= r)
{
now->Flandre = to;
now->key = to;
return ;
}
if (now->Flandre)
{
now->Left->key = now->Flandre;
now->Right->key = now->Flandre; now->Left->Flandre = now->Flandre;
now->Right->Flandre = now->Flandre; now->Flandre = ;
}
if (l <= now->Mid)
Change_Section_Maxn (now->Left, l, min (now->Mid, r), to);
if (r > now->Mid)
Change_Section_Maxn (now->Right, max (now->Mid + , l), r, to);
now->key = min (now->Left->key, now->Right->key);
}
}; Segment_Tree_Type Tree; int M;
bool is_exist[Max]; int main (int argc, char *argv[])
{
read (N);
read (K);
for (int i = ; i <= N; i++)
read (number[i]);
int type, x, y, z;
is_exist[] = true;
int now_1, now_2;
Tree.Build (Root, , N, );
register bool flag;
for (read (M); M--; )
{
flag = false;
read (type);
read (x);
read (y);
if (type == )
{
read (z);
now_1 = ceil (x * 1.0 / N);
now_2 = ceil (y * 1.0 / N);
for (int pos = now_1; pos <= now_2; pos++)
if (!is_exist[pos])
{
Tree.Build (Root, N * (pos - ) + , N * pos, pos);
flag = true;
is_exist[pos] = true;
}
if (flag)
Tree.Whole_Updata (Root, N * (now_1 - ) + , N * now_2);
Tree.Change_Section_Maxn (Root, x, y, z);
}
else
{
now_1 = ceil (x * 1.0 / N);
now_2 = ceil (y * 1.0 / N);
for (int pos = now_1; pos <= now_2; pos++)
if (!is_exist[pos])
{
Tree.Build (Root, N * (pos - ) + , N * pos, pos);
flag = true;
is_exist[pos] = true;
}
if (flag)
Tree.Whole_Updata (Root, N * (now_1 - ) + , N * now_2);
printf ("%d\n", Tree.Query (Root, x, y));
}
}
return ;
}

最新文章

  1. HTC辟谣: HTC Vive2不会在CES 2017上公布
  2. Google调用explorer.exe打开本地文件
  3. SQLServer 维护脚本分享(05)内存(Memory)
  4. [转载]在 JavaScript 中判断“空值”
  5. 2-sat按照最小字典序输出可行解(hdu1814)
  6. adb调试命令详解-2016.02.01
  7. 用wget实现cookie欺骗
  8. HttpServletResponse ServletResponse 返回响应 设置响应头设置响应正文体 重定向 常用方法 如何重定向 响应编码 响应乱码
  9. Python开发【socket篇】解决粘包
  10. solr参数之facet
  11. Druid简单使用
  12. 【转】void及void指针的深刻解析
  13. 黑马程序员_java基础笔记(14)...交通灯管理系统_编码思路及代码
  14. 【SqlServer】在SqlServer中把数据导入导出为Excel文件
  15. jQuery验证插件使用初步
  16. 【Nodejs】使用nimble串行化回调任务
  17. NYOJ----次方求模
  18. python学习笔记011——内置函数__module__、__name__
  19. styling the SVG images
  20. 多线程环境下的UI异步操作

热门文章

  1. C#从零单排上王者系列---数据类型
  2. PG SQL funcation
  3. 今日前端框架Vue学习笔记
  4. vue多页面项目搭建(vue-cli 4.0)
  5. Bootstrap源码
  6. var img = new Image()
  7. 2602978 - [How to] Content Synchronization between SLDs
  8. iOS NSNotification传递带参数的通知
  9. aspx反射调用方法
  10. 【leetcode】496. Next Greater Element I