이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <robots.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (ll i=(a); i >= b; i--)
#define MN 1000005
int n, m, t;
pii coo[MN];
int vert[MN];
int horiz[MN];
map<int, int> vcmp, hcmp;
int tim1, tim2;
ll tree[2*MN]; //range modify, store global min
ll lazy[2*MN];
void upd(int node, int a, int b, int i, int j, ll val){
if(lazy[node] != 0){
tree[node] += lazy[node];
if(a != b){
lazy[node*2] += lazy[node];
lazy[node*2+1] += lazy[node];
}
lazy[node] = 0;
}
if(a > j || b < i) return;
if(i <= a && b <= j){
tree[node] += val;
if(a != b){
lazy[node*2] += val;
lazy[node*2+1] += val;
}
return;
}
int mid = (a+b)/2;
upd(node*2, a, mid, i, j, val);
upd(node*2+1, 1+mid, b, i, j, val);
tree[node] = min(tree[node*2], tree[node*2+1]);
}
void pr(int node, int a, int b){
cout << node << " " << a << " " << b << " " << tree[node] << " " << lazy[node] << "\n";
if(a == b) return;
pr(node*2, a, (a+b)/2);
pr(node*2+1, 1+(a+b)/2, b);
}
bool chk(int x){
//cout << "checking " << x << "\n";
//cout << "tim2 " << tim2 << "\n";
memset(tree, 0, sizeof tree);
memset(lazy, 0, sizeof lazy);
F0R(i, m){
//cout << "upd 1 " << horiz[i] << " " << x << "\n";
upd(1, 1, tim2+1, 1, horiz[i], x);
}
//pr(1, 1, tim2+1);
int cur = t-1;
RFOR(i, n-1, 0){
while(cur >= 0 && coo[cur].f > vert[i]){
//cout << "upd " << coo[cur].s << " " << coo[cur].s << " -1\n";
upd(1, 1, tim2+1, 1, coo[cur].s, -1);
--cur;
}
//pr(1, 1, tim2+1);
if(tree[1] < 0) return false;
//cout << "upd 1 " << tim2+1 << " " << x << "\n";
upd(1, 1, tim2+1, 1, tim2+1, x);
}
while(cur >= 0){
//cout << "upd " << coo[cur].s << " " << coo[cur].s << " -1\n";
upd(1, 1, tim2+1, 1, coo[cur].s, -1);
--cur;
}
if(tree[1] < 0) return false;
return true;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]){
n = A; m = B; t = T;
F0R(i, n){
vert[i] = X[i]-1;
vcmp[vert[i]] = 0;
}
F0R(i, m){
horiz[i] = Y[i]-1;
hcmp[horiz[i]] = 0;
}
//int tim1 = 0;
for(auto &u : vcmp) u.s = ++tim1;
//int tim2 = 0;
for(auto &u : hcmp) u.s = ++tim2;
F0R(i, n)
vert[i] = vcmp[vert[i]];
F0R(i, m)
horiz[i] = hcmp[horiz[i]];
F0R(i, t){
//cout << "doing " << i << "\n";
if(vcmp.lower_bound(W[i]) == vcmp.end()) coo[i].f = tim1+1;
else coo[i].f = vcmp.lower_bound(W[i])->s;
if(hcmp.lower_bound(S[i]) == hcmp.end()) coo[i].s = tim2+1;
else coo[i].s = hcmp.lower_bound(S[i])->s;
if(coo[i].f == tim1+1 && coo[i].s == tim2+1) return -1;
//cout << coo[i].f << " " << coo[i].s << "\n";
}
sort(vert, vert+n);
sort(coo, coo+t);
//F0R(i, t) cout << coo[i].f << " " << coo[i].s << "\n";
int l = 0, r = t;
while(l+1 < r){
int mid = (l+r)/2;
if(chk(mid)){
r = mid;
} else{
l = mid;
}
}
return r;
}
/*int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int A, B, T;
cin >> A >> B >> T;
int X[A], Y[B], W[T], S[T];
F0R(i, A) cin >> X[i];
F0R(i, B) cin >> Y[i];
F0R(i, T) cin >> W[i] >> S[i];
cout << putaway(A, B, T, X, Y, W, S) << "\n";
return 0;
}*/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |