結果
| 問題 |
No.230 Splarraay スプラレェーイ
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2018-03-14 21:59:40 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,868 bytes |
| コンパイル時間 | 638 ms |
| コンパイル使用メモリ | 100,312 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-13 00:05:48 |
| 合計ジャッジ時間 | 6,064 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 12 |
ソースコード
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 push(int i){
if(laz[i]==nil) return;
val[(i*D)..((i+1)*D)]=laz[i];
laz[i]=nil;
}
int sum(int l, int r){
int ret=0;
if(r-l<=D*2){
ret=eachSum(l, r);
}else{
auto bl=l/D, br=r/D;
ret+=eachSum(l, (bl+1)*D);
ret+=buc[(bl+1)..br].sum;
ret+=eachSum(br*D, r);
}
return ret;
}
int eachSum(int l, int r){
push(l/D); push(r/D);
return val[l..r].sum;
}
void update(int l, int r, int x){
if(r-l<=D*2){
eachUpdate(l, r, x);
}else{
auto bl=l/D, br=r/D;
eachUpdate(l, (bl+1)*D, x);
buc[(bl+1)..br]=x*D;
laz[(bl+1)..br]=x;
eachUpdate(br*D, r, x);
}
}
void eachUpdate(int l, int r, int x){
push(l/D); push(r/D);
foreach(i; l..r){
buc[i/D]-=val[i];
val[i]=x;
buc[i/D]+=val[i];
}
}
}
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));
}
}
ikd