結果

問題 No.1435 Mmm......
ユーザー nok0nok0
提出日時 2021-03-20 00:14:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 2,720 ms
コンパイル使用メモリ 147,688 KB
最終ジャッジ日時 2025-01-19 19:53:39
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
    6 | main(){scanf("%d",&n);
      | ^~~~
main.cpp: In function ‘int main()’:
main.cpp:6:13: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 | main(){scanf("%d",&n);
      |        ~~~~~^~~~~~~~~
main.cpp:7:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         for(i=0;i<n;)scanf("%d",&a[i++]);
      |                      ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include<atcoder/all>
#include<set>
long long res;
int n,i,a[200000];
std::multiset<int>st;
main(){scanf("%d",&n);
	for(i=0;i<n;)scanf("%d",&a[i++]);
	for(int l = 0, r = 0; l < n; res += r - l - 1, st.erase(st.lower_bound((a[l++])))) {
		while(r < n) {
			st.insert(a[r]);
			int tmp = *st.begin() + *(++st.begin()) - *st.rbegin();
			if(tmp < 0) {
				st.erase(st.lower_bound(a[r]));
				break;
			}
			r++;
		}
	}
	printf("%lld\n", res);
}
0