# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
602035 | AmirElarbi | Teams (IOI15_teams) | C++14 | 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 vi vector<int>
#define gi greater<int>
#define gr greater
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e9+7;
const int nax = 2e5+5;
typedef complex<int> Point;
#define X real()
#define Y imag()
//#include "teams.h"
vii s;
int n;
void init(int N, int A[], int B[]) {
n = N;
for (int i = 0; i < N; ++i)
{
s.pb({A[i], B[i]});
}
sort(s.begin(), s.end());
}
int can(int M, int K[]) {
priority_queue<int,vi ,gi> pq;
vii k;
for (int i = 0; i < M; ++i)
{
k.pb({K[i], K[i]});
}
sort(k.begin(), k.end());
int j = 0;
for (int i = 0; i < M; ++i)
{
while(s[j].fi <= k[i].fi){
pq.push(s[i].se);
j++;
}
while(!pq.empty() && pq.top() < k[i].fi){
pq.pop();
}
while(!pq.empty() && pq.top() >= k[i].fi && k[i].se != 0){
pq.pop();
k[i].se--;
}
if(k[i].se) return 0;
}
return 1;
}
static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;
static inline int _read() {
if (_charsNumber < 0) {
exit(1);
}
if (!_charsNumber || _currentChar == _charsNumber) {
_charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile);
_currentChar = 0;
}
if (_charsNumber <= 0) {
return -1;
}
return _buffer[_currentChar++];
}
static inline int _readInt() {
int c, x, s;
c = _read();
while (c <= 32) c = _read();
x = 0;
s = 1;
if (c == '-') {
s = -1;
c = _read();
}
while (c > 32) {
x *= 10;
x += c - '0';
c = _read();
}
if (s < 0) x = -x;
return x;
}
int main() {
_inputFile = fopen("input.txt", "rb");
_outputFile = fopen("output.txt", "w");
int N;
N = _readInt();
int *A = (int*)malloc(sizeof(int)*(unsigned int)N);
int *B = (int*)malloc(sizeof(int)*(unsigned int)N);
for (int i = 0; i < N; ++i) {
A[i] = _readInt();
B[i] = _readInt();
}
init(N, A, B);
int Q;
Q = _readInt();
for (int i = 0; i < Q; ++i) {
int M;
M = _readInt();
int *K = (int*)malloc(sizeof(int)*(unsigned int)M);
for (int j = 0; j < M; ++j) {
K[j] = _readInt();
}
fprintf(_outputFile,"%d\n", can(M, K));
}
return 0;
}