結果

問題 No.255 Splarrraaay スプラーレェーーイ
ユーザー LayCurseLayCurse
提出日時 2015-07-24 12:11:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 612 ms / 10,000 ms
コード長 7,778 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 166,448 KB
実行使用メモリ 77,824 KB
最終ジャッジ日時 2024-10-12 19:23:33
合計ジャッジ時間 8,121 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 612 ms
77,824 KB
testcase_01 AC 596 ms
77,824 KB
testcase_02 AC 577 ms
77,696 KB
testcase_03 AC 475 ms
77,824 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 552 ms
77,696 KB
testcase_06 AC 566 ms
77,824 KB
testcase_07 AC 533 ms
77,696 KB
testcase_08 AC 544 ms
77,696 KB
testcase_09 AC 555 ms
77,696 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');}

struct Segtree{
  int N, logN;
  ll (*data)[5];
  int (*addval)[5], (*fixval)[5];
  char (*fixed)[5];
  ll *coef, *coefsum;

  void* malloc(int maxN, void *mem){
    int i;
    for(i=1;i<maxN;i*=2);
    data=(ll(*)[5])mem;
    fixval=(int(*)[5])(data+2*i);
    addval=fixval+i;
    fixed=(char(*)[5])(addval+i);
    coef=(ll*)(fixed+i);
    coefsum=coef+i;
    return coefsum+i+1;
  }
  
  void setN(int n, int zerofill=1){
    int i, k;
    for(i=1,logN=0;i<n;i*=2,logN++);
    N=i;
    if(zerofill){
      rep(i,N) rep(k,5) data[N+i][k]=0;
      rep(i,N)coef[i]=0;
    }
  }
  
  void build(void){
    int i, j;
    for(i=N-1;i;i--) rep(j,5) data[i][j]=data[2*i][j]+data[2*i+1][j];
    REP(i,1,N) rep(j,5) fixed[i][j] = 0;
    REP(i,1,N) rep(j,5) addval[i][j] = 0;
    coefsum[0]=0;
    rep(i,N)coefsum[i+1]=coefsum[i]+coef[i];
  }
  
  inline void push_one(int a, int st, int ed){
    int j;
    rep(j,5){
      if(fixed[a][j]){
        if(ed-st>2){
          fixed[a*2][j] = fixed[a*2+1][j] = 1;
          fixval[a*2][j] = fixval[a*2+1][j] = fixval[a][j];
        }
        data[a*2][j] = (coefsum[(st+ed)/2]-coefsum[st])*fixval[a][j];
        data[a*2+1][j] = (coefsum[ed]-coefsum[(st+ed)/2])*fixval[a][j];
        fixed[a][j] = 0;
        addval[a][j] = 0;
        continue;
      }
      
      if(addval[a][j]!=0){
        if(ed-st>2){
          if(fixed[a*2][j]) fixval[a*2][j] += addval[a][j];
          else              addval[a*2][j] += addval[a][j];
          if(fixed[a*2+1][j]) fixval[a*2+1][j] += addval[a][j];
          else                addval[a*2+1][j] += addval[a][j];
        }
        data[a*2][j]+=(coefsum[(st+ed)/2]-coefsum[st])*addval[a][j];
        data[a*2+1][j]+=(coefsum[ed]-coefsum[(st+ed)/2])*addval[a][j];
        addval[a][j]=0;
        continue;
      }
    }
  }
  
  inline void push(int a){
    int i,s=0,e=N;
    for(i=logN;i;i--){
      push_one(a>>i,s,e);
      if((a>>(i-1))&1)
        s=(s+e)/2;
      else
        e=(s+e)/2;
    }
  }
  
  inline void build(int a){
    int s=a-N,e=a-N+1,j;
    while(a>1){
      if(a%2)s-=e-s;
      else e+=e-s;a/=2;
      rep(j,5){
        if(fixed[a][j]){
          data[a][j] = fixval[a][j] * (coefsum[e]-coefsum[s]);
        } else {
          data[a][j]=data[a*2][j]+data[a*2+1][j];
          if(addval[a][j]!=0)data[a][j]+=addval[a][j]*(coefsum[e]-coefsum[s]);
        }
      }
    }
  }

