跳到正文

剪贴板

剪贴板 frimehgz

原文
剪贴板信息

剪贴板信息

收录
更新

P6688代码(C++)—— 防Ctrl-C-V版

C++
#include<cstdio>
#include<cctype>
#include<cstring>
const int N=1e6+10,M=1e6,base=1e6+3,p1=1e9+7,p2=1e9+9;
//encore dalao 的IO(注gai意cuo有le改keng动ren(雾))
namespace In{
char buf[1<<21],*p1=buf,*p2=buf;
inline int getc(){
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline void readi(T &ret) {
    int f = 0;char ch = getc();
    ret=0;
    while (!isdigit (ch)) {
        if (ch == '-') f = 1;
        ch = getc();
    }
    while (isdigit (ch)) {
        ret = ret * 10 + ch - 48;
        ch = getc();
    }
    if(f)ret=-ret;
}
}
namespace Out{
char buffer[1 << 21];
int p1 = - 1;
const int p2 = (1 << 21) - 1;
inline void flush() {
  fwrite(buffer, 1, p1 + 1, stdout),
  p1 = -1;
}
inline void putc(const char &x) {
  if (p1 == p2) flush();
  buffer[++p1] = x;
}
inline void puts(char *p)
{
    while(*p)putc(*p);
    putc('\n');
}
template<typename T>
void print(T x) {
  static char buf[35];
  static int len = -1;
  if (x >= 0) {
    do {
      buf[++len] = x % 10 + 48, x /= 10;
    } while (x>0);
  } else {
    putc('-');
    do {
      buf[++len] = -(x % 10) + 48, x /= 10;
    } while (x);
  }
  while (len >= 0) {
    putc(buf[len]), --len;
  }
}
}
//哈希取模
inline int addmod1(const int &x,const int &y)
{static int re;re=x+y;re-=(((re<p1)-1)&p1);return re;}//(((re<p1)-1)&p1) 相当于 (re<p1?0:p1)
inline int addmod2(const int &x,const int &y)
{static int re;re=x+y;re-=(((re<p2)-1)&p2);return re;}
//哈希值
struct hashnum
{
    int data1,data2;
    inline hashnum(int x=0){data1=x;data2=x;}
    inline hashnum(int x,int y){data1=x;data2=y;}
    inline hashnum operator + (const hashnum &a) {return hashnum(addmod1(data1,a.data1),addmod2(data2,a.data2));}
    inline hashnum operator * (const hashnum &a) {return hashnum((long long)data1*a.data1%p1,(long long)data2*a.data2%p2);}
    inline bool operator == (const hashnum &a) const {return data1==a.data1&&data2==a.data2;}
};

int n,q;
hashnum pow[N];
//segment tree - 线段树
namespace sgtree
{
int ql,qr,p,x;
int mn[N<<2];
hashnum sum[N<<2];
inline int min(const int &a,const int &b){return (((a>b)-1)&a)|(((b>a)-1)&b);}//同上
inline void pushup(int rt){sum[rt]=sum[rt<<1]+sum[rt<<1|1];mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);}
void build(int rt,int l,int r)
{
    if(l==r){In::readi(mn[rt]);sum[rt]=pow[mn[rt]];return;}
    int mid=(l+r)>>1;
    build(rt<<1,l,mid);
    build(rt<<1|1,mid+1,r);
    pushup(rt);
}
void update(int rt,int l,int r)
{
    if(l==r){sum[rt]=pow[mn[rt]=x];return;}
    int mid=(l+r)>>1;
    if(p<=mid)update(rt<<1,l,mid);
    else update(rt<<1|1,mid+1,r);
}
void query(int rt,int l,int r,hashnum &x,int &y)
{
    if(ql<=l&&r<=qr){x=x+sum[rt];y=min(y,mn[rt]);return;}
    int mid=(l+r)>>1;
    if(ql<=mid)query(rt<<1,l,mid,x,y);
    if(qr>mid)query(rt<<1|1,mid+1,r,x,y);
}
}
inline void getpow()
{
	const int M=100;
    register int i;pow[0]=hashnum(1);
    hashnum bas=hashnum(base);
    for(i=1;i<=M;i++)
    pow[i]=pow[i-1]*bas;
}
template<typename T>
inline void swap(T &a, T &b){T t=a;a=b;b=t;}
char strans[2][10]={"NO","YES"};
int main()
{
    getpow();
    int op;
    int mn1,mn2;
    hashnum s1,s2;
    In::readi(n);In::readi(q);
    sgtree::build(1,1,n);
    while(q--)
    {
        In::readi(op);
        if(!op)
        {
            In::readi(sgtree::p);In::readi(sgtree::x);
            sgtree::update(1,1,n);
        }
        else
        {
            mn1=mn2=M+10;s1.data1=s1.data2=s2.data1=s2.data2=0;
            In::readi(sgtree::ql);In::readi(sgtree::qr);
            sgtree::query(1,1,n,s1,mn1);
            In::readi(sgtree::ql);In::readi(sgtree::qr);
            sgtree::query(1,1,n,s2,mn2);
            if(mn1>mn2)swap(mn1,mn2),swap(s1,s2);
            Out::puts(strans[s1*pow[mn2-mn1]==s2]);
        }
    }
    return 0;
}