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;
#define pb push_back
const int nax=1e5+5;
struct query{
int x,type,r,idx;
bool operator<(const query &o) const{
if(o.x!=x) return x<o.x;
else if(o.type!=type) return type<o.type;
}
};
vector<query> q;
int cnt[nax];
void init(int N, int A[], int B[]) {
for (int i = 0; i < N; ++i)
{
q.pb({A[i],0,B[i],i});
q.pb({B[i],2,B[i],i});
}
}
int can(int M, int K[]){
vector<query> cur=q;
multiset<int> st;
memset(cnt,0,sizeof cnt);
for (int i = 0; i < M; ++i)
{
cur.pb({K[i],1,K[i],i});
}
sort(cur.begin(),cur.end());
bool test=true;
for (int i = 0; i < cur.size(); ++i)
{
//cout <<cur[i].x<<" "<<cur[i].type<<" "<<cur[i].r<<" "<<st.size()<<endl;
if(cur[i].type==0){
st.insert(cur[i].r);
}else if(cur[i].type==1){
int c=0;
for(auto u:st){
if(c==cur[i].r) break;
cnt[u]++;
c++;
}
if(c<cur[i].r){
test=false;
break;
}
c=0;
while(c<cur[i].r){
c++;
st.erase(st.find(*st.begin()));
}
}else{
if(cnt[cur[i].r]>0) cnt[cur[i].r]--;
else st.erase(st.find(cur[i].r));
}
}
return (test ? 1 : 0);
}
/*
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() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int N;
cin>>N;
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) {
cin>>A[i];
cin>>B[i];
}
init(N, A, B);
int Q;
cin>>Q;
for (int i = 0; i < Q; ++i) {
int M;
cin>>M;
int K[M];
for (int j = 0; j < M; ++j) {
cin>>K[j];
}
cout <<can(M, K)<<" ";
}
return 0;
}*/
Compilation message (stderr)
teams.cpp: In function 'int can(int, int*)':
teams.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < cur.size(); ++i)
| ~~^~~~~~~~~~~~
teams.cpp: In member function 'bool query::operator<(const query&) const':
teams.cpp:11:5: warning: control reaches end of non-void function [-Wreturn-type]
11 | }
| ^
# | 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... |