이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*input
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
namespace my_template {
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;
template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }
template<typename T>
void print(vector<T> vec, string name = "") {
cout << name;
for (auto u : vec)
cout << u << ' ';
cout << '\n';
}
}
using namespace my_template;
const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
typedef tree <
pi,
null_type,
less<pi>,
rb_tree_tag,
tree_order_statistics_node_update >
ordered_set;
vpi convert(int N, int C, int *S, int *E) {
ordered_set curr;
vpi queries;
for (int i = 0; i < N; ++i)
curr.insert({i, i});
for (int i = 0; i < C; ++i)
{
auto prad = curr.find_by_order(S[i]);
pi p;
p.x = (*prad).x;
for (int j = 0; j < E[i] - S[i]; ++j)
{
auto nxt = next(prad);
curr.erase(prad);
prad = nxt;
}
p.y = (*prad).y;
curr.erase(prad);
curr.insert(p);
queries.push_back(p);
}
return queries;
}
struct max_seg {
int l, r;
int did;
max_seg *left = nullptr;
max_seg *right = nullptr;
max_seg(int a, int b, int *K): l(a), r(b) {
if (l == r) {
did = K[l];
} else {
left = new max_seg(l, (l + r) / 2, K);
right = new max_seg((l + r) / 2 + 1, r, K);
did = max(left->did, right->did);
}
}
int get(int a, int b) {
if (r < a or b < l) return -MOD;
else if (a <= l and r <= b) return did;
else
return max(left->get(a, b), right->get(a, b));
}
};
struct node {
int l, r;
int did;
int lazy;
node *left = nullptr;
node *right = nullptr;
node(int a, int b): l(a), r(b), did(0), lazy(0) {
if (l != r) {
left = new node(l, (l + r) / 2);
right = new node((l + r) / 2 + 1, r);
}
}
inline void push() {
if (left) left->lazy += lazy;
if (right) right->lazy += lazy;
did += lazy;
lazy = 0;
}
void add(int a, int b, int val) {
push();
if (r < a or b < l) return;
else if (a <= l and r <= b) {
lazy += val;
push();
} else {
left->add(a, b, val);
right->add(a, b, val);
left->push();
right->push();
did = max(left->did, right->did);
}
}
};
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
vpi queries = convert(N, C, S, E);
// for (auto u : queries)
// printf("%d %d\n", u.x, u.y);
int ats = 0;
max_seg maxS(0, N - 2, K);
node med(0, N - 1);
for (int i = 0; i < C; ++i)
{
int s = queries[i].x;
int e = queries[i].y;
int d = maxS.get(s, e - 1);
// printf("s = %d, e = %d, d = %d, R = %d\n", s, e, d, R);
if (d > R)
med.add(s, e, -1e6);
else
med.add(s, e, 1);
ats = max(ats, med.did);
}
return ats;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |