結果

問題 No.674 n連勤
ユーザー tanimani364tanimani364
提出日時 2021-05-03 19:04:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,865 bytes
コンパイル時間 2,228 ms
コンパイル使用メモリ 213,000 KB
実行使用メモリ 5,476 KB
最終ジャッジ日時 2023-09-29 15:44:51
合計ジャッジ時間 3,127 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a; i >-1; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a; i > b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll mypow(ll x, ll n, const ll &p = -1)
{ //x^nをmodで割った余り

	if (p != -1)
	{
		x =(x%p+p)%p;
	}
	ll ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
//using namespace atcoder;

template<typename S,typename T>//S:the type of intervals,T:the type of data
struct IntervalMerge{
	struct interval{
		S l,r;
		T content;

		interval(const S &_l,const S &_r,const T &_content):l(_l),r(_r),content(_content){}
		interval(){}

		constexpr bool operator<(const interval &rhs)const{
			if(l!=rhs.l)return l<(rhs.l);
			return r<(rhs.r);
		}
	};
	set<interval>st;

	IntervalMerge(){}
	IntervalMerge(vector<T> &a){
		int n=a.size();
		a.eb(-1);
		int pos=0;
		while(pos<n){
			int pre=pos;
			while(pos<n&&a[pos]==a[pos+1])++pos;
			st.emplace(pre,pos+1,a[pre]);
			++pos;
		}
	}

	template<void(*add)(S,S,T),void(*del)(S,S,T)>
	void query(S l,S r,const T &x){//[l,r)
		auto itr=st.lower_bound(interval{l,l,numeric_limits<T>::max()});
		if(itr!=st.begin()){
			auto pre_itr=prev(itr);
			auto pre_interval=*pre_itr;
			if(pre_itr->r>=l){
				del(pre_itr->l,pre_itr->r,pre_itr->content);
				st.erase(pre_itr);
				if(pre_interval.content==x){
					l=pre_interval.l;
					r=max(r,pre_interval.r);
				}
				else {
					add(pre_interval.l,l,pre_interval.content);
					st.emplace(pre_interval.l,l,pre_interval.content);
					if(r<pre_interval.r){
						add(r,pre_interval.r,pre_interval.content);
						st.emplace(r,pre_interval.r,pre_interval.content);
					}
				}
			}
		}

		while(itr!=st.end()){
			if(r<=itr->l)break;
			if(itr->r<=r){
				del(itr->l,itr->r,itr->content);
				itr=st.erase(itr);
			}else{
				interval cur=*itr;
				del(itr->l,itr->r,itr->content);
				itr=st.erase(itr);
				if(cur.content==x)r=cur.r;
				else{
					add(r,cur.r,cur.content);
					st.emplace(r,cur.r,cur.content);
				}
				break;
			}
		}
		add(l,r,x);
		st.emplace(l,r,x);
	}
};


using S=ll;
using T=ll;
map<ll,ll>mp;
ll ans;

void add(S l,S r,T x){
	mp[r-l]++;
	chmax(ans,r-l);
}

void del(S l,S r,T x){
	mp[r-l]--;
	if(mp[r-l]==0){
		mp.erase(r-l);
		if(!mp.empty())ans=prev(mp.end())->first;
	}
}

void solve()
{
	ll d,q;
	cin>>d>>q;
	IntervalMerge<S,T>im;
	ans=0;
	while(q--){
		ll a,b;
		cin>>a>>b;
		b++;
		im.query<add,del>(a,b,1);
		cout<<ans<<"\n";
	}
	// for(auto x:im.st){
	// 	cout<<x.l<<" "<<x.r<<" "<<x.content<<"\n";
	// }
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


0