QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#51668 | #4887. Fast Bridges | zhoukangyang# | WA | 17ms | 4740kb | C++11 | 5.3kb | 2022-10-03 13:03:43 | 2022-10-03 13:03:43 |
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];
//int a[N];
//unsigned long long A[12];
//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;
// }
//}
vector < pair < int, int > > vc;
int sum, arr[N];
void insert(int x, int y) {
int lw = lower_bound(vc.begin(), vc.end(), make_pair(x, y)) - vc.begin(), pos = lw;
if(y <= vc[pos].second) return ;
while(lw && vc[lw - 1].second <= y) --lw;
(sum += (ll) arr[x] * y % mod) %= mod;
(sum += mod - (ll) arr[x] * vc[pos].second % mod) %= mod;
(sum += mod - (ll) arr[lw - 1] * y % mod) %= mod;
L(i, lw, pos - 1) (sum += mod - (ll) arr[vc[i].first] * vc[i].second % mod) %= mod;
L(i, lw, pos) (sum += (ll) arr[vc[i - 1].first] * vc[i].second % mod) %= mod;
vc.erase(vc.begin() + lw, vc.begin() + pos);
vc.insert(vc.begin() + lw, {x, y});
}
int dis[N][N];
int arrx[N], arry[N], atotx, atoty;
bool vis[N];
int t[N];
vi gp[N], st[N];
int xl[N], yl[N];
vector < int > id[N];
int atot;
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;
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);
vc.clear();
vc.push_back({0, 1e9 + 7});
vc.push_back({1e9 + 7, 0});
R(j, atoty, 1) {
if(sz(st[j])) {
for(const int &a : st[j]) insert(f[a].xr, 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] = max(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] >= 0) 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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 4700kb
input:
2 2 1 1 2 2 1 2 2 1
output:
6
result:
ok answer is '6'
Test #2:
score: 0
Accepted
time: 0ms
memory: 4640kb
input:
0 1000000000
output:
916520226
result:
ok answer is '916520226'
Test #3:
score: 0
Accepted
time: 3ms
memory: 4644kb
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: 0
Accepted
time: 4ms
memory: 4732kb
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:
708
result:
ok answer is '708'
Test #5:
score: -100
Wrong Answer
time: 17ms
memory: 4740kb
input:
500 10 5 6 7 10 1 3 8 10 3 3 4 9 2 10 10 2 9 4 10 10 5 4 7 8 7 1 10 7 3 1 7 10 5 2 8 9 6 3 7 10 3 10 7 9 4 9 5 1 2 5 3 3 7 10 8 2 7 7 9 8 6 6 8 3 5 10 8 8 1 1 5 5 3 3 10 5 5 5 7 6 3 8 4 7 6 7 7 5 7 3 10 9 5 3 9 4 4 6 10 5 1 5 9 10 5 6 9 7 3 10 10 3 1 2 5 7 4 6 5 1 3 1 8 5 5 8 8 9 1 8 4 3 6 4 7 10 7 ...
output:
25292
result:
wrong answer expected '27373', found '25292'