結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
tanimani364
|
| 提出日時 | 2021-05-03 19:06:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,876 bytes |
| コンパイル時間 | 1,914 ms |
| コンパイル使用メモリ | 209,236 KB |
| 最終ジャッジ日時 | 2025-01-21 06:21:38 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 6 |
ソースコード
#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]++;
ans=prev(mp.end())->first;
}
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;
}
tanimani364