結果

問題 No.865 24時間降水量
ユーザー kotatsugamekotatsugame
提出日時 2019-08-17 02:30:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 71,912 KB
実行使用メモリ 4,680 KB
最終ジャッジ日時 2023-10-24 23:03:13
合計ジャッジ時間 1,744 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
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 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0):n(n_),bit(n_+1){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
	int lower_bound(T k)//k<=sum(ret)
	{
		if(k<=0)return 0;
		int ret=0,i=1;
		while((i<<1)<=n)i<<=1;
		for(;i;i>>=1)
			if(ret+i<=n&&bit[ret+i]<k)k-=bit[ret+=i];
		return ret+1;
	}
};
int N;
int A[1<<17];
main()
{
	cin>>N;
	BIT<int>P(N);
	for(int i=1;i<=N;i++)
	{
		int a;cin>>a;P.add(i,a);
		A[i]=a;
	}
	int Q;cin>>Q;
	int ans=0;
	for(int i=24;i<=N;i++)
	{
		ans=max(ans,P.sum(i)-P.sum(i-24));
	}
	for(;Q--;)
	{
		int t,v;cin>>t>>v;
		P.add(t,v-A[t]);
		A[t]+=v;
		for(int i=max(0,t-24);i<=min(N-24,t);i++)
		{
			ans=max(ans,P.sum(i+24)-P.sum(i));
		}
		cout<<ans<<endl;
	}
}
0