QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#51754#4887. Fast BridgeszhoukangyangRE 3ms4700kbC++115.3kb2022-10-03 20:31:422022-10-03 20:31:46

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-03 20:31:46]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:4700kb
  • [2022-10-03 20:31:42]
  • 提交

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; 
assert(pos == lw);
	
	(sum += (ll) arr[x] * y % mod) %= mod; 
	(sum += mod - (ll) arr[x] * vc[pos].second % mod) %= mod;
	(sum += mod - (ll) arr[vc[lw - 1].first] * 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4648kb

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: 4700kb

input:

0 1000000000

output:

916520226

result:

ok answer is '916520226'

Test #3:

score: -100
Dangerous Syscalls

input:

5 5
1 1 3 3
3 3 5 1
3 3 4 5
3 3 5 4
1 5 3 3

output:


result: