結果

問題 No.833 かっこいい電車
ユーザー kotatsugamekotatsugame
提出日時 2019-05-24 22:32:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 579 ms / 2,000 ms
コード長 1,729 bytes
コンパイル時間 1,201 ms
コンパイル使用メモリ 93,848 KB
実行使用メモリ 5,432 KB
最終ジャッジ日時 2023-09-14 20:53:48
合計ジャッジ時間 7,734 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 579 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 262 ms
4,376 KB
testcase_11 AC 331 ms
5,432 KB
testcase_12 AC 95 ms
4,376 KB
testcase_13 AC 73 ms
4,376 KB
testcase_14 AC 246 ms
5,128 KB
testcase_15 AC 118 ms
4,380 KB
testcase_16 AC 64 ms
4,376 KB
testcase_17 AC 98 ms
4,376 KB
testcase_18 AC 323 ms
4,380 KB
testcase_19 AC 71 ms
4,376 KB
testcase_20 AC 14 ms
4,376 KB
testcase_21 AC 283 ms
4,376 KB
testcase_22 AC 126 ms
5,268 KB
testcase_23 AC 85 ms
4,380 KB
testcase_24 AC 132 ms
5,276 KB
testcase_25 AC 318 ms
4,380 KB
testcase_26 AC 87 ms
5,136 KB
testcase_27 AC 202 ms
4,424 KB
testcase_28 AC 159 ms
4,376 KB
testcase_29 AC 179 ms
4,380 KB
testcase_30 AC 83 ms
5,180 KB
testcase_31 AC 409 ms
4,396 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:52:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   52 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
	function<T(T,T)>calcfn,updatefn;
	int n;
	T defvalue;
	vector<T>dat;
	segtree(int n_=0,T defvalue_=numeric_limits<T>::max(),
		function<T(T,T)>calcfn_=[](T a,T b){return a<b?a:b;},
		function<T(T,T)>updatefn_=[](T a,T b){return b;}
	):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
	}
	void update(int i,T a)
	{
		i+=n-1;
		dat[i]=updatefn(dat[i],a);
		while(i>0)
		{
			i=(i-1)/2;
			dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
		}
	}
	T query(int a,int b,int i=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		if(r<=a||b<=l)return defvalue;
		else if(a<=l&&r<=b)return dat[i];
		else
		{
			return calcfn(
				query(a,b,i*2+1,l,(l+r)/2),
				query(a,b,i*2+2,(l+r)/2,r)
			);
		}
	}
};
int N,q;
main()
{
	cin>>N>>q;
	segtree<long>P(N+1,0,[](long a,long b){return a+b;},[](long a,long b){return a+b;});
	segtree<bool>Q(N+1,true,[](bool a,bool b){return a&&b;});
	for(int i=0;i<N;i++)
	{
		long A;cin>>A;P.update(i+1,A);
	}
	for(int i=0;i<=N;i++)Q.update(i,false);
	for(;q--;)
	{
		int id,x;cin>>id>>x;
		if(id==1)Q.update(x,true);
		else if(id==2)Q.update(x,false);
		else if(id==3)P.update(x,1);
		else
		{
			int L,R,l,r;
			l=0,r=x;
			while(r-l>1)
			{
				int m=(r+l)/2;
				if(Q.query(m,x))r=m;
				else l=m;
			}
			L=r;
			l=x-1,r=N+1;
			while(r-l>1)
			{
				int m=(r+l)/2;
				if(Q.query(x,m))l=m;
				else r=m;
			}
			R=r;
			cout<<P.query(L,R)<<endl;
		}
	}
}
0