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 "teams.h"
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
const int maxn = 5e5 + 5;
int n;
vector<int> tree[maxn];
vector<int>::iterator used[maxn];
int pos[maxn];
void add(int x, int y) {
while(x<=n) {
tree[x].push_back(y);
x += x&-x;
}
}
int query(int x, int y) {
int res = 0;
while(x>0) {
if(!tree[x].empty()) {
auto it = --upper_bound(all(tree[x]), y);
res += it - used[x];
}
x -= x&-x;
}
return res;
}
void change(int x, int y) {
while(x>0) {
if(!tree[x].empty()) used[x] = --upper_bound(all(tree[x]), y);
x -= x&-x;
}
}
void reset(int x) {
while(x>0) {
used[x] = --tree[x].begin();
x -= x&-x;
}
}
void init(int N, int A[], int B[]) {
n = N;
for(int i=0;i<n;i++) add(A[i],B[i]);
for(int i=1;i<=n;i++) {
used[i] = --tree[i].begin();
sort(all(tree[i]));
}
}
int can(int m, int K[]) {
int res = 1;
sort(K, K+m);
for(int i=0;i<m;i++) {
int l = 1, r = n, mid; pos[i] = -1;
while(l<=r) {
mid = (l+r)/2;
if(query(K[i],mid) >= K[i]) {
pos[i] = mid;
r = mid-1;
}
else l = mid+1;
}
if(pos[i]==-1) res = 0;
change(K[i], pos[i]);
}
for(int i=0;i<m;i++) reset(K[i]);
return res;
}
Compilation message (stderr)
teams.cpp: In function 'int query(int, int)':
teams.cpp:26:17: warning: conversion to 'int' from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type {aka long int}' may alter its value [-Wconversion]
res += it - used[x];
^
# | 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... |