結果

問題 No.2065 Sum of Min
ユーザー kotatsugamekotatsugame
提出日時 2022-09-03 01:20:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 684 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 79,732 KB
実行使用メモリ 8,168 KB
最終ジャッジ日時 2024-04-28 01:12:12
合計ジャッジ時間 5,649 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_04 AC 125 ms
8,040 KB
testcase_05 AC 126 ms
8,040 KB
testcase_06 AC 118 ms
8,040 KB
testcase_07 AC 137 ms
8,040 KB
testcase_08 AC 155 ms
8,036 KB
testcase_09 AC 158 ms
8,044 KB
testcase_10 AC 150 ms
8,044 KB
testcase_11 AC 153 ms
8,040 KB
testcase_12 AC 159 ms
8,040 KB
testcase_13 AC 159 ms
8,168 KB
testcase_14 AC 164 ms
8,040 KB
testcase_15 AC 163 ms
8,168 KB
testcase_16 AC 162 ms
8,044 KB
testcase_17 AC 161 ms
7,916 KB
testcase_18 AC 160 ms
8,044 KB
testcase_19 AC 165 ms
7,912 KB
testcase_20 AC 160 ms
8,164 KB
testcase_21 AC 161 ms
8,168 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<atcoder/fenwicktree>
using namespace std;
int N,Q;
int L[1<<17],R[1<<17];
long ans[1<<17];
main()
{
	cin>>N>>Q;
	atcoder::fenwick_tree<long>C(N),A(N);
	vector<pair<int,int> >qs;
	for(int i=0;i<N;i++)
	{
		int a;cin>>a;
		qs.push_back(make_pair(a,i));
		C.add(i,1);
	}
	for(int i=0;i<Q;i++)
	{
		int x;
		cin>>L[i]>>R[i]>>x;
		L[i]--;
		qs.push_back(make_pair(x,~i));
	}
	sort(qs.begin(),qs.end());
	for(pair<int,int>p:qs)
	{
		if(p.second>=0)
		{
			C.add(p.second,-1);
			A.add(p.second,p.first);
		}
		else
		{
			int i=~p.second;
			ans[i]=C.sum(L[i],R[i])*p.first+A.sum(L[i],R[i]);
		}
	}
	for(int i=0;i<Q;i++)cout<<ans[i]<<"\n";
}
0