求助,为什么全 RE
查看原帖
求助,为什么全 RE
407417
HerikoDeltana楼主2021/6/26 15:44
RT.\texttt{RT.}
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#define lc(x) (x<<1)
#define rc(x) (x<<1|1)
#define Heriko return
#define Deltana 0
#define S signed
#define LL long long
#define R register
#define I inline
#define CI const int
#define mst(a, b) memset(a, b, sizeof(a))
#define ON std::ios::sync_with_stdio(false)
using namespace std;
template<typename T>
I void fr(T &x)
{
    short f=1;
    char c=getchar();
    x=0;
    while(c<'0' or c>'9')
    {
        if(c=='-') f=-1;
        c=getchar();
    }
    while (c>='0' and c<='9') 
    {
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    x*=f;
}
template<typename T>
I void fw(T x,bool k)
{
    if(x<0) putchar('-'),x=-x;
    static short stak[55];
    short top=0;
    do
    {
        stak[top++]=x%10;
        x/=10;
    }
    while(x);
    while(top) putchar(stak[--top]+'0');
    if(k) putchar('\n');
    else putchar(' ');
}

CI MXX=1e5+5;

I int cnt(int x){
    int res=0;
    while(x) res+=(x&1),x>>=1;
    return res;
}

I int nex(int x){
    --x;int res=1;
    while(x) res<<=1,--x;
    return res;
}

struct SegTree
{
    int l,r,val,tag;
}
t[MXX<<2];

void Build(int x,int l,int r)
{
    t[x].l=l,t[x].r=r;
    t[x].val=1,t[x].tag=0;
    if(l==r) Heriko;
    int mid=(l+r)>>1;
    Build(lc(x),l,mid);
    Build(rc(x),mid+1,r);
}

I void Pushup(int x) {t[x].val=t[lc(x)].val|t[rc(x)].val;}

I void Pushdown(int x)
{
    t[lc(x)].val=t[lc(x)].tag=t[x].tag;
    t[rc(x)].val=t[rc(x)].tag=t[x].tag;
    t[x].tag=0;
}

void Modify(int x,int l,int r,int v)
{
    if(l<=t[x].l and t[x].r<=r) {t[x].val=t[x].tag=v;Heriko;}
    if(t[x].tag) Pushdown(x);
    int mid=(t[x].l+t[x].r)>>1;
    if(l<=mid) Modify(lc(x),l,r,v);
    if(r>mid) Modify(rc(x),l,r,v);
    Pushup(x);
}

int Query(int x,int l,int r)
{
    if(l<=t[x].l and t[x].r<=r) Heriko t[x].val;
    if(t[x].tag) Pushdown(x);
    int mid=(t[x].l+t[x].r)>>1,res=0;
    if(l<=mid) res=res|Query(lc(x),l,r);
    if(r>mid) res=res|Query(rc(x),l,r);
    Heriko res;
}

int N,T,M;

char opt[5],a,b,c;

S main()
{
    // freopen("RNMTQ.in","r",stdin);
    // freopen("RNMTQ.out","w",stdout);
    fr(N),fr(T),fr(M);
    // cout<<N<<' '<<T<<' '<<M<<endl;
    //fw(N,0),fw(T,0),fw(M,0);
    Build(1,1,N);
    while(M--)
    {
        scanf("%s",opt);
        if(opt[0]=='C')
        {
            fr(a),fr(b),fr(c);
            if(a>b) swap(a,b);
            Modify(1,a,b,nex(c));
        }
        else
        {
            fr(a),fr(b);
            if(a>b) swap(a,b);
            printf("%d\n",cnt(Query(1,a,b)));
            // fw(cnt(Query(1,a,b)),1);
        }
    }
    Heriko Deltana;
}
2021/6/26 15:44
加载中...