# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1110968 | underwaterkillerwhale | Teams (IOI15_teams) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
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, vector<int> _A, vector<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; });
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 can (int _m, vector<int> _K) {
m = _m;
K = _K;
return process ();
}
//#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";
//// return 0;
//// cout << can(2, {1, 1}) <<"\n";
//// 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
*/