QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#51663 | #4887. Fast Bridges | zhoukangyang# | WA | 3ms | 4712kb | C++11 | 5.0kb | 2022-10-03 12:26:33 | 2022-10-03 12:26:34 |
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 ull unsigned long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
using namespace std;
const int N = 507, mod = 998244353, iv3 = (mod + 1) / 3;
int n, k;
struct tup {
int xl, xr, yl, yr;
} f[N];
struct vec {
int x, y;
};
//int a[N];
//unsigned long long A[64];
//unsigned long long cur;
//inline int lst(int x) {
// int bk = x >> 6, t = x & 63;
// ull o = A[bk] & ((1ull << (t + 1)) - 1);
// if(o) return 63 - __builtin_clzll(o) + (bk << 6);
// ull G = cur & ((1ull << bk) - 1);
// if(!G) return 0;
// int c = 63 - __builtin_clzll(G);
// return (63 - __builtin_clzll(A[c])) + (c << 6);
//}
//inline int nxt(int x) {
// int bk = x >> 6, t = x & 63;
// ull o = A[bk] >> t;
// if(o) return __builtin_ctzll(o) + (bk << 6) + t;
// ull G = cur >> (bk + 1);
// if(!G) return 0;
// int c = __builtin_ctzll(G) + bk + 1;
// return __builtin_ctzll(A[c]) + (c << 6);
//}
//void init() {
// me(a, 0x3f), me(A, 0), cur = 0, me(vis, 0);
//}
//void ins(int x) {
// int bk = x >> 6, t = x & 63;
// A[bk] |= 1ull << t, cur |= 1ull << bk;
// vis[x] = true;
//}
//void del(int x) {
// int bk = x >> 6, t = x & 63;
// if(A[bk] >> t & 1) A[bk] ^= 1ull << t;
// if(!A[bk] && (cur >> bk & 1)) cur ^= 1ull << bk;
// vis[x] = false;
//}
//void insert(int x, int w) {
// a[x] = min(a[x], w);
// if(!vis[x]) {
// int u = nxt(x);
// if(u <= n && a[u] <= a[x]) return ;
// ins(x);
// }
// while(true) {
// int u = lst(x - 1);
// if(!u || a[u] < a[x]) return ;
// del(u), a[u] = 1e9;
// }
//}
int dis[N][N];
int arrx[N], arry[N], atotx, atoty;
bool vis[N];
int t[N];
vi gp[N], st[N];
int haha[N], xl[N], yl[N];
vector < int > id[N];
int arr[N], atot;
int a[10][10][10][10];
int work(vector < pair < int, int > > vp) {
L(i, 1, n) vis[i] = false, gp[i].clear();
for(auto u : vp) vis[u.first] = true, gp[u.first].emplace_back(u.second);
atotx = atoty = 0;
L(i, 1, n) if(vis[i]) arrx[++atotx] = f[i].xl;
sort(arrx + 1, arrx + atotx + 1), atotx = unique(arrx + 1, arrx + atotx + 1) - arrx - 1;
L(i, 1, n) if(vis[i]) xl[i] = lower_bound(arrx + 1, arrx + atotx + 1, f[i].xl) - arrx;
L(i, 1, n) if(vis[i]) arry[++atoty] = f[i].yl;
sort(arry + 1, arry + atoty + 1), atoty = unique(arry + 1, arry + atoty + 1) - arry - 1;
L(i, 1, n) if(vis[i]) yl[i] = lower_bound(arry + 1, arry + atoty + 1, f[i].yl) - arry;
me(t, 0);
L(i, 1, n) if(vis[i]) id[xl[i]].emplace_back(i);
L(i, 0, n) st[i].clear();
int ns = 0;
me(a, 0);
for(auto u : vp) {
int A = u.first, B = u.second;
L(h, 1, f[A].xl)
L(j, 1, f[A].yl)
L(k, 1, f[B].xr)
L(l, 1, f[B].yr)
ns += !a[h][j][k][l], a[h][j][k][l] = 1;
}
ns = 0;
R(i, atotx, 1) {
for(const int &ic : id[i])
for(const int &u : gp[ic]) t[u] = max(t[u], yl[ic]);
int rns = 0, sum = 0;
L(j, 1, n) if(t[j]) st[t[j]].emplace_back(j);
me(haha, 0);
R(j, atoty, 1) {
if(sz(st[j])) {
for(const int &a : st[j]) {
L(t, 1, f[a].xr)
if(haha[t] < f[a].yr)
(sum += (ll) (arr[t] - arr[t - 1]) * (f[a].yr - haha[t]) % mod) %= mod,
haha[t] = f[a].yr;
}
st[j].clear();
}
(rns += (ll) sum * (arry[j] - arry[j - 1]) % mod) %= mod;
}
(ns += (ll) rns * (arrx[i] - arrx[i - 1]) % mod) %= mod;
}
L(i, 1, n) if(vis[i]) id[xl[i]].clear();
return ns;
}
vector < pair < int, int > > vq[N];
int solve(vector < tup > T) {
n = sz(T);
L(i, 1, sz(T)) f[i] = T[i - 1];
me(dis, 0x3f);
L(i, 1, n) dis[i][i] = 0;
L(i, 1, n) L(j, 1, n) if(f[i].xr <= f[j].xl && f[i].yr <= f[j].yl) dis[i][j] = 1;
L(k, 1, n) L(i, 1, n) L(j, 1, n) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
L(i, 0, n) vq[i].clear();
L(i, 1, n) L(j, 1, n) if(dis[i][j] < n) vq[dis[i][j]].emplace_back(make_pair(i, j));
atot = 0;
L(i, 1, n) f[i].xr = k - f[i].xr + 1, f[i].yr = k - f[i].yr + 1, arr[++atot] = f[i].xr;
sort(arr + 1, arr + atot + 1), atot = unique(arr + 1, arr + atot + 1) - arr - 1;
L(i, 1, n) f[i].xr = lower_bound(arr + 1, arr + atot + 1, f[i].xr) - arr;
int qwq = 0;
L(i, 0, n - 1) if(sz(vq[i])) qwq += work(vq[i]), qwq %= mod;
return qwq;
}
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n;
cin >> n >> k;
vector < tup > A, B;
while(n--) {
tup a;
cin >> a.xl >> a.yl >> a.xr >> a.yr;
if(a.yl > a.yr) {
a.yl = k - a.yl + 1;
a.yr = k - a.yr + 1;
A.push_back(a);
} else {
B.push_back(a);
}
}
int ns = (ll) (k + 1) * k % mod * (k - 1) % mod * iv3 % mod * k % mod * k % mod;
(ns += mod - solve(A)) %= mod;
(ns += mod - solve(B)) %= mod;
cout << ns << '\n';
return 0;
}
/*
2 5
3 3 4 5
3 3 5 4
*/
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 4684kb
input:
2 2 1 1 2 2 1 2 2 1
output:
6
result:
ok answer is '6'
Test #2:
score: 0
Accepted
time: 3ms
memory: 4636kb
input:
0 1000000000
output:
916520226
result:
ok answer is '916520226'
Test #3:
score: 0
Accepted
time: 3ms
memory: 4676kb
input:
5 5 1 1 3 3 3 3 5 1 3 3 4 5 3 3 5 4 1 5 3 3
output:
946
result:
ok answer is '946'
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 4712kb
input:
200 5 1 1 4 2 2 5 4 4 2 3 4 2 2 4 3 5 1 4 4 2 2 5 4 2 1 2 4 4 1 2 2 4 1 4 5 1 3 4 5 1 4 2 5 1 2 2 5 4 3 2 5 1 3 1 5 2 4 2 5 3 1 3 5 1 3 4 4 5 2 2 4 3 2 3 5 4 1 4 5 3 2 2 3 1 2 5 3 3 1 1 5 3 4 4 5 5 1 3 4 4 4 3 5 1 2 3 3 4 3 4 4 2 1 4 4 5 2 1 4 4 1 3 5 2 1 1 3 3 1 5 3 1 1 1 3 5 1 4 3 5 4 5 5 4 1 1 4 ...
output:
728
result:
wrong answer expected '708', found '728'