結果

問題 No.674 n連勤
ユーザー cielciel
提出日時 2018-04-18 00:38:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,190 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 58,856 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 11:12:29
合計ジャッジ時間 1,890 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 14 ms
4,376 KB
testcase_15 AC 12 ms
4,380 KB
testcase_16 AC 155 ms
4,376 KB
testcase_17 AC 156 ms
4,380 KB
testcase_18 AC 29 ms
4,380 KB
testcase_19 AC 14 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<long long,long long> pll;

long long checkio(const vector<pll> &v){
	long long result=0;
	long long l,r;
	vector<pll> se;
	long long ma=0;
	for(auto &e:v){
		l=e.first,r=e.second;
		auto right=lower_bound(se.begin(),se.end(),make_pair(l,0LL)); //l <= se[right_idx].first
		size_t right_idx=right-se.begin();
		if(right_idx!=0){
			size_t left_idx=right_idx-1;
			if(l<=se[left_idx].second+1){ // overlap with left
				l=se[left_idx].first;
				r=max(r,se[left_idx].second);
				result-=se[left_idx].second-se[left_idx].first+1;
				se.erase(se.begin()+left_idx);
				right_idx--;
			}
		}
		while(right_idx<se.size() && se[right_idx].first-1<=r){ // overlap with right
			r=max(r,se[right_idx].second);
			result-=se[right_idx].second-se[right_idx].first+1;
			se.erase(se.begin()+right_idx);
		}
		result+=r-l+1;
		se.insert(se.begin()+right_idx,make_pair(l,r));
		ma=max(ma,r-l+1);
		printf("%lld\n",ma);
	}
	return result;
}

int main(){
	vector<pll>data;
	long long a,b;
	scanf("%lld%lld",&a,&b);
	for(;~scanf("%lld%lld",&a,&b);){
		data.emplace_back(a,b);
	}
	checkio(data);
}
0