이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "seats.h"
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1<<20;
int n, val = 4, m, nm;
int drz[2 * N], il[2 * N], laz[2 * N];
vector<int> tab[N];
pair<int, int> wh[N];
void Change(int v, int p, int k, int pz, int kz, int x)
{
if(p > kz || k < pz) return;
if(p >= pz && k <= kz)
{
drz[v] += x; laz[v] += x;
return;
}
int m = (p + k) / 2;
Change(v * 2, p, m, pz, kz, x);
Change(v * 2 + 1, m + 1, k, pz, kz, x);
drz[v] = min(drz[v * 2], drz[v * 2 + 1]); il[v] = 0;
if(drz[v] == drz[v * 2]) il[v] += il[v * 2];
if(drz[v] == drz[v * 2 + 1]) il[v] += il[v * 2 + 1];
drz[v] += laz[v];
}
inline void CH(int a, int b, int x)
{if(a <= b) Change(1, 0, N - 1, a, b, x);}
inline void HN(vector<vector<int>> v, int x)
{
if(v[0][0] > v[1][1]) swap(v[0][0], v[1][1]);
if(v[0][1] > v[1][0]) swap(v[0][1], v[1][0]);
if(v[0][1] < v[0][0])
{swap(v[0][0], v[0][1]); swap(v[1][0], v[1][1]);}
//cout << "\n" << v[0][0] << " " << v[0][1] << "\n";
//cout << v[1][0] << " " << v[1][1] << "\n";
CH(v[0][0], min(v[0][1], v[1][1]) - 1, x);
CH(min(v[1][1], v[1][0]), max(v[1][1], v[1][0]) - 1, x * 5);
}
inline void HLP(pair<int, int> a, int d)
{
vector<int> x(2, 0); vector<vector<int>> v(2, x);
for(int i = a.st - 1; i <= a.st; ++i)
for(int j = a.nd - 1; j <= a.nd; ++j)
{
v[0][0] = tab[i][j]; v[0][1] = tab[i][j + 1]; v[1][0] = tab[i + 1][j]; v[1][1] = tab[i + 1][j + 1];
HN(v, d);
}
}
void Query(int a, int b)
{
++a; ++b;
pair<int, int> x = wh[a], y = wh[b];
HLP(x, -1); HLP(y, -1);
swap(tab[x.st][x.nd], tab[y.st][y.nd]);
wh[a] = y; wh[b] = x;
HLP(x, 1); HLP(y, 1);
}
int Ans()
{
int ans = 0;
if(drz[1] == val) ans += il[1];
return ans;
}
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C)
{
n = H; m = W; nm = n * m; vector<int> p1(m + 5, 0), p2(m + 5, nm + 10);
p1[0] = nm + 10; p1[m + 1] = nm + 10; tab[0] = p2; tab[n + 1] = p2;
for(int i = 1; i <= n; ++i) tab[i] = p1;
for(int i = N; i < 2 * N; ++i) il[i] = 1;
drz[N] = N; for(int i = N + nm + 1; i < 2 * N; ++i) drz[i] = N;
for(int v = N - 1; v > 0; --v)
{
drz[v] = min(drz[v * 2], drz[v * 2 + 1]);
if(drz[v] == drz[v * 2]) il[v] += il[v * 2];
if(drz[v] == drz[v * 2 + 1]) il[v] += il[v * 2 + 1];
}
for(int i = 1; i <= nm; ++i)
{
tab[R[i - 1] + 1][C[i - 1] + 1] = i;
wh[i] = make_pair(R[i - 1] + 1, C[i - 1] + 1);
}
vector<int> x(2, 0); vector<vector<int>> v(2, x);
for(int i = 0; i <= n; ++i)
{
for(int j = 0; j <= m; ++j)
{
v[0][0] = tab[i][j]; v[0][1] = tab[i][j + 1]; v[1][0] = tab[i + 1][j]; v[1][1] = tab[i + 1][j + 1];
HN(v, 1);
}
}
//cout << "XD " << Ans() << "\n";
}
int swap_seats(int a, int b)
{
Query(a, b);
return Ans();
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |