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>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "teams.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 2e5 + 10;
int n;
int root[N];
struct node {
int lhs, rhs;
int cnt;
} st[N * 50];
int nNode = 0;
int add(int id, int L, int R, int i) {
if (L == R) {
st[++nNode] = st[id];
++st[nNode].cnt;
return nNode;
}
int cur = ++nNode;
st[cur] = st[id];
int mid = L + R >> 1;
if (i <= mid) st[cur].lhs = add(st[id].lhs, L, mid, i);
else st[cur].rhs = add(st[id].rhs, mid + 1, R, i);
st[cur].cnt = st[st[cur].lhs].cnt + st[st[cur].rhs].cnt;
return cur;
}
int get(int id, int L, int R, int u, int v) {
if (u > R || L > v) return 0;
if (u <= L && R <= v) return st[id].cnt;
int mid = L + R >> 1;
return get(st[id].lhs, L, mid, u, v) + get(st[id].rhs, mid + 1, R, u, v);
}
void init(int _n, int A[], int B[]) {
n = _n;
vector <vector <int>> s(n + 1);
for (int i = 0; i < n; ++i) s[B[i]].push_back(A[i]);
for (int i = 1; i <= n; ++i) {
int r = root[i - 1];
for (auto val: s[i]) r = add(r, 1, n, val);
root[i] = r;
}
}
int cnt[N];
int can(int m, int x[]) {
map <int, int> mp;
long long tot = 0;
for (int i = 0; i < m; ++i) tot += x[i];
if (tot > n) return 0;
for (int i = 0; i < m; ++i) mp[x[i]] += x[i];
vector <int> List;
for (auto [x, need]: mp) {
List.push_back(x);
}
List.push_back(n + 1);
for (int i = 0; i < List.size() - 1; ++i) cnt[i] = 0;
for (int i = 0; i + 1 < List.size(); ++i) {
int need = mp[List[i]];
for (int j = i; j + 1 < List.size(); ++j) {
// List[j] -> List[j + 1]
int cur = get(root[List[j + 1] - 1], 1, n, 1, List[i]) - get(root[List[j] - 1], 1, n, 1, List[i]);
cur -= cnt[j];
int delta = min(cur, need);
need -= delta;
cnt[j] += delta;
}
if (need != 0) return 0;
}
return 1;
}
Compilation message (stderr)
teams.cpp: In function 'int add(int, int, int, int)':
teams.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | int mid = L + R >> 1;
| ~~^~~
teams.cpp: In function 'int get(int, int, int, int, int)':
teams.cpp:42:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int mid = L + R >> 1;
| ~~^~~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:67:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
67 | for (auto [x, need]: mp) {
| ^
teams.cpp:67:16: warning: declaration of 'auto x' shadows a parameter [-Wshadow]
67 | for (auto [x, need]: mp) {
| ^
teams.cpp:60:20: note: shadowed declaration is here
60 | int can(int m, int x[]) {
| ~~~~^~~
teams.cpp:71:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i = 0; i < List.size() - 1; ++i) cnt[i] = 0;
| ~~^~~~~~~~~~~~~~~~~
teams.cpp:72:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i = 0; i + 1 < List.size(); ++i) {
| ~~~~~~^~~~~~~~~~~~~
teams.cpp:74:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for (int j = i; j + 1 < List.size(); ++j) {
| ~~~~~~^~~~~~~~~~~~~
# | 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... |