QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#416839 | #8711. Tiles | zhoukangyang# | 4 | 56ms | 216408kb | C++14 | 3.9kb | 2024-05-22 09:28:33 | 2024-05-22 09:28:33 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define sz(a) ((int) (a).size())
#define vi vector < int >
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
#define ld __float128
#define pb emplace_back
using namespace std;
const int N = 1e6 + 7;
struct fenwt {
int fen[N];
fenwt() {
me(fen, 0);
}
void add(int p, int w) {
for(; p < N; p += p & -p)
fen[p] += w;
}
inline int query(int p) {
int ret = 0;
for(; p; p -= p & -p) ret += fen[p];
return ret;
}
} F;
map<int,vector<pair<int,int>>>mp;
int n, m;
int x[N], y[N];
int arr[N], tot;
vector<pair<int,vector<pair<int,int>>>>vc;
bool hos[N], occ[N];
int odd[N];
struct pm {
int perm[4];
bool v1[4], v2[4];
pm() {
L(i, 0, 3)perm[i] = i, v1[i] = v2[i] = 0;
}
};
pm operator + (pm a, pm b) {
pm c;
L(i, 0, 3) {
c.perm[i] = b.perm[a.perm[i]];
c.v1[i] = a.v1[i] | b.v1[a.perm[i]];
c.v2[i] = a.v2[i] | b.v2[a.perm[i]];
}
return c;
}
pm seg[N][2][2][2]; // col.rev; val.rev; val.(col.rev)
void upd(int x) {
L(i, 0, 1) L(j, 0, 1) L(k, 0, 1) {
seg[x][i][j][k] = seg[x * 2][i][j][k] + seg[x * 2 + 1][i][j][k];
}
}
struct tag {
int a, b, c;
tag(int A = 0, int B = 0, int C = 0) {
a = A, b = B, c = C;
}
};
tag operator + (tag a, tag b) {
if(!a.a) return tag(a.a ^ b.a, a.b ^ b.b, a.c ^ b.c);
else return tag(a.a ^ b.a, a.b ^ b.c, a.c ^ b.b);
}
tag tg[N];
void adt(int x, tag w) {
if(w.b) L(i, 0, 1) L(k, 0, 1) swap(seg[x][i][0][k], seg[x][i][1][k]);
if(w.c) L(i, 0, 1) L(j, 0, 1) swap(seg[x][i][j][0], seg[x][i][j][1]);
if(w.a) L(j, 0, 1) L(k, 0, 1) swap(seg[x][0][j][k], seg[x][1][k][j]);
tg[x] = tag();
}
void build(int x, int L, int R) {
if(L == R) {
L(i, 0, 1) L(j, 0, 1) L(k, 0, 1) {
int occ = i, hos = k;
L(t, 0, 3) {
int ban = 0;
int hav_one = 0;
int lst = t % 2, var = t / 2;
if(occ) {
if(hos)hav_one = 1;
if(var == 0) lst = hos;
else if(lst != hos) ban = 1;
var ^= 1;
}
if(!occ && hos) {
ban = 1;
}
if(!occ && var) {
ban = 1;
}
auto &s = seg[x][i][j][k];
s.perm[t] = lst + var * 2;
s.v1[t] = ban;
s.v2[t] = hav_one;
}
}
return;
}
int mid = (L + R) >> 1;
build(x * 2, L, mid), build(x * 2 + 1, mid + 1, R);
upd(x);
}
void push(int x) {
adt(x * 2, tg[x]);
adt(x * 2 + 1, tg[x]);
tg[x] = tag();
}
void cov(int x, int L, int R, int l, int r, tag w) {
if(l <= L && R <= r) {
adt(x, w);
return;
}
push(x);
int mid = (L + R) >> 1;
if(l <= mid) cov(x * 2, L, mid, l, r, w);
if(r > mid) cov(x * 2 + 1, mid + 1, R, l, r, w);
upd(x);
}
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
L(i, 1, n) {
cin >> x[i] >> y[i];
++y[i];
arr[++tot] = y[i];
arr[++tot] = y[i] ^ 1;
arr[++tot] = y[i] + 2;
arr[++tot] = (y[i] ^ 1) + 2;
}
sort(arr + 1, arr + tot + 1);
tot = unique(arr + 1, arr + tot + 1) - arr - 1;
L(i, 1, n) {
y[i] = lower_bound(arr + 1, arr + tot + 1, y[i]) - arr;
}
L(i, 1, n) {
int nxt = i % n + 1;
if(x[nxt] == x[i]) {
mp[x[i]].pb(min(y[i], y[nxt]), max(y[i], y[nxt]));
}
}
for(auto&u : mp) {
vc.pb(u);
}
build(1, 1, tot);
int ns = 0;
L(i, 0, sz(vc) - 2) {
int len = vc[i + 1].first - vc[i].first;
if(len >= 3) len = len % 2 + 2;
sort(vc[i].second.begin(), vc[i].second.end());
for(auto&it : vc[i].second)
cov(1, 1, tot, it.first + 1, it.second, tag(1, 0, 0));
L(t, 1, len) {
cov(1, 1, tot, 1, tot, tag(0, 1, 0));
auto dt = seg[1][0][0][0];
int ban = dt.v1[0];
int hav_one = dt.v2[0];
int lst = dt.perm[0] % 2, var = dt.perm[0] / 2;
if(var)ban = 1;
if(ban) {
cout << ns << '\n';
return 0;
}
if(!hav_one) {
ns = max(ns, vc[i + 1].first - len + t);
}
}
}
cout << ns << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 4ms
memory: 209084kb
input:
4 3 0 0 0 3 3 3 3 0
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 4ms
memory: 209376kb
input:
4 999999999 999999999 0 999999999 1000000000 0 1000000000 0 0
output:
999999998
result:
ok single line: '999999998'
Test #3:
score: 0
Accepted
time: 12ms
memory: 209124kb
input:
4 875 875 0 0 0 0 284 875 284
output:
874
result:
ok single line: '874'
Test #4:
score: 0
Accepted
time: 16ms
memory: 209664kb
input:
4 317 317 0 317 920 0 920 0 0
output:
316
result:
ok single line: '316'
Test #5:
score: 0
Accepted
time: 16ms
memory: 210372kb
input:
4 912 912 814 912 0 0 0 0 814
output:
912
result:
ok single line: '912'
Test #6:
score: 0
Accepted
time: 7ms
memory: 210044kb
input:
4 2 0 0 0 1 2 1 2 0
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 3ms
memory: 208952kb
input:
4 1 0 0 0 1 1 1 1 0
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 12ms
memory: 210256kb
input:
4 412 412 998 0 998 0 17 412 17
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 8ms
memory: 210320kb
input:
4 87523458 87523458 42385699 0 42385699 0 23498231 87523458 23498231
output:
87523458
result:
ok single line: '87523458'
Test #10:
score: 0
Accepted
time: 18ms
memory: 208948kb
input:
4 1 0 0 0 1000000000 1 1000000000 1 0
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 15ms
memory: 209724kb
input:
4 1000000000 1000000000 0 1000000000 1000000000 0 1000000000 0 0
output:
1000000000
result:
ok single line: '1000000000'
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #12:
score: 9
Accepted
time: 12ms
memory: 209812kb
input:
5 29034873 29034873 13721 0 13721 0 99198237 29034870 99198237 29034873 99198237
output:
29034872
result:
ok single line: '29034872'
Test #13:
score: 0
Accepted
time: 3ms
memory: 209016kb
input:
6 999999993 2934870 21349 2934870 3423847 0 3423847 0 91827393 999999993 91827393 999999993 21349
output:
999999992
result:
ok single line: '999999992'
Test #14:
score: -9
Wrong Answer
time: 15ms
memory: 210468kb
input:
6 401 153 409 153 751 0 751 0 909 401 909 401 409
output:
401
result:
wrong answer 1st lines differ - expected: '152', found: '401'
Subtask #3:
score: 0
Wrong Answer
Test #32:
score: 0
Wrong Answer
time: 7ms
memory: 210380kb
input:
1551 1000 0 988 2 988 3 988 6 988 6 985 6 982 6 981 6 979 6 978 6 977 6 976 6 975 6 974 6 972 6 970 6 969 6 968 6 966 6 965 6 964 7 964 8 964 8 963 8 961 8 960 10 960 11 960 13 960 16 960 16 959 16 958 16 957 16 954 16 953 16 951 16 950 17 950 18 950 18 948 18 946 18 945 18 944 18 942 18 941 18 939 ...
output:
6
result:
wrong answer 1st lines differ - expected: '164', found: '6'
Subtask #4:
score: 0
Wrong Answer
Test #45:
score: 19
Accepted
time: 4ms
memory: 209820kb
input:
14 6 0 1 0 3 2 3 2 4 0 4 0 6 3 6 3 7 4 7 6 7 6 5 3 5 3 2 3 1
output:
2
result:
ok single line: '2'
Test #46:
score: 0
Accepted
time: 15ms
memory: 210896kb
input:
18 9 0 2 2 2 2 1 4 1 4 0 9 0 9 2 4 2 4 4 7 4 7 3 9 3 9 6 4 6 4 5 2 5 2 4 0 4
output:
6
result:
ok single line: '6'
Test #47:
score: -19
Wrong Answer
time: 56ms
memory: 215744kb
input:
199996 966 752 702 754 702 754 700 756 700 756 702 758 702 758 700 760 700 760 702 762 702 762 700 764 700 764 702 766 702 766 700 768 700 768 702 770 702 770 700 772 700 772 702 774 702 774 700 776 700 776 702 778 702 778 700 780 700 780 702 782 702 782 700 784 700 784 702 786 702 786 700 788 700 7...
output:
6
result:
wrong answer 1st lines differ - expected: '0', found: '6'
Subtask #5:
score: 0
Wrong Answer
Test #89:
score: 0
Wrong Answer
time: 40ms
memory: 216408kb
input:
199996 198506138 31225688 248200160 31225688 248291950 28995282 248291950 28995282 248200160 26764876 248200160 26764876 248291950 24534470 248291950 24534470 248200160 22304064 248200160 22304064 248291950 20073658 248291950 20073658 248200160 17843252 248200160 17843252 248291950 15612846 24829195...
output:
3
result:
wrong answer 1st lines differ - expected: '0', found: '3'
Subtask #6:
score: 0
Runtime Error
Test #118:
score: 0
Runtime Error
input:
200000 1000000000 1000000000 0 999990876 0 999990876 38 999972524 38 999972524 1510 999969180 1510 999969180 3734 999964780 3734 999964780 4138 999960464 4138 999960464 11052 999953728 11052 999953728 24478 999914972 24478 999914972 25892 999909864 25892 999909864 28102 999902920 28102 999902920 301...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%