結果

問題 No.674 n連勤
ユーザー NokonoKotlinNokonoKotlin
提出日時 2021-10-02 02:51:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 9,189 bytes
コンパイル時間 1,216 ms
コンパイル使用メモリ 109,940 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 03:04:10
合計ジャッジ時間 3,737 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include<queue>
using namespace std;
//conversion
//------------------------------------------
inline long long toint(string s) {long long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef long long ll;
typedef long long LL;
typedef vector<int > vi;
typedef vector<long long > VLL;
typedef vector<long long > vll;
typedef vector<string > ves;
typedef vector<char > vech;

typedef pair<long long , long long> pll;
typedef pair<long long , long long> PLL;
typedef map<ll , ll >mll;
typedef map<int , int >mii;
typedef map<char , int >mci;
typedef map<char , ll >mcl;
typedef vector<pair<ll , ll> > vpll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define VECMAX(x) *max_element(ALL(x))
#define VECMIN(x) *min_element(ALL(x))
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(long long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//#define MULTIPLE(i,n,k) for(int i = (k) ; i<(n) ; i+=k+1)//倍数ループ
//constant
//------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define SIZEOF(x) sizeof(x)/sizeof(x[0])


const long long INF = 4e18;
const long long NINF = 1 - INF;

#define ENDL cout << endl;
#define CIN(a) REP(i,a.size())cin >> a[i];

//二次元座標の点を表す構造体。xとyをメンバに持つ
struct POINT{
    double x;
    double y;

};



ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

/*
    nCr , 値が大きいとオーバーフローする
    n<=kなら1 (0C1や1C5= 1)
*/
ll nCr(ll n,  ll r){
  if ( r * 2 > n ) r = n - r;
  ll dividend = 1;
  ll divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}



//firstが最大値(最小値) , second が index
template<class T>
pair<T , ll> maxP(vector<T> a , ll size){
    pair <T , ll> p;
    ll ind = 0;
    T mx = NINF;
    REP(i,size){
        if(mx<a[i]){
            mx = a[i];
            ind = i;
        }
    }
    p.first = mx;
    p.second = ind;
    return p;
}


template<class T>
pair<T , ll> minP(vector<T> a , ll size){
    pair <T , ll> p;
    T mn = INF;
    ll ind = 0;
    REP(i,size){
        if(mn > a[i]){
            mn = a[i];
            ind = i;
        }
    }
    p.first = mn;
    p.second = ind;
    return p;
}

template<class T>
T sumL(vector<T> a , ll size){
    T sum = 0;
    REP(i,size){
        sum += a[i];

    }
    return sum;
}


 //sort済みのvll ; a のleft ~ rightにtがいくつあるか
ll counT(VLL a ,ll left , ll right ,  ll t ){
    //sort(a.begin(),a.end());
    return upper_bound(a.begin() + left , a.begin() + right,t)-lower_bound(a.begin() + left , a.begin() + right, t);
}

//切り上げ
ll kiriage(ll a , ll b){
    return a/b + (a%b!=0);
}

#define COUNT(a,b) counT((a),0,a.size(),(b))

#define MAX(x) maxP(x,x.size())
#define MIN(x) minP(x,x.size())
#define SUM(x) sumL(x,x.size())




//-------要素を見つける-----------
ll search(vll &a , ll n ){//a内のnのindexを返す
    std::vector<ll>::iterator iter = std::find(a.begin(), a.end(), n);
    size_t index = distance(a.begin(), iter);
    return index;
}


//桁数
int getdigit(ll n){
    return log10(n)+1;
}



// toBinary[i]は,binaを二進数で表したときの下からi桁目のbitが入ってる
vll toBinary(ll bina){
    vll ans;
    for (ll i = 0; bina>0 ; i++)
    {
        ans.push_back(bina%2);
        bina = bina/2;
    }
    return ans;
}








/* 
    Description: 区間をsetで管理するデータ構造(なお実装はmap).各クエリO(log区間数).
    区間は閉区間!! : [l, r] ( include r, not [l, r) )

    // コンストラクタ 隣接区間を結合する場合はtrue、そうでないならfalse
    SegmentMap map(true);

    // iを含む区間[l, r]のstd::map<ll,ll>::const_iteratorを返す
     //  => [it.first , it.second]
    // iを含む区間が無ければmap.end()を返す
    auto it = map.get(i);
    
    map.insert(l, r);// 区間[l, r]を挿入する
    map.remove(l, r);// 全区間で[l, r]に重なる部分を全て消す
    bool f = map.same(i, j);// iとjが同じ区間に属しているかのbool値を返す
*/
class SegmentMap : public std::map<long long, long long> {
    private:
        bool flagToMergeAdjacentSegment;
    public:

    // 区間[l , c] , [c+1 , r]を結合して扱う場合、コンストラクタにtrueをいれる
    SegmentMap(bool flagToMergeAdjacentSegment)
    :flagToMergeAdjacentSegment(flagToMergeAdjacentSegment) 
    {

    }
    /* 
        SegmentMapに存在する区間(merge済み)のうち、点pを含む区間を返す
        map<int,int>のiterを返すので
        [iter.first , iter.second]といった表現になる
        
        なければ -> map.end()
    */
    auto get(long long p) const {
        auto it = upper_bound(p);
        if (it == begin() || (--it)->second < p) return end();
        return it;
    }

    // insert segment [l, r]
    void insert(long long l, long long r) {
        auto itl = upper_bound(l), itr = upper_bound(r + flagToMergeAdjacentSegment);
        if (itl != begin()) {
            if ((--itl)->second < l - flagToMergeAdjacentSegment) ++itl;
        }
        if (itl != itr) {
            l = std::min(l, itl->first);
            r = std::max(r, std::prev(itr)->second);
            erase(itl, itr);
        }
        (*this)[l] = r;
    }

    // remove segment [l, r]
    void remove(long long l, long long r) {
        auto itl = upper_bound(l), itr = upper_bound(r);
        if (itl != begin()) {
            if ((--itl)->second < l) ++itl;
        }
        if (itl == itr) return;
        long long tl = std::min(l, itl->first), tr = std::max(r, std::prev(itr)->second);
        erase(itl, itr);
        if (tl < l) (*this)[tl] = l - 1;
        if (r < tr) (*this)[r + 1] = tr;
    }

    // Is p and q in same segment?
    bool same(long long p, long long q) const {
        const auto&& it = get(p);
        return it != end() && it->first <= q && q <= it->second;
    }
};





//-----------MAIN:困った時メモ------------//
//    
//    Sqrは2乗 sqrtはルート , 二次元座標の点は struct POINT でも表せる(メンバはx , y)
//    小さい順ならpriority_queue<ll, vll, greater<ll> > と書く
//    ゲーム:grundy数 , グラフ:LCA,eulerTour, 
//    最大流がScalingMaxFlow , 最小費用流がPrimalDual<flow_t , cost_t>
//    めぐる式二分探索 , 半分前列挙
//    bitDP , 最小全域木でコストやグラフを求める , オイラーツアー , 0-1BFS 
//    オイラーツアーはDFS , 全域木はDFS , 三分探索
//    区間スケジューリング問題(右端が小さい順にソート)
//    定数倍(log)を落とすことで通ることもたまにある(setやmapに注意)
//    度数 = ラジアン × 180 ÷ 円周率
//    競技プログラミングでは「数が少ない方を考えると考察が進む場合がある」という典型テクニックがあります。
//    std::mapをループするときは、for(pair<type,type> x(要素): MAP)
//    期待値の線形性, 平均値は期待値の特殊な場合 

//    二次元累積和の計算 : s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + a[i][j];
//    (a,b) -> (c,d)の二次元累積和 : s[c][d] - s[a][d] - s[b][c] + s[a][b]

//    multisetは便利 , 値の重複、upperbound、追加削除がlogN , *rbeginで最大値,*beginで最小値

#define ENDL cout << endl;


ll n , m;
ll h , w , k; 
string s;
vll A ,B;    
map<ll , ll>p;
ll v , e;


int main(){
    
    SegmentMap M(1);
    
   ll d,q;cin>>d >>q;
   ll mx = 0;
   REP(i,q){
       ll a, b;
       cin>> a >> b;
   
       M.insert(a,b);
       map<ll,ll>::const_iterator it = M.get(a);
       pll p = *it;
       mx = max(mx , p.second-p.first+1);
       cout << mx << endl;

   }

    
    


    return 0;   
}

0