結果

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

ソースコード

diff #

#include <iostream>
#include <set>
#include <vector>

long long res;
int n, a[200000];
std::multiset<int> st;
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) 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