結果

問題 No.230 Splarraay スプラレェーイ
ユーザー hashiryohashiryo
提出日時 2018-10-10 22:38:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 220 ms / 5,000 ms
コード長 4,295 bytes
コンパイル時間 1,673 ms
コンパイル使用メモリ 92,464 KB
実行使用メモリ 11,344 KB
最終ジャッジ日時 2023-08-02 19:25:46
合計ジャッジ時間 4,898 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 11 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 98 ms
6,928 KB
testcase_10 AC 92 ms
4,376 KB
testcase_11 AC 55 ms
5,080 KB
testcase_12 AC 97 ms
7,408 KB
testcase_13 AC 16 ms
4,376 KB
testcase_14 AC 84 ms
11,236 KB
testcase_15 AC 138 ms
11,224 KB
testcase_16 AC 170 ms
11,204 KB
testcase_17 AC 220 ms
11,216 KB
testcase_18 AC 123 ms
11,344 KB
testcase_19 AC 128 ms
11,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ull INF = ULLONG_MAX;
const ll MOD = 1e9+7;

inline int get_min2pow(int n) {
	int res = 1;
	while (res < n)
		res *= 2;
	return res;
}
//遅延評価SegmentTree///////////
//lazyの初期値に注意
template<typename T>
struct delay_segtree {
private:
	int N;
	vector<T> node, lazy;
  //-------書くとこ---------------------
	//例外値 ex)INF,0
	T default_value = 0;
	T default_lazy = -1;
	static inline T merge(const T& u, const T& v) {
		return u + v;
	}
	static inline void lazy_transmit(T& u, const T& v) {
		u = v;
	}
  static inline void node_transmit(T& u,const T& v,int l,int r){
    u = (r-l)*v;
  }
  //------------------------------------
	// k 番目のノードについて遅延評価を行う
	void eval(int k, int l, int r) {
		// 遅延配列が空でない場合、自ノード及び子ノードへの
		// 値の伝播が起こる
		if (lazy[k] != default_lazy) {
			node_transmit(node[k], lazy[k],l,r);
			// 最下段かどうかのチェックをしよう
			if (r - l > 1) {
				lazy_transmit(lazy[2 * k + 1], lazy[k]);
				lazy_transmit(lazy[2 * k + 2], lazy[k]);
			}
			// 伝播が終わったので、自ノードの遅延配列を空にする
			lazy[k] = default_lazy;
		}
	}
public:
	delay_segtree(int n) {
    for(N=1;N<n;N*=2);
		node.resize(2 * N, default_value);
		lazy.resize(2 * N, default_lazy);
	}
	delay_segtree(vector<int> v) {
		int sz = v.size();
    for(N=1;N<sz;N*=2);
		node.resize(2 * N, default_value);
		lazy.resize(2 * N, default_lazy);
		for (int i = 0; i < sz; i++)
			node[i + N - 1] = v[i];
		for (int i = N - 2; i >= 0; i--)
			node[i] = merge(node[2 * i + 1], node[2 * i + 2]);
	}
	void update(int a, int b, T x, int k = 0, int l = 0, int r = -1) {
		if (r < 0)
			r = N;
		// k 番目のノードに対して遅延評価を行う
		eval(k, l, r);
		// 範囲外なら何もしない
		if (b <= l || r <= a)
			return;
		// 完全に被覆しているならば、遅延配列に値を入れた後に評価
		if (a <= l && r <= b) {
			lazy_transmit(lazy[k], x);
			eval(k, l, r);
		}
		// そうでないならば、子ノードの値を再帰的に計算して、
		// 計算済みの値をもらってくる
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = merge(node[2 * k + 1], node[2 * k + 2]);
		}
	}
	// update k th element
	void update(int k, T val) {
		k += N - 1; // leaf
		node[k] = val;
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = merge(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	// [a, b)
	T query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)
			r = N;
		eval(k, l, r);
		if (r <= a or b <= l)
			return default_value;
		if (a <= l and r <= b)
			return node[k];
		int m = (l + r) / 2;
		T vl = query(a, b, k * 2 + 1, l, m);
		T vr = query(a, b, k * 2 + 2, m, r);
		return merge(vl, vr);
	}

	T operator[](const int &k) {
		//遅延評価をまずしておく
		query(k, k + 1);
		return node[k + N - 1];
	}
};



int main(){
  int N;cin>>N;
  delay_segtree<ll> A(N),B(N);
  ll scoreA=0,scoreB=0;
  int Q;cin>>Q;
  repeat(q,Q){
    int x,l,r;cin>>x>>l>>r;
    if(x==0){
      ll a=A.query(l,r+1),b=B.query(l,r+1);
      if(a>b){
        scoreA+=a;
      }else if(a<b){
        scoreB+=b;
      }
    }else if(x==1){
      A.update(l,r+1,1);
      B.update(l,r+1,0);
    }else{
      A.update(l,r+1,0);
      B.update(l,r+1,1);
    }
  }
  scoreA += A.query(0,N);
  scoreB += B.query(0,N);
  cout << scoreA << " " << scoreB << endl;
  return 0;
}
0