結果

問題 No.876 Range Compress Query
ユーザー kotatsugamekotatsugame
提出日時 2019-09-08 12:48:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,516 bytes
コンパイル時間 1,022 ms
コンパイル使用メモリ 78,300 KB
実行使用メモリ 5,724 KB
最終ジャッジ日時 2023-09-09 22:24:22
合計ジャッジ時間 3,985 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:57:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   57 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
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)//[a,b)
	{
		int L=a<0?0:a>n?n:a;
		int R=b<0?0:b>n?n:b;
		T ret=defvalue;
		for(;L<R;L>>=1,R>>=1)
		{
			if(!(L&1))
			{
				ret=calcfn(ret,dat[L]);
			}
			if(!(R&1))
			{
				ret=calcfn(ret,dat[--R]);
			}
		}
		return ret;
	}
};
int N,Q;
long A[1<<17],B[1<<17];
main()
{
	cin>>N>>Q;
	segtree<int>P(N,0,[](int a,int b){return a+b;});
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		if(i)
		{
			B[i-1]=A[i]-A[i-1];
			if(B[i-1])P.update(i-1,1);
		}
	}
	for(int i=0;i<Q;i++)
	{
		int c,l,r;cin>>c>>l>>r;
		l--,r--;
		if(c==1)
		{
			int x;cin>>x;
			if(l)
			{
				B[l-1]+=x;
				P.update(l-1,!!B[l-1]);
			}
			if(r<N-1)
			{
				B[r]-=x;
				P.update(r,!!B[r]);
			}
		}
		else
		{
			cout<<P.query(l,r)+1<<endl;
		}
	}
}
0