# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
727333 |
2023-04-20T12:09:33 Z |
TheSahib |
Teams (IOI15_teams) |
C++17 |
|
2941 ms |
145128 KB |
#include "teams.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int MAX = 5e5 + 5;
const int TREE_SIZE = MAX * 20;
int n;
//vector<pii> v;
int tree[TREE_SIZE], L[TREE_SIZE], R[TREE_SIZE];
int nxt = 0;
int roots[MAX];
void build(int node, int l, int r){
if(l == r) return;
int mid = (l + r) / 2;
L[node] = ++nxt;
R[node] = ++nxt;
build(L[node], l, mid);
build(R[node], mid + 1, r);
}
int update(int node, int l, int r, int pos){
int id = ++nxt;
tree[id] = tree[node] + 1;
if(l == r) return id;
L[id] = L[node];
R[id] = R[node];
int mid = (l + r) >> 1;
if(pos <= mid){
L[id] = update(L[id], l, mid, pos);
}
else{
R[id] = update(R[id], mid + 1, r, pos);
}
return id;
}
int ask(int node, int l, int r, int ql, int qr){
if(ql > r || qr < l){
return 0;
}
if(ql <= l && r <= qr){
return tree[node];
}
int mid = (l + r) >> 1;
return ask(L[node], l, mid, ql, qr) + ask(R[node], mid + 1, r, ql, qr);
}
void init(int N, int A[], int B[])
{
n = N;
vector<int> a[n + 1];
for (int i = 0; i < n; i++)
{
//v.push_back({A[i], B[i]});
a[A[i]].push_back(B[i]);
}
for (int i = 1; i <= n; i++)
{
roots[i] = roots[i - 1];
for(int r:a[i]){
roots[i] = update(roots[i], 1, MAX, r);
}
}
}
int can(int M, int K[])
{
sort(K, K + M);
int s = 0;
vector<pii> v;
for (int i = 0; i < M; i++)
{
if(!v.empty() && v[v.size() - 1].first == K[i]){
v[v.size() - 1].second += K[i];
}
else{
v.push_back({K[i], K[i]});
}
s += K[i];
}
if(s > n) return false;
vector<pii> blocks;
for (int i = 0; i < v.size(); i++)
{
if(!blocks.empty()){
blocks[blocks.size() - 1].second = v[i].first - 1;
}
blocks.push_back({v[i].first, 0});
}
blocks[blocks.size() - 1].second = n;
vector<int> used;
used.resize(blocks.size(), 0);
for (int i = 0; i < v.size(); i++)
{
int need = v[i].second;
for (int j = i; j < blocks.size(); j++)
{
int c = min(ask(roots[v[i].first], 1, MAX, blocks[j].first, blocks[j].second) - used[j], need);
used[j] += c;
need -= c;
if(need == 0) break;
}
if(need != 0) return false;
}
return true;
}
Compilation message
teams.cpp: In function 'int can(int, int*)':
teams.cpp:94:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
teams.cpp:106:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
teams.cpp:109:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (int j = i; j < blocks.size(); j++)
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
29060 KB |
Output is correct |
2 |
Correct |
57 ms |
28952 KB |
Output is correct |
3 |
Correct |
58 ms |
29060 KB |
Output is correct |
4 |
Correct |
62 ms |
29392 KB |
Output is correct |
5 |
Correct |
30 ms |
27884 KB |
Output is correct |
6 |
Correct |
29 ms |
27852 KB |
Output is correct |
7 |
Correct |
30 ms |
27980 KB |
Output is correct |
8 |
Correct |
28 ms |
27852 KB |
Output is correct |
9 |
Correct |
29 ms |
27748 KB |
Output is correct |
10 |
Correct |
28 ms |
27716 KB |
Output is correct |
11 |
Correct |
29 ms |
27748 KB |
Output is correct |
12 |
Correct |
31 ms |
27780 KB |
Output is correct |
13 |
Correct |
34 ms |
28036 KB |
Output is correct |
14 |
Correct |
40 ms |
28244 KB |
Output is correct |
15 |
Correct |
55 ms |
28836 KB |
Output is correct |
16 |
Correct |
54 ms |
28908 KB |
Output is correct |
17 |
Correct |
31 ms |
27984 KB |
Output is correct |
18 |
Correct |
30 ms |
28000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
29064 KB |
Output is correct |
2 |
Correct |
109 ms |
29060 KB |
Output is correct |
3 |
Correct |
191 ms |
30584 KB |
Output is correct |
4 |
Correct |
64 ms |
29040 KB |
Output is correct |
5 |
Correct |
53 ms |
27860 KB |
Output is correct |
6 |
Correct |
51 ms |
27956 KB |
Output is correct |
7 |
Correct |
48 ms |
27880 KB |
Output is correct |
8 |
Correct |
52 ms |
27952 KB |
Output is correct |
9 |
Correct |
29 ms |
27760 KB |
Output is correct |
10 |
Correct |
31 ms |
27716 KB |
Output is correct |
11 |
Correct |
64 ms |
27848 KB |
Output is correct |
12 |
Correct |
1061 ms |
27800 KB |
Output is correct |
13 |
Correct |
279 ms |
28048 KB |
Output is correct |
14 |
Correct |
222 ms |
29444 KB |
Output is correct |
15 |
Correct |
89 ms |
28960 KB |
Output is correct |
16 |
Correct |
84 ms |
28876 KB |
Output is correct |
17 |
Correct |
52 ms |
27860 KB |
Output is correct |
18 |
Correct |
54 ms |
27848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
580 ms |
145100 KB |
Output is correct |
2 |
Correct |
575 ms |
145128 KB |
Output is correct |
3 |
Correct |
826 ms |
144980 KB |
Output is correct |
4 |
Correct |
476 ms |
144208 KB |
Output is correct |
5 |
Correct |
192 ms |
138060 KB |
Output is correct |
6 |
Correct |
190 ms |
138084 KB |
Output is correct |
7 |
Correct |
172 ms |
138092 KB |
Output is correct |
8 |
Correct |
181 ms |
138060 KB |
Output is correct |
9 |
Correct |
140 ms |
137308 KB |
Output is correct |
10 |
Correct |
140 ms |
137416 KB |
Output is correct |
11 |
Correct |
1582 ms |
137340 KB |
Output is correct |
12 |
Correct |
2941 ms |
137412 KB |
Output is correct |
13 |
Correct |
906 ms |
138780 KB |
Output is correct |
14 |
Correct |
830 ms |
142848 KB |
Output is correct |
15 |
Correct |
405 ms |
142480 KB |
Output is correct |
16 |
Correct |
408 ms |
142484 KB |
Output is correct |
17 |
Correct |
200 ms |
137604 KB |
Output is correct |
18 |
Correct |
191 ms |
137784 KB |
Output is correct |