답안 #210008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210008 2020-03-16T09:25:32 Z Alexa2001 RMQ (NOI17_rmq) C++17
46.1 / 100
67 ms 10104 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)
        {
            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;
    }


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

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2684 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 7 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
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2684 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 7 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 Partially correct 7 ms 2680 KB Output is partially correct
13 Correct 6 ms 2680 KB Output is correct
14 Correct 7 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 7 ms 2680 KB Output is correct
18 Correct 7 ms 2680 KB Output is correct
19 Partially correct 7 ms 2684 KB Output is partially correct
20 Partially correct 6 ms 2680 KB Output is partially correct
21 Correct 6 ms 2680 KB Output is correct
22 Correct 6 ms 2808 KB Output is correct
23 Correct 7 ms 2680 KB Output is correct
24 Correct 6 ms 2680 KB Output is correct
25 Correct 6 ms 2680 KB Output is correct
26 Correct 6 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2684 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 7 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 Partially correct 7 ms 2680 KB Output is partially correct
13 Correct 6 ms 2680 KB Output is correct
14 Correct 7 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 7 ms 2680 KB Output is correct
18 Correct 7 ms 2680 KB Output is correct
19 Partially correct 7 ms 2684 KB Output is partially correct
20 Partially correct 6 ms 2680 KB Output is partially correct
21 Correct 6 ms 2680 KB Output is correct
22 Correct 6 ms 2808 KB Output is correct
23 Correct 7 ms 2680 KB Output is correct
24 Correct 6 ms 2680 KB Output is correct
25 Correct 6 ms 2680 KB Output is correct
26 Correct 6 ms 2680 KB Output is correct
27 Correct 60 ms 8808 KB Output is correct
28 Correct 59 ms 9104 KB Output is correct
29 Correct 54 ms 8568 KB Output is correct
30 Correct 67 ms 9584 KB Output is correct
31 Correct 49 ms 8044 KB Output is correct
32 Correct 50 ms 8048 KB Output is correct
33 Partially correct 34 ms 7416 KB Output is partially correct
34 Partially correct 25 ms 5880 KB Output is partially correct
35 Partially correct 42 ms 8312 KB Output is partially correct
36 Correct 53 ms 9464 KB Output is correct
37 Correct 62 ms 10104 KB Output is correct
38 Correct 29 ms 6008 KB Output is correct
39 Correct 50 ms 8544 KB Output is correct
40 Correct 6 ms 2680 KB Output is correct
41 Correct 6 ms 2680 KB Output is correct