Submission #1057226

#TimeUsernameProblemLanguageResultExecution timeMemory
1057226Faisal_Saqib팀들 (IOI15_teams)C++17
Compilation error
0 ms0 KiB
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

struct Node {
    int lc = 0, rc = 0;
    int sum = 0;
};

unordered_map<int, Node> seg;
int nfi = 1;  // Start node ID from 1

int build(int l, int r) {
    int cur = nfi++;
    if (l == r) return cur;
    int mid = (l + r) / 2;
    seg[cur].lc = build(l, mid);
    seg[cur].rc = build(mid + 1, r);
    return cur;
}

int update(int node, int l, int r, int x) {
    int cur = nfi++;
    seg[cur] = seg[node];
    if (l == r) {
        seg[cur].sum++;
        return cur;
    }
    int mid = (l + r) / 2;
    if (x <= mid) seg[cur].lc = update(seg[node].lc, l, mid, x);
    else seg[cur].rc = update(seg[node].rc, mid + 1, r, x);
    seg[cur].sum = seg[seg[cur].lc].sum + seg[seg[cur].rc].sum;
    return cur;
}

int get(int node, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return seg[node].sum;
    int mid = (l + r) / 2;
    if (qr <= mid) return get(seg[node].lc, l, mid, ql, qr);
    else if (mid < ql) return get(seg[node].rc, mid + 1, r, ql, qr);
    else return get(seg[node].lc, l, mid, ql, qr) + get(seg[node].rc, mid + 1, r, ql, qr);
}

int n, till[N], cup;
vector<int> add[N];
void init(int Ng, int A[], int B[]) {
    n = Ng;
    for (int i = 0; i < n; i++) {
        add[A[i]].push_back(B[i]);
    }
    till[0] = build(1, n);
    cup = till[0];
    for (int i = 1; i <= n; i++) {
        for (auto& j : add[i])
            cup = update(cup, 1, n, j);
        till[i] = cup;
    }
}

int Contains(int l, int r) {
    return get(till[l], 1, n, r, n);
}

int cnt[N]; // cnt of x
int dp[N];  // dp
int can(int m, int k[]) {
    int sm = 0;
    for (int i = 0; i < m; i++) {
        sm += k[i];
        if (sm > n) {
            // Not Possible
            return 0;
        }
    }
    for (int i = 0; i < m; i++)
        cnt[k[i]]++;
    sort(k, k + m);
    int mp = unique(k, k + m) - k;
    // Here we write the dp solution
    int mi = 1e9;
    for (int i = 0; i < mp; i++) {
        int x = k[i];
        int sz = cnt[x] * x;
        int cntx = Contains(x, x);
        dp[i] = cntx - sz;
        for (int j = i - 1; j >= 0; j--)
            dp[i] = min(dp[i], dp[j] + cntx - Contains(k[j], x) - sz);
        mi = min(mi, dp[i]);
    }
    for (int i = 0; i < mp; i++)
        cnt[k[i]] = 0;
    return (mi >= 0);
}

Compilation message (stderr)

teams.cpp:46:13: error: 'N' was not declared in this scope
   46 | int n, till[N], cup;
      |             ^
teams.cpp:47:17: error: 'N' was not declared in this scope
   47 | vector<int> add[N];
      |                 ^
teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:51:9: error: 'add' was not declared in this scope
   51 |         add[A[i]].push_back(B[i]);
      |         ^~~
teams.cpp:53:5: error: 'till' was not declared in this scope
   53 |     till[0] = build(1, n);
      |     ^~~~
teams.cpp:56:24: error: 'add' was not declared in this scope
   56 |         for (auto& j : add[i])
      |                        ^~~
teams.cpp: In function 'int Contains(int, int)':
teams.cpp:63:16: error: 'till' was not declared in this scope
   63 |     return get(till[l], 1, n, r, n);
      |                ^~~~
teams.cpp: At global scope:
teams.cpp:66:9: error: 'N' was not declared in this scope
   66 | int cnt[N]; // cnt of x
      |         ^
teams.cpp:67:8: error: 'N' was not declared in this scope
   67 | int dp[N];  // dp
      |        ^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:78:9: error: 'cnt' was not declared in this scope; did you mean 'int'?
   78 |         cnt[k[i]]++;
      |         ^~~
      |         int
teams.cpp:80:31: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
   80 |     int mp = unique(k, k + m) - k;
      |              ~~~~~~~~~~~~~~~~~^~~
teams.cpp:85:18: error: 'cnt' was not declared in this scope; did you mean 'int'?
   85 |         int sz = cnt[x] * x;
      |                  ^~~
      |                  int
teams.cpp:87:9: error: 'dp' was not declared in this scope; did you mean 'mp'?
   87 |         dp[i] = cntx - sz;
      |         ^~
      |         mp
teams.cpp:93:9: error: 'cnt' was not declared in this scope; did you mean 'int'?
   93 |         cnt[k[i]] = 0;
      |         ^~~
      |         int