Submission #1110978

# Submission time Handle Problem Language Result Execution time Memory
1110978 2024-11-11T08:27:39 Z underwaterkillerwhale Teams (IOI15_teams) C++17
21 / 100
1580 ms 375072 KB
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define REB(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 5e5 + 7;
const int Mod = 1e9 + 7;///lon
const ll INF = 1e18 + 7;
const int BASE = 137;
const int szBL = 350;

int n, Q, m;
pii seg[N], seg2[N];
vector<int> K;

struct Node {
    Node *lc, *rc;
    int val;

    Node (int _val = 0) {
        lc = rc = NULL;
        val = _val;
    }
    Node (Node *L, Node *R) {
        lc = L;
        rc = R;
        val = 0;
        if (lc) val += lc->val;
        if (rc) val += rc->val;
    }
}*Ver[N];

struct Persistent_Segment_Tree {
    int m;
    int num_Ver;
    Node *root[N];

    Node *build (int l, int r) {
        if (l == r) {
            return new Node();
        }
        int mid = l + r >> 1;
        return new Node(build (l, mid), build (mid + 1, r));
    }
    Node *init (int n) {
        m = n;
        return root[0] = build (1, m);
    }
    Node *update (Node *cur, int l, int r, int pos, int val) {
        if (l == r) {
            return new Node (cur->val + val);
        }
        int mid = l + r >> 1;
        if (pos <= mid) return new Node (update (cur->lc, l, mid, pos, val), cur->rc);
        else return new Node (cur->lc, update (cur->rc, mid + 1, r, pos, val));
    }
    int get (Node *cur, int l, int r, int u, int v) {
        if (l > v || r < u) return 0;
        if (l >= u && r <= v) return cur->val;
        int mid = l + r >> 1;
        return get (cur->lc, l, mid, u, v) + get (cur->rc, mid + 1, r, u, v);
    }
    Node *update (int pos, int val) {
        ++num_Ver;
        return root[num_Ver] = update (root[num_Ver - 1], 1, m, pos, val);
    }
    int get (int req, int u, int v) { ///get các version mà chỉ có các con Y <= req
        return get(Ver[req], 1, m, u, v);
    }
}ST;

void init (int _n, int _A[], int _B[]) {
    n = _n;
    rep (i, 1, n) seg[i].fs = _A[i - 1], seg[i].se = _B[i - 1];
    Ver[0] = ST.init(n);
    sort (seg + 1, seg + 1 + n, [] (pii A, pii B) { return A.se < B.se; });
    rep (i, 1, n) seg2[i] = seg[i];
    sort (seg2 + 1, seg2 + 1 + n, [] (pii A, pii B) { return A.fs <B.fs; });
    int ptr = 1;
    rep (i, 1, n) {
        while (ptr <= n && seg[ptr].se < i) ++ptr;
        Ver[i] = Ver[i - 1];
        while (ptr <= n && seg[ptr].se == i) {
            Ver[i] = ST.update (seg[ptr].fs, 1);
            ++ptr;
        }
    }
}

bool process () {
    sort (ALL(K));
    vector<int> rem(m + 3, 0); {
        rep (i, 0, m - 1) rem[i] = K[i];
    }
    K.pb(n + 1);
    rep (i, 0, m - 1) {
        int L = K[i], R = K[i + 1] - 1;
        int cur_rem = 0;
        rep (j, 0, i) {
            int delta = ST.get(R, 1, K[j]) - ST.get(L - 1, 1, K[j]) - cur_rem;
            cur_rem += min(rem[j], delta);
//            cout << j <<" "<<i<< " "<<L<<" "<<R<<" "<<K[j]<<" "<<ST.get(R, 1, K[j]) <<"\n";
            if (delta >= rem[j]) rem[j] = 0;
            else rem[j] -= delta;
        }
    }
//    rep (i, 0, m - 1) cout << rem[i] <<"\n";
    rep (i, 0, m - 1) if (rem[i] != 0) return 0;
    return 1;
}
bool process2 () {
    sort (ALL(K));
    priority_queue<int, vector<int>, greater<int>> pq;
    int ptr = 1;
    rep (i, 0, m - 1) {
        while (ptr <= n && seg2[ptr].fs <= K[i]) {
            if (seg2[ptr].se >= K[i]) pq.push(seg2[ptr].se);
            ++ptr;
        }
        while (K[i] > 0 && !pq.empty()) {
            int u = pq.top();
            pq.pop();
            if (u >= i) --K[i];
        }
        if (K[i] != 0) return 0;
    }
    return 1;
}
bool can (int _m, int _K[]) {
    m = _m;
    K.resize(m);
    rep (i, 0, m - 1) K[i] = _K[i];
    if (m <= szBL) return process();
    else return process2 ();
}


//#define file(name) if(fopen(name".inp","r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
//main () {
//    init(4, {2, 1, 2, 2}, {4, 2, 3, 3});
////    cout << ST.get(2, 1, 1) <<" asd\n";
//    cout << can(2, {1, 3}) <<"\n";
//    return 0;
////    file("c");
//    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
//    int num_Test = 1;
//    cin >> num_Test;
//    while (num_Test--) {
//        process();
//    }
//}
/*
onepunch +25

chắt lọc thông tin để mô hình
cận trên dưới
*/

Compilation message

teams.cpp: In member function 'Node* Persistent_Segment_Tree::build(int, int)':
teams.cpp:57:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |         int mid = l + r >> 1;
      |                   ~~^~~
teams.cpp: In member function 'Node* Persistent_Segment_Tree::init(int)':
teams.cpp:60:21: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   60 |     Node *init (int n) {
      |                 ~~~~^
teams.cpp:27:5: note: shadowed declaration is here
   27 | int n, Q, m;
      |     ^
teams.cpp: In member function 'Node* Persistent_Segment_Tree::update(Node*, int, int, int, int)':
teams.cpp:68:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   68 |         int mid = l + r >> 1;
      |                   ~~^~~
teams.cpp: In member function 'int Persistent_Segment_Tree::get(Node*, int, int, int, int)':
teams.cpp:75:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   75 |         int mid = l + r >> 1;
      |                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6648 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 2 ms 6648 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 4 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 2 ms 6480 KB Output is correct
16 Correct 2 ms 6480 KB Output is correct
17 Correct 2 ms 6616 KB Output is correct
18 Correct 2 ms 6480 KB Output is correct
19 Correct 2 ms 6652 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 2 ms 6648 KB Output is correct
22 Correct 2 ms 6480 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
24 Correct 2 ms 6528 KB Output is correct
25 Correct 2 ms 6480 KB Output is correct
26 Correct 1 ms 6480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 72528 KB Output is correct
2 Correct 138 ms 72520 KB Output is correct
3 Correct 127 ms 72532 KB Output is correct
4 Correct 124 ms 73284 KB Output is correct
5 Correct 82 ms 72520 KB Output is correct
6 Correct 97 ms 73288 KB Output is correct
7 Incorrect 90 ms 75088 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 139 ms 74568 KB Output is correct
2 Correct 774 ms 77640 KB Output is correct
3 Correct 228 ms 77644 KB Output is correct
4 Correct 135 ms 75080 KB Output is correct
5 Correct 317 ms 77128 KB Output is correct
6 Correct 908 ms 75848 KB Output is correct
7 Incorrect 307 ms 75848 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 828 ms 364360 KB Output is correct
2 Correct 952 ms 368104 KB Output is correct
3 Correct 1098 ms 375072 KB Output is correct
4 Correct 907 ms 372184 KB Output is correct
5 Correct 1508 ms 369060 KB Output is correct
6 Correct 1443 ms 368968 KB Output is correct
7 Incorrect 1580 ms 369108 KB Output isn't correct
8 Halted 0 ms 0 KB -