結果
| 問題 |
No.230 Splarraay スプラレェーイ
|
| コンテスト | |
| ユーザー |
moti
|
| 提出日時 | 2015-07-12 23:18:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,802 bytes |
| コンパイル時間 | 755 ms |
| コンパイル使用メモリ | 73,340 KB |
| 実行使用メモリ | 68,864 KB |
| 最終ジャッジ日時 | 2024-07-08 06:11:25 |
| 合計ジャッジ時間 | 3,084 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 WA * 14 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
enum class color { mine, yours, invalid };
template<int Max>
struct lazy_segtree {
vector<int> val; // 確定値
vector<color> lazy; // 遅延値(自分の色かどうか: Mine, Yours or 塗りつぶしが一様でない: Invalid)
lazy_segtree() { val.resize(Max*2); lazy.resize(Max*2); }
int get(int x, int y, int l=0, int r=Max, int k=1) {
if(r <= x || y <= l) { return 0; }
if(x <= l && r <= y) { return val[k]; }
x = max(x, l); y = min(y, r);
if(lazy[k] != color::invalid) { return lazy[k] == color::mine ? (y-x) : 0; }
return get(x, y, l, (l+r)/2, k*2) + get(x, y, (l+r)/2, r, k*2+1);
}
void update(int x, int y, color col, int l=0, int r=Max, int k=1) {
if(l >= r) { return ; }
if(x <= l && r <= y) {
lazy[k] = col;
val[k] = lazy[k] != color::yours ? (r-l) : 0;
}
else if(l < y && x < r) {
if(lazy[k] != color::invalid) {
lazy[k*2] = lazy[k*2+1] = lazy[k];
val[k*2] = val[k*2+1] = lazy[k] != color::yours ? (r-l) / 2 : 0;
lazy[k] = color::invalid;
}
update(x, y, col, l, (l+r)/2, k*2);
update(x, y, col, (l+r)/2, r, k*2+1);
val[k] = val[k*2] + val[k*2+1];
}
}
};
int N, Q;
ll AA, BB;
lazy_segtree<1<<21> st[2];
int main() {
cin >> N >> Q;
while(Q--) {
int x, l, r;
cin >> x >> l >> r;
if(x == 0) {
int a = st[0].get(l, r+1);
int b = st[1].get(l, r+1);
if(a > b) { AA += a; }
if(a < b) { BB += b; }
}
else {
st[x-1].update(l, r+1, color::mine);
st[(x-1)^1].update(l, r+1, color::yours);
}
}
AA += st[0].get(0, N);
BB += st[1].get(0, N);
cout << AA << " " << BB << endl;
return 0;
}
moti