結果

問題 No.230 Splarraay スプラレェーイ
ユーザー ikdikd
提出日時 2018-05-30 05:57:31
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 470 ms / 5,000 ms
コード長 1,799 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 85,156 KB
実行使用メモリ 6,140 KB
最終ジャッジ日時 2023-09-03 20:15:39
合計ジャッジ時間 4,560 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 11 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 158 ms
4,380 KB
testcase_10 AC 80 ms
4,376 KB
testcase_11 AC 86 ms
4,380 KB
testcase_12 AC 158 ms
4,376 KB
testcase_13 AC 18 ms
4,380 KB
testcase_14 AC 329 ms
5,644 KB
testcase_15 AC 470 ms
4,380 KB
testcase_16 AC 443 ms
4,376 KB
testcase_17 AC 413 ms
4,376 KB
testcase_18 AC 390 ms
6,140 KB
testcase_19 AC 257 ms
5,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  int q; rd(q);
  long a=0, b=0;
  auto treeA=new SquareRootDecomposition(n),
       treeB=new SquareRootDecomposition(n);
  while(q--){
    int t, l, r; rd(t, l, r);
    if(t==0){
      auto cntA=treeA.sum(l, r+1), cntB=treeB.sum(l, r+1);
      if(cntA==cntB) continue;
      (cntA>cntB ? a : b)+=max(cntA, cntB);
    }else if(t==1){
      treeA.update(l, r+1, 1);
      treeB.update(l, r+1, 0);
    }else if(t==2){
      treeA.update(l, r+1, 0);
      treeB.update(l, r+1, 1);
    }
  }

  a+=treeA.sum(0, n);
  b+=treeB.sum(0, n);
  writeln(a, " ", b);
}

class SquareRootDecomposition{
  import std.algorithm;
  int D=1, nil=-1;
  int[] val, buc, laz;
  this(int n){
    while(D*D<n) D++;
    val.length=D*D;
    buc.length=laz.length=D;
    fill(laz, nil);
  }

  void update(int ql, int qr, int x){
    foreach(k; 0..D){
      int l=k*D, r=(k+1)*D;
      if(r<=ql || qr<=l){
        // 
      }else if(ql<=l && r<=qr){
        buc[k]=x*D;
        laz[k]=x;
      }else{
        push(k);
        foreach(i; max(l, ql)..min(r, qr)){
          buc[k]-=val[i];
          val[i]=x;
          buc[k]+=x;
        }        
      }
    }
  }

  int sum(int ql, int qr){
    int ret=0;
    foreach(k; 0..D){
      int l=k*D, r=(k+1)*D;
      if(r<=ql || qr<=l){
        // 
      }else if(ql<=l && r<=qr){
        ret+=buc[k];
      }else{
        push(k);
        foreach(i; max(l, ql)..min(r, qr)) ret+=val[i];
      }
    }
    return ret;
  }

  void push(int k){
    if(laz[k]<0) return;
    val[(k*D)..((k+1)*D)]=laz[k];
    laz[k]=-1;
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}
0