이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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, 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; });
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, int _K[]) {
m = _m;
rep (i, 0, m - 1) K[i] = _K[i];
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
*/
컴파일 시 표준 에러 (stderr) 메시지
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |