Submission #386771

# Submission time Handle Problem Language Result Execution time Memory
386771 2021-04-07T09:35:36 Z BartolM Event Hopping 2 (JOI21_event2) C++17
1 / 100
140 ms 15456 KB
#define DEBUG 0
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=1e5+5;
const int LOG=18;

int n, m, k;
ppi p[N];
pii poc[N];
vector <pii> v;
int nx[LOG][N];
vector <int> res;
set <pii> S;
vector <int> sol;

void build() {
    for (int i=1; i<LOG; ++i) {
        for (int j=0; j<=m; ++j) {
            nx[i][j]=nx[i-1][nx[i-1][j]];
        }
    }
}

int calc(pii pp, int gr) {
    if (pp.Y>gr) return -INF;
    int x=lower_bound(v.begin(), v.end(), mp(pp.Y, -1))-v.begin();
    if (v[x].Y>gr) return 1;
    int ret=2;
    for (int i=LOG-1; i>=0; --i) {
        if (v[nx[i][x]].Y<=gr) {
            ret+=(1<<i);
            x=nx[i][x];
        }
    }
    return ret;
}

int cmp(ppi a, ppi b) {
    if (a.X.X==b.X.X) return a.X.Y>b.X.Y;
    return a.X.X<b.X.X;
}

void solve() {
    sort(p, p+n, cmp);
    int rig=INF;
    for (int i=n-1; i>=0; --i) {
        if (p[i].X.Y<rig) {
            rig=p[i].X.Y;
            v.pb(p[i].X);
        }
    }
    reverse(v.begin(), v.end());

    #if DEBUG
        printf("----------------\n");
        for (pii pp:v) printf("%d %d\n", pp.X, pp.Y);
    #endif // DEBUG

    m=v.size();
    v.pb(mp(INF, INF+1));
    nx[0][m]=m;
    for (int i=0; i<m; ++i) nx[0][i]=lower_bound(v.begin(), v.end(), mp(v[i].Y, -1))-v.begin();
    build();

    S.insert(mp(-2, -1));
    S.insert(mp(INF, INF+1));

    int uk=calc(mp(-2, -1), INF);
    if (uk<=k) {
        printf("-1\n");
        return;
    }

    for (int i=0; i<n; ++i) {
        if ((int)sol.size()>=k) break;
        pii pp=poc[i];
        if (S.count(pp)) continue;
        auto it=S.insert(pp).X;
        auto pr=it, slj=it;
        pr--; slj++;

        int prije=calc((*pr), slj->X);
        int sad=calc((*pr), it->X)+calc(pp, slj->X);
#if DEBUG
        printf("pp: (%d, %d), prije: %d, sad: %d\n", pp.X, pp.Y, prije, sad);
#endif
        if (uk-prije+sad<=k) S.erase(it);
        else sol.pb(i+1);
    }
    for (int x:sol) printf("%d\n", x);
}

void load() {
    scanf("%d %d", &n, &k);
    for (int i=0; i<n; ++i) {
        scanf("%d %d", &p[i].X.X, &p[i].X.Y);
        p[i].Y=i;
        poc[i]=p[i].X;
    }
}

int main() {
    load();
    solve();
	return 0;
}

Compilation message

event2.cpp: In function 'void load()':
event2.cpp:107:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  107 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
event2.cpp:109:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  109 |         scanf("%d %d", &p[i].X.X, &p[i].X.Y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 130 ms 15456 KB Output is correct
5 Correct 140 ms 15072 KB Output is correct
6 Correct 117 ms 14816 KB Output is correct
7 Correct 108 ms 14304 KB Output is correct
8 Correct 124 ms 15328 KB Output is correct
9 Correct 123 ms 15072 KB Output is correct
10 Correct 116 ms 14816 KB Output is correct
11 Correct 114 ms 14304 KB Output is correct
12 Correct 112 ms 12816 KB Output is correct
13 Correct 114 ms 12828 KB Output is correct
14 Correct 108 ms 12512 KB Output is correct
15 Correct 100 ms 12128 KB Output is correct
16 Correct 97 ms 7408 KB Output is correct
17 Correct 85 ms 7268 KB Output is correct
18 Correct 87 ms 7244 KB Output is correct
19 Correct 88 ms 3816 KB Output is correct
20 Incorrect 80 ms 3816 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 4 ms 592 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 4 ms 592 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 4 ms 492 KB Output is correct
29 Incorrect 3 ms 492 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 130 ms 15456 KB Output is correct
5 Correct 140 ms 15072 KB Output is correct
6 Correct 117 ms 14816 KB Output is correct
7 Correct 108 ms 14304 KB Output is correct
8 Correct 124 ms 15328 KB Output is correct
9 Correct 123 ms 15072 KB Output is correct
10 Correct 116 ms 14816 KB Output is correct
11 Correct 114 ms 14304 KB Output is correct
12 Correct 112 ms 12816 KB Output is correct
13 Correct 114 ms 12828 KB Output is correct
14 Correct 108 ms 12512 KB Output is correct
15 Correct 100 ms 12128 KB Output is correct
16 Correct 97 ms 7408 KB Output is correct
17 Correct 85 ms 7268 KB Output is correct
18 Correct 87 ms 7244 KB Output is correct
19 Correct 88 ms 3816 KB Output is correct
20 Incorrect 80 ms 3816 KB Output isn't correct
21 Halted 0 ms 0 KB -