結果

問題 No.1338 Giant Class
ユーザー oteraotera
提出日時 2021-01-16 05:06:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 2,530 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 209,792 KB
実行使用メモリ 8,384 KB
最終ジャッジ日時 2023-08-18 01:42:01
合計ジャッジ時間 5,152 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 42 ms
5,312 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 42 ms
5,844 KB
testcase_07 AC 62 ms
7,864 KB
testcase_08 AC 40 ms
5,844 KB
testcase_09 AC 36 ms
5,584 KB
testcase_10 AC 68 ms
8,280 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 46 ms
6,340 KB
testcase_13 AC 41 ms
5,884 KB
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 17 ms
4,380 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 41 ms
5,856 KB
testcase_18 AC 11 ms
4,376 KB
testcase_19 AC 19 ms
4,380 KB
testcase_20 AC 74 ms
8,224 KB
testcase_21 AC 73 ms
8,384 KB
testcase_22 AC 75 ms
8,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *    author:  otera    
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T>
struct SegmentTree{
private:
    int n;
    T E;
    vector<T> node;
    inline void updatef(T& x,T& y){
        //x = y;
        // x += y;
        //x = max(x,y);
        x = min(x,y);
    }
    inline T queryf(T& x,T& y){
        //return min(x,y);
        return x+y;
        //return max(x,y);
    }

public:
    SegmentTree(int sz,T E_):E(E_){
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
    }

    SegmentTree(vector<T>& A,T E_):E(E_){
        int sz=A.size();
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
        rep(i,sz)node[i+n-1]=A[i];
        for(int i=n-2;i>=0;--i){
            node[i]=queryf(node[2*i+1], node[2*i+2]);
        }
    }
    void update(int k,T x){
        k+=n-1;
        updatef(node[k],x);
        while(k>0){
            k=(k-1)/2;
            node[k]=queryf(node[2*k+1], node[2*k+2]);
        }
    }
       //[a,b)での値を返す
    T get(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=a||b<=l)return E;
        if(a<=l&&r<=b)return node[k];
        T xl=get(a,b,2*k+1,l,(l+r)/2);
        T xr=get(a,b,2*k+2,(l+r)/2,r);
        return queryf(xl, xr);
    }
};

void solve() {
    int h, w; cin >> h >> w;
    int q; cin >> q;
    vector<int> y(q), x(q);
    rep(i, q) {
        cin >> y[i] >> x[i];
        -- y[i], -- x[i];
    }
    auto comx = x;
    sort(all(comx));
    comx.erase(unique(all(comx)), comx.end());
    int sz = (int)comx.size();
    ll offset = (w - sz) * h;
    vector<int> vec(sz, h);
    SegmentTree<int> seg(vec, 0);
    rep(i, q) {
        x[i] = lower_bound(all(comx), x[i]) - comx.begin();
        seg.update(x[i], y[i]);
        cout << offset + seg.get(0, sz) << "\n";
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}
0