#include "seats.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
random_device(rd);
mt19937 rng(rd());
const long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
struct custom_hash
{
template<class T>
unsigned long long operator()(T v) const
{
unsigned long long x = v;
x += FIXED_RANDOM; x += 11400714819323198485ull;
x = (x ^ (x >> 30)) * 13787848793156543929ull;
x = (x ^ (x >> 27)) * 10723151780598845931ull;
return x ^ (x >> 31);
}
};
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class U> using hash_table = gp_hash_table<T, U, custom_hash>;
template<class T>
void ckmin(T &a, T b)
{
a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
a = max(a, b);
}
long long expo(long long a, long long e, long long mod)
{
return ((e == 0) ? 1 : ((expo(a * a % mod, e >> 1, mod)) * ((e & 1) ? a : 1) % mod));
}
template<class T, class U>
T nmod(T &x, U mod)
{
if (x >= mod) x -= mod;
}
template<class T>
T gcd(T a, T b)
{
return (b ? gcd(b, a % b) : a);
}
template<class T>
T randomize(T mod)
{
return (uniform_int_distribution<T>(0, mod - 1))(rng);
}
#define y0 ___y0
#define y1 ___y1
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define debug(x) cerr << #x << " = " << x << endl;
#define sz(x) ((int) (x.size()))
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-9;
#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 1000013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
int N, M;
int coor[MAXN];
int arr[MAXN];
struct segtree
{
int mins[3 * MAXN], sum[3 * MAXN];
int lazy[3 * MAXN];
pii comb(pii a, pii b)
{
pii res = MP(0, 0);
if (a.fi <= b.fi)
{
res.fi = a.fi;
res.se += a.se;
}
if (a.fi >= b.fi)
{
res.fi = b.fi;
res.se += b.se;
}
return res;
}
void build(int w, int L, int R)
{
lazy[w] = 0;
mins[w] = 0;
sum[w] = 1;
if (L == R) return;
int mid = (L + R) >> 1;
build(w << 1, L, mid);
build(w << 1 | 1, mid + 1, R);
sum[w] = sum[w << 1] + sum[w << 1 | 1];
}
void push(int w, int L, int R)
{
mins[w] += lazy[w];
if (L != R)
{
lazy[w << 1] += lazy[w];
lazy[w << 1 | 1] += lazy[w];
}
lazy[w] = 0;
}
void update(int w, int L, int R, int a, int b, int v)
{
push(w, L, R);
if (b < L || R < a) return;
if (a <= L && R <= b)
{
lazy[w] += v;
push(w, L, R);
return;
}
int mid = (L + R) >> 1;
update(w << 1, L, mid, a, b, v);
update(w << 1 | 1, mid + 1, R, a, b, v);
tie(mins[w], sum[w]) = comb(MP(mins[w << 1], sum[w << 1]), MP(mins[w << 1 | 1], sum[w << 1 | 1]));
}
pii query(int w, int L, int R, int a, int b)
{
push(w, L, R);
if (b < L || R < a) return MP(INF, 0);
// cerr << L << ' ' << R << ' ' << mins[w] << ' ' << sum[w] << endl;
if (a <= L && R <= b)
{
return MP(mins[w], sum[w]);
}
int mid = (L + R) >> 1;
pii lq = query(w << 1, L, mid, a, b), rq = query(w << 1 | 1, mid + 1, R, a, b);
return comb(lq, rq);
}
};
segtree seg;
void give_initial_chart(int h, int w, vector<int> R, vector<int> C)
{
N = h;
M = w;
// cerr << "what the\n";
for (int i = 0; i < M; i++)
{
coor[i] = C[i];
}
for (int i = 0; i < M; i++)
{
arr[coor[i]] = i;
}
seg.build(1, 0, M - 1);
for (int i = 0; i < M; i++)
{
seg.update(1, 0, M - 1, i, i, i);
}
for (int i = 1; i < M; i++)
{
seg.update(1, 0, M - 1, max(arr[i - 1], arr[i]), M - 1, -1);
}
// cerr << seg.query(1, 0, M - 1, 0, M - 1).se << endl;
// cerr << "wtf\n";
//for each range (L, R), you want to store: (size of range) (# of edges entirely in this range) and if it's -1, you win
//this is great, but what do you delete an edge?
}
int swap_seats(int a, int b)
{
//remove the edge a => a + 1
//remove the edge b => b + 1
//delete (a, a + 1)
if (coor[a] > coor[b]) swap(a, b);
if (coor[a] != 0)
{
seg.update(1, 0, M - 1, max(arr[coor[a] - 1], a), M - 1, 1);
}
seg.update(1, 0, M - 1, max(arr[coor[a] + 1], a), M - 1, 1);
seg.update(1, 0, M - 1, max(arr[coor[b] + 1], b), M - 1, 1);
if (coor[b] != M - 1)
{
seg.update(1, 0, M - 1, max(arr[coor[b] - 1], b), M - 1, 1);
}
swap(coor[a], coor[b]);
swap(arr[coor[a]], arr[coor[b]]);
swap(a, b);
if (coor[a] != 0)
{
seg.update(1, 0, M - 1, max(arr[coor[a] - 1], a), M - 1, -1);
}
seg.update(1, 0, M - 1, max(arr[coor[a] + 1], a), M - 1, -1);
seg.update(1, 0, M - 1, max(arr[coor[b] + 1], b), M - 1, -1);
if (coor[b] != M - 1)
{
seg.update(1, 0, M - 1, max(arr[coor[b] - 1], b), M - 1, -1);
}
return (seg.query(1, 0, M - 1, 0, M - 1).se);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
325 ms |
16124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
16124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
16124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |