結果

問題 No.230 Splarraay スプラレェーイ
ユーザー 👑 kmjpkmjp
提出日時 2015-06-20 02:23:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 1,964 bytes
コンパイル時間 2,666 ms
コンパイル使用メモリ 159,604 KB
実行使用メモリ 27,720 KB
最終ジャッジ日時 2023-09-21 10:30:48
合計ジャッジ時間 3,753 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
27,648 KB
testcase_01 AC 11 ms
27,704 KB
testcase_02 AC 11 ms
27,676 KB
testcase_03 AC 11 ms
27,560 KB
testcase_04 AC 11 ms
27,484 KB
testcase_05 AC 12 ms
27,664 KB
testcase_06 AC 16 ms
27,720 KB
testcase_07 AC 13 ms
27,444 KB
testcase_08 AC 13 ms
27,484 KB
testcase_09 AC 41 ms
27,636 KB
testcase_10 AC 63 ms
27,664 KB
testcase_11 AC 32 ms
27,484 KB
testcase_12 AC 42 ms
27,704 KB
testcase_13 AC 17 ms
27,644 KB
testcase_14 AC 44 ms
27,484 KB
testcase_15 AC 72 ms
27,712 KB
testcase_16 AC 71 ms
27,524 KB
testcase_17 AC 73 ms
27,444 KB
testcase_18 AC 62 ms
27,648 KB
testcase_19 AC 56 ms
27,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<int NV> class SegTree_Lazy {
public:
	typedef pair<int,int> V;
	vector<int> val;
	vector<V> to;
	SegTree_Lazy(){val.resize(NV*2); to.resize(NV*2);};
	V comp(V l,V r){ l.first+=r.first, l.second+=r.second; return l;};
	V makeval(int type,int num) {
		return {(type==1)?num:0,(type==2)?num:0};
	}

	V getval(int x,int y,int l=0,int r=NV,int k=1) {
		if(r<=x || y<=l) return {0,0};
		if(x<=l && r<=y) return to[k];
		x=max(x,l);
		y=min(y,r);
		if(val[k]>=0) return makeval(val[k],y-x);
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}

	void update(int x,int y, int v,int l=0,int r=NV,int k=1) {
		if(l>=r) return;
		if(x<=l && r<=y) {
			val[k]=v;
			to[k]=makeval(v,r-l);
		}
		else if(l < y && x < r) {
			if(val[k]!=-1) {
				val[k*2]=val[k*2+1]=val[k];
				to[k*2]=to[k*2+1]=makeval(val[k],(r-l)/2);
				val[k]=-1;
			}
			update(x,y,v,l,(l+r)/2,k*2);
			update(x,y,v,(l+r)/2,r,k*2+1);
			to[k]=comp(to[k*2],to[k*2+1]);
		}
	}
};

int N,Q;
ll AA,BB;
SegTree_Lazy<1<<20> st;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	while(Q--) {
		cin>>x>>l>>r;
		
		if(x==0) {
			auto rr=st.getval(l,r+1);
			if(rr.first>rr.second) AA+=rr.first;
			if(rr.first<rr.second) BB+=rr.second;
		}
		else {
			st.update(l,r+1,x);
		}
	}
	auto rr=st.getval(0,N);
	AA+=rr.first;
	BB+=rr.second;
	
	_P("%lld %lld\n",AA,BB);
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0