Submission #3379331


Source Code Expand

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

template<typename T>
struct delay_segtree {
private:
    int N;
    vector<T> node, lazy;
    //例外値 ex)INF,0
    //-------書くとこ---------------------
    T default_value = 0;
    T default_lazy = 0;
    static inline T merge(const T& u, const T& v) {
        return max(u,v);
    }
    static inline void lazy_transmit(T& u, const T& v) {
        u += v;
    }
    static inline void node_transmit(T& u,const T& v,int l,int r){
        u += v;
    }
    //------------------------------------
    // k 番目のノードについて遅延評価を行う
    void eval(int k, int l, int r) {
        // 遅延配列が空でない場合、自ノード及び子ノードへの
        // 値の伝播が起こる
        if (lazy[k] != default_lazy) {
            node_transmit(node[k], lazy[k],l,r);
            // 最下段かどうかのチェックをしよう
            if (r - l > 1) {
                lazy_transmit(lazy[2 * k + 1], lazy[k]);
                lazy_transmit(lazy[2 * k + 2], lazy[k]);
            }
            // 伝播が終わったので、自ノードの遅延配列を空にする
            lazy[k] = default_lazy;
        }
    }
public:
    delay_segtree(int n) {
        for(N=1;N<n;N*=2);
        node.resize(2 * N, default_value);
        lazy.resize(2 * N, default_lazy);
    }
    delay_segtree(vector<int> v) {
        int sz = v.size();
        for(N=1;N<sz;N*=2);
        node.resize(2 * N, default_value);
        lazy.resize(2 * N, default_lazy);
        for (int i = 0; i < sz; i++)
            node[i + N - 1] = v[i];
        for (int i = N - 2; i >= 0; i--)
            node[i] = merge(node[2 * i + 1], node[2 * i + 2]);
    }
    void update(int a, int b, T x, int k = 0, int l = 0, int r = -1) {
        if (r < 0)
            r = N;
        // k 番目のノードに対して遅延評価を行う
        eval(k, l, r);
        // 範囲外なら何もしない
        if (b <= l || r <= a)
            return;
        // 完全に被覆しているならば、遅延配列に値を入れた後に評価
        if (a <= l && r <= b) {
            lazy_transmit(lazy[k], x);
            eval(k, l, r);
        }
        // そうでないならば、子ノードの値を再帰的に計算して、
        // 計算済みの値をもらってくる
        else {
            update(a, b, x, 2 * k + 1, l, (l + r) / 2);
            update(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = merge(node[2 * k + 1], node[2 * k + 2]);
        }
    }
    // update k th element
    void update(int k, T val) {
        k += N - 1; // leaf
        node[k] = val;
        while (k > 0) {
            k = (k - 1) / 2;
            node[k] = merge(node[k * 2 + 1], node[k * 2 + 2]);
        }
    }
    // [a, b)
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0)
            r = N;
        eval(k, l, r);
        if (r <= a or b <= l)
            return default_value;
        if (a <= l and r <= b)
            return node[k];
        int m = (l + r) / 2;
        T vl = query(a, b, k * 2 + 1, l, m);
        T vr = query(a, b, k * 2 + 2, m, r);
        return merge(vl, vr);
    }

    T operator[](const int &k) {
        //遅延評価をまずしておく
        query(k, k + 1);
        return node[k + N - 1];
    }
};



int main(){
  int N;cin>>N;
  delay_segtree<ll> seg(112345);
  vint S(N),T(N);
  repeat(i,N){
    cin>>S[i]>>T[i];
    seg.update(S[i],T[i],1);
  }
  ll ans = INF;
  repeat(i,N){
    seg.update(S[i],T[i],-1);
    ans = min(ans,seg.query(0,112345));
    seg.update(S[i],T[i],1);
  }
  cout << ans << endl;
  return 0;
}

Submission Info

Submission Time
Task D - 足ゲームII
User hashiryo
Language C++14 (GCC 5.4.1)
Score 100
Code Size 4614 Byte
Status AC
Exec Time 233 ms
Memory 5120 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 34
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
All sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01-01.txt AC 3 ms 4352 KB
01-02.txt AC 3 ms 4352 KB
01-03.txt AC 3 ms 4352 KB
01-04.txt AC 5 ms 4352 KB
01-05.txt AC 230 ms 5120 KB
01-06.txt AC 228 ms 5120 KB
01-07.txt AC 228 ms 5120 KB
01-08.txt AC 228 ms 5120 KB
01-09.txt AC 228 ms 5120 KB
01-10.txt AC 3 ms 4352 KB
01-11.txt AC 228 ms 5120 KB
01-12.txt AC 228 ms 5120 KB
01-13.txt AC 229 ms 5120 KB
01-14.txt AC 228 ms 5120 KB
01-15.txt AC 8 ms 4352 KB
01-16.txt AC 228 ms 5120 KB
01-17.txt AC 233 ms 5120 KB
01-18.txt AC 228 ms 5120 KB
01-19.txt AC 229 ms 5120 KB
01-20.txt AC 8 ms 4352 KB
01-21.txt AC 225 ms 5120 KB
01-22.txt AC 225 ms 5120 KB
01-23.txt AC 225 ms 5120 KB
01-24.txt AC 165 ms 5120 KB
01-25.txt AC 3 ms 4352 KB
01-26.txt AC 3 ms 4352 KB
01-27.txt AC 143 ms 5120 KB
01-28.txt AC 144 ms 5120 KB
sample-01.txt AC 3 ms 4352 KB
sample-02.txt AC 3 ms 4352 KB
sample-03.txt AC 3 ms 4352 KB