結果

問題 No.1000 Point Add and Array Add
ユーザー kotatsugamekotatsugame
提出日時 2020-02-28 21:35:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 1,980 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 15,380 KB
最終ジャッジ日時 2024-04-21 18:05:55
合計ジャッジ時間 5,476 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 263 ms
11,816 KB
testcase_17 AC 234 ms
9,472 KB
testcase_18 AC 387 ms
12,948 KB
testcase_19 AC 377 ms
12,820 KB
testcase_20 AC 255 ms
15,252 KB
testcase_21 AC 407 ms
10,624 KB
testcase_22 AC 281 ms
15,380 KB
testcase_23 AC 395 ms
11,156 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   74 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct dualsegtree{
	using F=function<T(T,T)>;
	const F lazycalcfn,updatefn;
	int n;
	T lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	dualsegtree(int n_=0,T defvalue=0,
		const F lazycalcfn_=[](T a,T b){return a+b;},
		const F updatefn_=[](T a,T b){return a+b;},
		T lazydefvalue_=0
	):lazydefvalue(lazydefvalue_),
		lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(n,defvalue);
		lazy.assign(n-1,lazydefvalue);
		lazyflag.assign(n-1,false);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i]=v[i];
		lazy.assign(n-1,lazydefvalue);
		lazyflag.assign(n-1,false);
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			if(k<n-1)
			{
				lazy[k]=lazycalcfn(lazy[k],x);
				lazyflag[k]=true;
			}
			else dat[k-n+1]=updatefn(dat[k-n+1],x);
		}
		else
		{
			if(lazyflag[k])
			{
				update(0,n,lazy[k],k*2+1,l,(l+r)/2);
				update(0,n,lazy[k],k*2+2,(l+r)/2,r);
				lazy[k]=lazydefvalue;
				lazyflag[k]=false;
			}
			update(a,b,x,k*2+1,l,(l+r)/2);
			update(a,b,x,k*2+2,(l+r)/2,r);
		}
	}
	T query(int i)
	{
		T ret=dat[i];
		i+=n-1;
		while(i>0)
		{
			i=(i-1)/2;
			if(lazyflag[i])ret=updatefn(ret,lazy[i]);
		}
		return ret;
	}
};
int N,Q;
long A[2<<17];
long ans[2<<17];
main()
{
	cin>>N>>Q;
	for(int i=0;i<N;i++)cin>>A[i];
	dualsegtree<long>P(N);
	vector<pair<int,pair<long,long> > >Bu;
	for(int i=0;i<Q;i++)
	{
		char c;int x,y;cin>>c>>x>>y;
		if(c=='B')
		{
			P.update(x-1,y,1);
		}
		else
		{
			Bu.push_back(make_pair(x-1,make_pair(y,-P.query(x-1))));
		}
	}
	for(int i=0;i<N;i++)
	{
		ans[i]=A[i]*P.query(i);
	}
	for(pair<int,pair<long,long> >p:Bu)
	{
		long y=p.second.first,cnt=p.second.second;
		cnt+=P.query(p.first);
		ans[p.first]+=cnt*y;
	}
	for(int i=0;i<N;i++)cout<<ans[i]<<(i+1==N?"\n":" ");
}
0