結果

問題 No.877 Range ReLU Query
ユーザー kotatsugamekotatsugame
提出日時 2019-09-08 12:51:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 367 ms / 2,000 ms
コード長 1,885 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 94,596 KB
実行使用メモリ 10,720 KB
最終ジャッジ日時 2024-04-25 22:12:45
合計ジャッジ時間 6,284 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 348 ms
10,544 KB
testcase_12 AC 310 ms
10,268 KB
testcase_13 AC 251 ms
8,000 KB
testcase_14 AC 262 ms
7,944 KB
testcase_15 AC 367 ms
10,440 KB
testcase_16 AC 344 ms
10,292 KB
testcase_17 AC 355 ms
10,444 KB
testcase_18 AC 355 ms
10,580 KB
testcase_19 AC 341 ms
10,720 KB
testcase_20 AC 356 ms
10,596 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
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)+n-1;
		int R=(b<0?0:b>n?n:b)+n-1;
		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;
vector<pair<pair<int,int>,pair<int,int> > >E;
vector<pair<int,int> >A;
long ans[1<<17];
main()
{
	cin>>N>>Q;
	segtree<pair<long,int> >P(N,make_pair(0,0),
	[](pair<long,int>a,pair<long,int>b){return make_pair(a.first+b.first,a.second+b.second);}
	);
	for(int i=0;i<N;i++)
	{
		int a;cin>>a;
		A.push_back(make_pair(a,i));
		P.update(i,make_pair(a,1));
	}
	for(int i=0;i<Q;i++)
	{
		int c,l,r,x;cin>>c>>l>>r>>x;
		E.push_back(make_pair(make_pair(x,i),make_pair(l,r)));
	}
	sort(A.begin(),A.end());
	sort(E.begin(),E.end());
	int id=0;
	for(pair<pair<int,int>,pair<int,int> >p:E)
	{
		while(id<N&&A[id].first<p.first.first)
		{
			P.update(A[id].second,make_pair(0,0));
			id++;
		}
		pair<long,int>a=P.query(p.second.first-1,p.second.second);
		ans[p.first.second]=a.first-1L*a.second*p.first.first;
	}
	for(int i=0;i<Q;i++)cout<<ans[i]<<endl;
}
0