Submission #210010

# Submission time Handle Problem Language Result Execution time Memory
210010 2020-03-16T09:31:31 Z Alexa2001 RMQ (NOI17_rmq) C++17
100 / 100
66 ms 8824 KB
#include <bits/stdc++.h>
//#define no_sol { cout << "-1\n"; exit(0); }


using namespace std;

///11:12

const int Nmax = 1e5 + 5;

set<int> S;
int last, n, m;
vector<pair<int,int>> v[Nmax];
bool used[Nmax];
int ans[Nmax];



void no_sol()
{
    int i;
    for(i=0; i<n; ++i) cout << "-1 ";
    exit(0);
}



void add(int val, int start, int finish, int L, int R)
{
    set<int> :: iterator it = S.lower_bound(start), it2 = it;

    bool added = 0;

    while(it != S.end() && *it <= finish)
    {
        if(*it >= L && *it <= R && !added)
        {
            assert(used[val] == 0);
            ans[*it] = val;
            used[val] = 1;
            added = 1;
        }
        else
        {
            while(last>=0 && used[last]) --last;
            if(last <= val) no_sol();

            used[last] = 1;
            ans[*it] = last;
        }

        ++it;
    }

    if(!added) no_sol();
    S.erase(it2, it);
}

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;

    int i;
    for(i=1; i<=m; ++i)
    {
        int x, y, val;
        cin >> x >> y >> val;
        v[val].push_back({x, y});
    }

    for(i=0; i<n; ++i) S.insert(i);

    last = n-1;

    for(i=n-1; i>=0; --i)
        if(v[i].size())
        {
            int lmin, rmax, lmax, rmin;
            lmin = rmin = n-1;
            lmax = rmax = 0;

            for(auto it : v[i])
            {
                int x, y;
                tie(x, y) = it;

                lmin = min(lmin, x);
                lmax = max(lmax, x);
                rmin = min(rmin, y);
                rmax = max(rmax, y);
            }

            if(lmax > rmin) no_sol();

            add(i, lmin, rmax, lmax, rmin);
        }

    for(auto it : S)
    {
        while(last>=0 && used[last]) --last;
        if(last < 0) no_sol();
        ans[it] = last;
        used[last] = 1;
    }


    for(i=0; i<n; ++i) cout << ans[i] << ' ';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2684 KB Output is correct
3 Correct 7 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2684 KB Output is correct
3 Correct 7 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
12 Correct 6 ms 2680 KB Output is correct
13 Correct 7 ms 2680 KB Output is correct
14 Correct 6 ms 2680 KB Output is correct
15 Correct 6 ms 2680 KB Output is correct
16 Correct 7 ms 2808 KB Output is correct
17 Correct 6 ms 2808 KB Output is correct
18 Correct 6 ms 2684 KB Output is correct
19 Correct 6 ms 2680 KB Output is correct
20 Correct 6 ms 2680 KB Output is correct
21 Correct 6 ms 2808 KB Output is correct
22 Correct 6 ms 2808 KB Output is correct
23 Correct 6 ms 2808 KB Output is correct
24 Correct 6 ms 2808 KB Output is correct
25 Correct 6 ms 2680 KB Output is correct
26 Correct 6 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2684 KB Output is correct
3 Correct 7 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
12 Correct 6 ms 2680 KB Output is correct
13 Correct 7 ms 2680 KB Output is correct
14 Correct 6 ms 2680 KB Output is correct
15 Correct 6 ms 2680 KB Output is correct
16 Correct 7 ms 2808 KB Output is correct
17 Correct 6 ms 2808 KB Output is correct
18 Correct 6 ms 2684 KB Output is correct
19 Correct 6 ms 2680 KB Output is correct
20 Correct 6 ms 2680 KB Output is correct
21 Correct 6 ms 2808 KB Output is correct
22 Correct 6 ms 2808 KB Output is correct
23 Correct 6 ms 2808 KB Output is correct
24 Correct 6 ms 2808 KB Output is correct
25 Correct 6 ms 2680 KB Output is correct
26 Correct 6 ms 2680 KB Output is correct
27 Correct 56 ms 7472 KB Output is correct
28 Correct 56 ms 7952 KB Output is correct
29 Correct 49 ms 7548 KB Output is correct
30 Correct 60 ms 8304 KB Output is correct
31 Correct 49 ms 7024 KB Output is correct
32 Correct 50 ms 6768 KB Output is correct
33 Correct 33 ms 7416 KB Output is correct
34 Correct 25 ms 5880 KB Output is correct
35 Correct 42 ms 8184 KB Output is correct
36 Correct 51 ms 8568 KB Output is correct
37 Correct 66 ms 8824 KB Output is correct
38 Correct 21 ms 6008 KB Output is correct
39 Correct 46 ms 7516 KB Output is correct
40 Correct 6 ms 2680 KB Output is correct
41 Correct 6 ms 2680 KB Output is correct