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>
#include "teams.h"
using namespace std;
const int INF = INT32_MAX;
const int batch = 750;
vector<pair<int, int>> arr;
int ST[800005];
void init(int N, int A[], int B[]) {
for(int i = 0; i < N; i++) {
int U = A[i], V = B[i];
arr.push_back({U, V});
}
}
void update(int v, int l, int r, int p, int val) {
if(l == r) {
ST[v] += val;
return;
}
int md = (l + r) / 2;
if(p <= md) update(v * 2, l, (l + r) / 2, p, val);
else update(v * 2 + 1, (l + r) / 2 + 1, r, p, val);
ST[v] = min(ST[v * 2], ST[v * 2 + 1]);
}
int query(int v, int l, int r) {
if(l == r) return l;
if(ST[v * 2] <= ST[v * 2 + 1])
return query(v * 2, l, (l + r) / 2);
return query(v * 2 + 1, (l + r) / 2 + 1, r);
}
int can(int M, int K[]) {
int N = arr.size(); vector<int> adj[N];
vector<int> order(N, 0);
for(int l = 0; l < N; l++) {
order[l] = l;
int U = arr[l].first, V = arr[l].second;
for(int i = 0; i < M; i++)
if(K[i] >= U && K[i] <= V)
adj[l].push_back(i);
}
vector<int> cur(M, 0); int res = 1;
sort(order.begin(), order.end(), [&](int A, int B) { return adj[A].size() < adj[B].size(); });
for(int l = 0; l < N; l++) {
int i = order[l];
for(auto u : adj[i]) {
if(cur[u] < K[u]) { cur[u]++; break; }
}
}
for(int l = 0; l < M; l++)
res &= (cur[l] == K[l]);
///cout << res << "\n";
return res;
}
Compilation message (stderr)
teams.cpp: In function 'int can(int, int*)':
teams.cpp:36:33: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
36 | int N = arr.size(); vector<int> adj[N];
| ~~~~~~~~^~
# | 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... |