結果

問題 No.230 Splarraay スプラレェーイ
ユーザー LayCurseLayCurse
提出日時 2015-06-21 02:17:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 6,895 bytes
コンパイル時間 1,313 ms
コンパイル使用メモリ 163,012 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-07-07 15:25:03
合計ジャッジ時間 2,658 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 29 ms
6,940 KB
testcase_10 AC 19 ms
6,940 KB
testcase_11 AC 17 ms
6,944 KB
testcase_12 AC 29 ms
6,944 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 24 ms
6,940 KB
testcase_15 AC 41 ms
6,940 KB
testcase_16 AC 53 ms
7,040 KB
testcase_17 AC 62 ms
7,424 KB
testcase_18 AC 35 ms
7,424 KB
testcase_19 AC 42 ms
7,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void reader(double*)’:
main.cpp:15:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 | void reader(double *x){scanf("%lf",x);}
      |                        ~~~~~^~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[17000000]; void *mem = memarr;
#define MD 1000000007

template<class T, class S>
struct mypair{
  T first;
  S second;

  mypair(void){};
  mypair(T a, S b){first=a;second=b;}

  mypair<T,S> &operator+=(mypair<T,S> a){
    first += a.first;
    second += a.second;
    return *this;
  }
  mypair<T,S> &operator-=(mypair<T,S> a){
    first -= a.first;
    second -= a.second;
    return *this;
  }

  mypair<T,S> operator+(mypair<T,S> a){ return mypair<T,S>(*this)+=a; }
  mypair<T,S> operator-(mypair<T,S> a){ return mypair<T,S>(*this)-=a; }

  mypair<T,S> &operator*=(int a){
    first *= a;
    second *= a;
    return *this;
  }
  mypair<T,S> operator*(int a){ return mypair<T,S>(*this)*=a; }
  
  mypair<T,S> &operator=(int a){
    first = a;
    second = a;
    return *this;
  }

  bool operator==(int a){
    return first==a && second==a;
  }
  bool operator!=(int a){
    return first!=a || second!=a;
  }
};
template<class T, class S> mypair<T,S> operator*(int a, mypair<T,S> b){b.first*=a;b.second*=a;return b;}

template<class T>
struct lazySegtreeSum{
  int N, logN;
  T *data;

  T *fixval; char *fixed;
  T *addval;

  void malloc(int maxN){
    int i;
    for(i=1;i<maxN;i*=2);
    
    data = (T*)std::malloc(sizeof(T)*2*i);
    fixval = (T*)std::malloc(sizeof(T)*i);
    addval = (T*)std::malloc(sizeof(T)*i);
    fixed = (char*)std::malloc(sizeof(char)*i);
  }

  T& operator[](int i){
    return data[N+i];
  }

  void setN(int n, int zerofill = 1){
    int i;
    for(i=1,logN=0;i<n;i*=2,logN++);
    N = i;
    if(zerofill) rep(i,N) data[N+i] = 0;
  }

  void build(void){
    int i;
    for(i=N-1;i;i--) data[i] = data[2*i]+data[2*i+1];
    REP(i,1,N) fixed[i] = 0;
    REP(i,1,N) addval[i] = 0;
  }

  inline void push_one(int a, int sz){
    if(fixed[a]){
      if(sz > 1){
        fixed[a*2] = fixed[a*2+1] = 1;
        fixval[a*2] = fixval[a*2+1] = fixval[a];
        data[a*2] = data[a*2+1] = sz * fixval[a];
      } else {
        data[a*2] = data[a*2+1] = fixval[a];
      }
      fixed[a] = 0;
      addval[a] = 0;
      return;
    }
    if(addval[a] != 0){
      if(sz > 1){
        if(fixed[a*2]) fixval[a*2] += addval[a];
        else           addval[a*2] += addval[a];
        if(fixed[a*2+1]) fixval[a*2+1] += addval[a];
        else             addval[a*2+1] += addval[a];
        data[a*2] += sz * addval[a];
        data[a*2+1] += sz * addval[a];
      } else {
        data[a*2] += addval[a];
        data[a*2+1] += addval[a];
      }
      addval[a] = 0;
      return;
    }
  }

  inline void push(int a){
    int i, aa;
    for(i=logN;i;i--){
      aa = a>>i;
      push_one(aa, 1<<(i-1));
    }
  }

  inline void build(int a){
    int sz = 1;
    while(a > 1){
      a /= 2;
      sz *= 2;
      if(fixed[a]){
        data[a] = fixval[a] * sz;
      } else {
        data[a] = data[a*2] + data[a*2+1];
        if(addval[a] != 0) data[a] += addval[a] * sz;
      }
    }
  }

  inline void change(int a, int b, T val){
    int sz = 1, aa, bb;
    if(a >= b) return;

    aa = (a += N);
    bb = (b += N);
    push(a); push(b-1);

    if(a%2) data[a++] = val;
    if(b%2) data[--b] = val;
    a /= 2;
    b /= 2;

    while(a < b){
      sz *= 2;
      if(a%2) fixed[a]=1, fixval[a]=val, data[a++] = sz*val;
      if(b%2) fixed[--b]=1, fixval[b]=val, data[b] = sz*val;
      a /= 2;
      b /= 2;
    }

    build(aa);
    build(bb-1);
  }

  inline void add(int a, int b, T val){
    int sz = 1, aa, bb;
    if(a >= b) return;

    aa = (a += N);
    bb = (b += N);
    push(a); push(b-1);

    if(a%2) data[a++] += val;
    if(b%2) data[--b] += val;
    a /= 2;
    b /= 2;

    while(a < b){
      sz *= 2;
      if(a%2){
        if(fixed[a]) fixval[a] += val; else addval[a] += val;
        data[a++] += sz*val;
      }
      if(b%2){
        b--;
        if(fixed[b]) fixval[b] += val; else addval[b] += val;
        data[b] += sz*val;
      }
      a /= 2;
      b /= 2;
    }

    build(aa);
    build(bb-1);
  }

  inline T getSum(int a, int b){
    T res;
    int sz = 1;
    
    a += N;
    b += N;
    push(a); push(b-1);

    res = 0;
    while(a < b){
      if(a%2) res += data[a++];
      if(b%2) res += data[--b];
      a /= 2;
      b /= 2;
    }
    return res;
  }
};


int N, Q;
int X, L, R;


int main(){
  int i, j, k, v1, v2;
  ll s1=0, s2=0;
  mypair<int,int> a;
  lazySegtreeSum<mypair<int,int> > t;

  reader(&N,&Q);

  t.malloc(N);
  t.setN(N);
  t.build();

  while(Q--){
    reader(&X,&L,&R);
    R++;
    if(X==0){
      a = t.getSum(L, R);
      if(a.first > a.second) s1 += a.first;
      if(a.first < a.second) s2 += a.second;
    } else if(X==1){
      t.change(L, R, mypair<int,int>(1,0));
    } else if(X==2){
      t.change(L, R, mypair<int,int>(0,1));
    }
  }

  a = t.getSum(0, N);
  s1 += a.first;
  s2 += a.second;

  writerLn(s1,s2);

  return 0;
}
0