結果
| 問題 | No.230 Splarraay スプラレェーイ | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-11-10 13:06:05 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 138 ms / 5,000 ms | 
| コード長 | 2,977 bytes | 
| コンパイル時間 | 951 ms | 
| コンパイル使用メモリ | 98,036 KB | 
| 実行使用メモリ | 7,296 KB | 
| 最終ジャッジ日時 | 2024-09-13 14:19:37 | 
| 合計ジャッジ時間 | 2,782 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
typedef long long ll;
using namespace std;
int inputValue(){
    int a;
    cin >> a;
    return a;
}
template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << fixed << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
int sz;
class segtree_lazy{
private:
    int n;
    // static int sz;
    
public:
    vector<int> isfull, to; // isfull : 1 / 0 / -1 : full / empty / mixed, to: count
    
    segtree_lazy(int a){
        n = 1;
        while(n < a){
            n *= 2;
        }
        sz = n;
        isfull.resize(2 * n - 1, 0); // 0-indexed
        to.resize(2 * n - 1, 0); // 0-indexed
    }
    
    int sum(int x, int y, int l = 0, int r = sz, int k = 0){ // [x, y)
        if(r <= x || y <= l) return 0;
        if(x <= l && r <= y) return to[k];
        x = max(x, l);
        y = min(y, r);
        if(isfull[k] >= 0) return isfull[k] ? (y - x) : 0;
        return sum(x, y, l, (l + r) / 2, k * 2 + 1) + sum(x, y, (l + r) / 2, r, k * 2 + 2);
    }
    
    void update(int x, int y, int v, int l = 0, int r = sz, int k = 0) { // [x, y)
        if(l >= r) return;
        if(x <= l && r <= y) {
            isfull[k] = v;
            to[k] = isfull[k] ? (r - l) : 0;
        }
        else if(l < y && x < r) {
            if(isfull[k] >= 0) {
                isfull[k * 2 + 1] = isfull[k * 2 + 2] = isfull[k];
                to[k * 2 + 1] = to[k * 2 + 2] = isfull[k] ? (r - l) / 2 : 0;
                isfull[k] = -1;
            }
            update(x, y, v, l, (l + r) / 2, k * 2 + 1);
            update(x, y, v, (l + r) / 2, r, k * 2 + 2);
            to[k] = to[k * 2 + 1] + to[k * 2 + 2];
        }
    }
    
    
};
// end of template
int main() {
    cin.tie(0);
    // source code
    int N = inputValue();
    int Q = inputValue();
    
    segtree_lazy A(N), B(N);
    
    ll ptA = 0;
    ll ptB = 0;
    
    rep(i, Q){
        int x = inputValue();
        int l = inputValue();
        int r = inputValue() + 1;
        if (x == 1) {
            A.update(l, r, 1);
            B.update(l, r, 0);
        }
        else if (x == 2){
            A.update(l, r, 0);
            B.update(l, r, 1);
        }
        else{
            int tptA = A.sum(l, r);
            int tptB = B.sum(l, r);
            if (tptA > tptB) {
                ptA += tptA;
            }
            else if (tptA < tptB){
                ptB += tptB;
            }
        }
    }
    ptA += A.sum(0, N);
    ptB += B.sum(0, N);
    
    cout << ptA << " " << ptB << endl;
    
    return 0;
}
            
            
            
        