Submission #163936

# Submission time Handle Problem Language Result Execution time Memory
163936 2019-11-16T10:27:13 Z combi1k1 Deda (COCI17_deda) C++14
140 / 140
401 ms 29188 KB
#include<bits/stdc++.h>

using namespace std;

#define all(x)  x.begin(),x.end()
#define sz(x)   x.size()

const int   N   = 2e5 + 1;

namespace BIT2D {
    vector<int> val[N];
    vector<int> bit[N];

    void ini()  {
        for(int i = 1 ; i < N ; ++i)    {
            sort(all(val[i]));
            val[i].resize(unique(all(val[i])) - val[i].begin());
            bit[i].assign(val[i].size() + 5,N);
        }
    }
    void add(int x,int y)   {
        for(; x > 0 ; x -= x & -x)
            val[x].push_back(y);
    }
    void upd(int x,int y,int v) {
        for(; x > 0 ; x -= x & -x)  {
            int p = upper_bound(all(val[x]),y) - val[x].begin();
            int K = bit[x].size();
            for(; p < K ; p += p & -p)
                bit[x][p] = min(bit[x][p],v);
        }
    }
    int get(int x,int y)    {
        int ans = N;
        for(; x < N ; x += x & -x)  {
            int p = upper_bound(all(val[x]),y)  - val[x].begin();
            for(; p > 0 ; p -= p & -p)
                ans = min(ans,bit[x][p]);
        }
        return  ans;
    }
};

int t[N], s[N];
int a[N], b[N];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;
    int q;  cin >> q;

    for(int i = 0 ; i < q ; ++i)    {
        char c; cin >> c;   t[i] = (c == 'M');
        cin >> b[i];
        cin >> a[i];

        if (t[i])   BIT2D::add(a[i],b[i]);
    }

    BIT2D::ini();

    for(int i = 0 ; i < q ; ++i)    {
        if (t[i])   BIT2D::upd(a[i],b[i],a[i]);
        else    {
            int res = BIT2D::get(a[i],b[i]);
            if (res > n)
                res = -1;

            cout << res << "\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 25 ms 15992 KB Output is correct
2 Correct 25 ms 15992 KB Output is correct
3 Correct 28 ms 16120 KB Output is correct
4 Correct 158 ms 23004 KB Output is correct
5 Correct 401 ms 29188 KB Output is correct
6 Correct 374 ms 28428 KB Output is correct
7 Correct 353 ms 27640 KB Output is correct