  inline void doit(int a, int b, int ind){
    int c,d,s=a,t=b,sz=1,j;
    if(a>=b)return;
    c=(a+=N);
    d=(b+=N);
    push(a);
    push(b-1);

    if(a%2){
      rep(j,5){
        if(j==ind) data[a][j]+=(coefsum[s+sz]-coefsum[s]);
        else       data[a][j]=0;
      }
      a++;
      s+=sz;
    }
    if(b%2){
      b--;
      rep(j,5){
        if(j==ind) data[b][j] += (coefsum[t]-coefsum[t-sz]);
        else       data[b][j] = 0;
      }
      t-=sz;
    }
    
    a/=2;
    b/=2;
    while(a<b){
      sz*=2;
      if(a%2){

        rep(j,5){
          if(j==ind){
            if(fixed[a][j]) fixval[a][j]++; else addval[a][j]++;
            data[a][j]+=coefsum[s+sz]-coefsum[s];
          } else {
            fixed[a][j] = 1;
            fixval[a][j] = 0;
            data[a][j] = 0;
          }
        }
        
        a++;
        s+=sz;
      }
      if(b%2){
        b--;

        rep(j,5){
          if(j==ind){
            if(fixed[b][j]) fixval[b][j]++; else addval[b][j]++;
            data[b][j]+=coefsum[t]-coefsum[t-sz];
          } else {
            fixed[b][j] = 1;
            fixval[b][j] = 0;
            data[b][j] = 0;
          }
        }
        t-=sz;
      }
      a/=2;
      b/=2;
    }
    build(c);
    build(d-1);
  }
  
  inline void getSum(int a, int b, ll res[]){
    int sz=1,j;
    a+=N;
    b+=N;
    push(a);
    push(b-1);
    rep(j,5)res[j] = 0;
    while(a<b){
      if(a%2){
        rep(j,5)res[j]+=data[a][j];
        a++;
      }
      if(b%2){
        b--;
        rep(j,5)res[j]+=data[b][j];
      }
      a/=2;b/=2;
    }
  }
};

template<class T> int coordinateCompress(int n, T arr[], int res[], void *mem){int i,k=0;pair<T,int>*r=(pair<T,int>*)mem;rep(i,n)r[i].first=arr[i],r[i].second=i;sort(r,r+n);if(res!=NULL){rep(i,n){if(i&&r[i].first!=r[i-1].first)k++;res[r[i].second]=k;}}else{rep(i,n){if(i&&r[i].first!=r[i-1].first)k++;arr[r[i].second]=k;}}return k+1;}
template<class T> int coordinateCompress(int n1, T arr1[], int n2, T arr2[], int res1[], int res2[], void *mem){int i,k=0;pair<T,int>*r =(pair<T,int>*)mem;rep(i,n1)r[i].first=arr1[i],r[i].second=i;rep(i,n2)r[n1+i].first=arr2[i],r[n1+i].second=n1+i;sort(r,r+n1+n2);rep(i,n1+n2){if(i&&r[i].first!=r[i-1].first) k++;if(r[i].second<n1){if(res1!=NULL)res1[r[i].second]=k;else arr1[r[i].second]=k;}else{if(res2!=NULL)res2[r[i].second-n1]=k;else arr2[r[i].second-n1]=k;}}return k+1;}


char memarr[147000000]; void *mem = memarr;
#define MD 1000000000000000009LL

ll N;
int Q, X[150010];
ll L[150010], R[150010];

int LL[150010], RR[150010];

ll csum[300010];

int main(){
  int i, j, k, nn;
  ll res[5], tmp[5];
  Segtree t;

  reader(&N,&Q);
  rep(i,Q) reader(X+i,L+i,R+i), R[i]++;

  rep(i,5) res[i] = 0;
  if(Q==0){ writerArr(res,5); return 0; }

  nn = coordinateCompress(Q, L, Q, R, LL, RR, mem);

  mem = t.malloc(nn-1, mem);
  t.setN(nn-1);

  rep(i,Q) csum[LL[i]] = L[i];
  rep(i,Q) csum[RR[i]] = R[i];
  rep(j,nn-1) t.coef[j] = csum[j+1]-csum[j];

  t.build();

  rep(i,Q){
    if(X[i]==0){
      t.getSum(LL[i],RR[i],tmp);
      rep(j,5) if(tmp[j]>tmp[(j+1)%5]&&tmp[j]>tmp[(j+2)%5]&&tmp[j]>tmp[(j+3)%5]&&tmp[j]>tmp[(j+4)%5]) res[j] = (res[j]+tmp[j]) % MD;
    } else {
      t.doit(LL[i], RR[i], X[i]-1);
    }
  }

  t.getSum(0,nn-1,tmp);
  rep(i,5) res[i] = (res[i] + tmp[i]) % MD;

  writerArr(res,5);

  return 0;
}
0