結果
| 問題 | No.230 Splarraay スプラレェーイ | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-01-15 13:48:28 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 852 ms / 5,000 ms | 
| コード長 | 3,071 bytes | 
| コンパイル時間 | 983 ms | 
| コンパイル使用メモリ | 117,760 KB | 
| 実行使用メモリ | 20,352 KB | 
| 最終ジャッジ日時 | 2024-06-13 02:47:13 | 
| 合計ジャッジ時間 | 6,810 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop;
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }
class SegmentTree {
  enum NUM_COLORS = 2;
  int n;
  int[][] cnt;
  int[] add;
  this(int n_) {
    for (n = 1; n < n_; n <<= 1) {}
    cnt = new int[][](n << 1, NUM_COLORS);
    add = new int[n << 1];
    add[] = -1;
  }
  private int[] query(int u, int l, int r, int a, int b, int val) {
    chmax(a, l);
    chmin(b, r);
    if (a >= b) {
      return new int[NUM_COLORS];
    }
    if (a == l && b == r) {
      if (val != -1) {
        cnt[u][] = 0;
        cnt[u][val] = r - l;
        add[u] = val;
      }
      return cnt[u];
    }
    const uL = u << 1;
    const uR = u << 1 | 1;
    const mid = (l + r) >> 1;
    if (add[u] != -1) {
      cnt[uL][] = 0;
      cnt[uL][add[u]] = mid - l;
      cnt[uR][] = 0;
      cnt[uR][add[u]] = r - mid;
      add[uL] = add[u];
      add[uR] = add[u];
      add[u] = -1;
    }
    const resL = query(uL, l, mid, a, b, val);
    const resR = query(uR, mid, r, a, b, val);
    auto ret = new int[NUM_COLORS];
    foreach (color; 0 .. NUM_COLORS) {
      cnt[u][color] = cnt[uL][color] + cnt[uR][color];
      ret[color] = resL[color] + resR[color];
    }
    return ret;
  }
  int[] query(int a, int b, int val) {
    return query(1, 0, n, a, b + 1, val);
  }
}
int N, Q;
int[] X, L, R;
void main() {
  try {
    for (; ; ) {
      N = readInt();
      Q = readInt();
      X = new int[Q];
      L = new int[Q];
      R = new int[Q];
      foreach (q; 0 .. Q) {
        X[q] = readInt() - 1;
        L[q] = readInt();
        R[q] = readInt();
      }
      
      auto seg = new SegmentTree(N);
      long[2] ans;
      foreach (q; 0 .. Q) {
        const res = seg.query(L[q], R[q], X[q]);
        if (X[q] == -1) {
          if (res[0] > res[1]) {
            ans[0] += res[0];
          } else if (res[0] < res[1]) {
            ans[1] += res[1];
          }
        }
      }
      {
        const res = seg.query(0, N - 1, -1);
        ans[0] += res[0];
        ans[1] += res[1];
      }
      writeln(ans[0], " ", ans[1]);
    }
  } catch (EOFException e) {
  }
}
            
            
            
        