結果

問題 No.618 labo-index
ユーザー maimai
提出日時 2017-12-20 01:15:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 6,599 bytes
コンパイル時間 4,117 ms
コンパイル使用メモリ 236,932 KB
実行使用メモリ 14,628 KB
最終ジャッジ日時 2024-12-16 02:53:26
合計ジャッジ時間 216,744 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,088 KB
testcase_01 AC 2 ms
8,832 KB
testcase_02 AC 2 ms
8,704 KB
testcase_03 WA -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 WA -
testcase_35 AC 277 ms
12,544 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In member function '{anonymous}::MaiScanner& {anonymous}::MaiScanner::operator>>(std::string&)':
main.cpp:56:9: warning: no return statement in function returning non-void [-Wreturn-type]
   56 |         }
      |         ^

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include "bits/stdc++.h" // define macro "/D__MAI"

using namespace std;
typedef long long int ll;

#define xprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define debugv(v) {printf("L%d %s > ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) {printf("L%d %s > ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;}
#define debugaa(m,h,w) {printf("L%d %s >\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}}
#define ALL(v) (v).begin(),(v).end()
#define repeat(cnt,l) for(auto cnt=0ll;(cnt)<(l);++(cnt))
#define iterate(cnt,b,e) for(auto cnt=(b);(cnt)!=(e);++(cnt))
#define MD 1000000007ll
#define PI 3.1415926535897932384626433832795
#define NAME(v) #v
template<typename T1, typename T2> ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; }
template<typename T> T& maxset(T& to, const T& val) { return to = max(to, val); }
template<typename T> T& minset(T& to, const T& val) { return to = min(to, val); }
void bye(string s, int code = 0) { cout << s << endl; exit(0); }
mt19937_64 randdev(8901016);
inline ll rand_range(ll l, ll h) {
    return uniform_int_distribution<ll>(l, h)(randdev);
}

#if defined(_WIN32) || defined(_WIN64)
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#elif __GNUC__
#else
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#endif
namespace {
#define isvisiblechar(c) (0x21<=(c)&&(c)<=0x7E)
    class MaiScanner {
    public:
        template<typename T> void input_integer(T& var) {
            var = 0; T sign = 1;
            int cc = getchar_unlocked();
            for (; cc<'0' || '9'<cc; cc = getchar_unlocked())
                if (cc == '-') sign = -1;
            for (; '0' <= cc&&cc <= '9'; cc = getchar_unlocked())
                var = (var << 3) + (var << 1) + cc - '0';
            var = var*sign;
        }
        inline int c() { return getchar_unlocked(); }
        inline MaiScanner& operator>>(int& var) { input_integer<int>(var); return *this; }
        inline MaiScanner& operator>>(long long& var) { input_integer<long long>(var); return *this; }
        inline MaiScanner& operator>>(string& var) {
            int cc = getchar_unlocked();
            for (; !isvisiblechar(cc); cc = getchar_unlocked());
            for (; isvisiblechar(cc); cc = getchar_unlocked())
                var.push_back(cc);
        }
        template<typename IT> void in(IT begin, IT end) { for (auto it = begin; it != end; ++it) *this >> *it; }
    };
    class MaiPrinter {
    public:
        template<typename T>
        void output_integer(T var) {
            if (var == 0) { putchar_unlocked('0'); return; }
            if (var < 0)
                putchar_unlocked('-'),
                var = -var;
            char stack[32]; int stack_p = 0;
            while (var)
                stack[stack_p++] = '0' + (var % 10),
                var /= 10;
            while (stack_p)
                putchar_unlocked(stack[--stack_p]);
        }
        inline MaiPrinter& operator<<(char c) { putchar_unlocked(c); return *this; }
        inline MaiPrinter& operator<<(int var) { output_integer<int>(var); return *this; }
        inline MaiPrinter& operator<<(long long var) { output_integer<long long>(var); return *this; }
        inline MaiPrinter& operator<<(char* str_p) { while (*str_p) putchar_unlocked(*(str_p++)); return *this; }
        inline MaiPrinter& operator<<(const string& str) {
            const char* p = str.c_str();
            const char* l = p + str.size();
            while (p < l) putchar_unlocked(*p++);
            return *this;
        }
        template<typename IT> void join(IT begin, IT end, char sep = '\n') { for (auto it = begin; it != end; ++it) *this << *it << sep; }
    };
}
MaiScanner scanner;
MaiPrinter printer;


template<typename T = ll>
class Bitree {
public:
    int size_;
    vector<T> data_;
    Bitree(int size_) :size_(size_ + 1), data_(size_ + 1) {}

    // 1..rの範囲の値の和を求める.
    T sum(int r) {
        T s = 0;
        while (0 < r) {
            s += data_[r];
            r -= r&-r; //  r&-r と書くことで最下のビットを得る
        }
        return s;
    }
    // idxの要素の値をval増やす
    void add(int idx, T val) {
        while (idx <= size_) {
            data_[idx] += val;
            idx += idx&-idx;
        }
    }
};



typedef ll bsearch_t;
bsearch_t bin_search(bsearch_t low, bsearch_t high, function<bool(bsearch_t)> func) {
    ++high; // --l;
    bsearch_t c;
    while (low + 1 < high) {
        c = (low + high) / 2;
        (func(c) ? high : low) = c;
    }
    return high; // return l;
}




ll m, n, kei, n_q;
vector<pair<int, ll>> queries;
vector<int> join;

int main() {

    scanner >> n_q;
    queries.reserve(n_q);

    map<ll, int> kenq_zip;
    vector<ll> kenq_cv;

    vector<int> history_in;
    history_in.reserve(n_q);

    ll offset = 0;
    repeat(i, n_q) {
        int t; ll x;
        scanner >> t >> x;
        queries.emplace_back(t, x);

        switch (t)
        {
        case 1:
            kenq_zip[x - offset] = i;
            history_in.push_back(x - offset);
            queries.back().second = x - offset;
            break;
        case 2:
            queries.back().second = history_in[x - 1];// +offset;
            break;
        case 3:
            offset += x;
            break;
        }
    }

    kenq_cv.resize(kenq_zip.size() + 1);
    {
        int i = 1;
        for (auto& p : kenq_zip) {
            kenq_cv[i] = p.first;
            p.second = i++;
        }
    }

    Bitree<int> bit(100010);

    //debugv(kenq_cv);
    ll o = 0;
    repeat(i, n_q) {
        int t; ll x;
        tie(t, x) = queries[i];
        //cout << queries[i] << endl;

        switch (t)
        {
        case 1:
            bit.add(kenq_zip[x], 1);
            //cout << "in: " << kenq_zip[x] << endl;
            break;
        case 2:
            bit.add(kenq_zip[x], -1);
            //cout << "out: " << kenq_zip[x] << endl;
            break;
        case 3:
            o += x;
            break;
        }
        //for (auto e: kenq_cv) cout << e+o << ' ';cout<<endl;

        ll kenq = bin_search(-1, 1e12, [&](ll r) {
            auto it = lower_bound(ALL(kenq_cv), r - o);
            ll ri = distance(kenq_cv.begin(), it);
            return bit.sum(100005) - bit.sum(ri) <= r;
        });
        printer << kenq << '\n';
    }


    return 0;
}
0