QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#495768#9141. Array Spreaducup-team2172#RE 11ms7908kbC++233.4kb2024-07-27 23:31:532024-07-27 23:31:54

Judging History

This is the latest submission verdict.

  • [2024-09-18 18:58:44]
  • hack成功,自动添加数据
  • (/hack/840)
  • [2024-09-18 18:53:02]
  • hack成功,自动添加数据
  • (/hack/839)
  • [2024-07-29 03:53:23]
  • hack成功,自动添加数据
  • (/hack/753)
  • [2024-07-29 03:51:16]
  • hack成功,自动添加数据
  • (/hack/752)
  • [2024-07-29 03:50:24]
  • hack成功,自动添加数据
  • (/hack/751)
  • [2024-07-29 03:48:52]
  • hack成功,自动添加数据
  • (/hack/750)
  • [2024-07-27 23:31:54]
  • Judged
  • Verdict: RE
  • Time: 11ms
  • Memory: 7908kb
  • [2024-07-27 23:31:53]
  • Submitted

answer

#include <bits/stdc++.h>
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
	int ch = 0, f = 0; x = 0;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
	for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
	if(f) x = -x;
}
#define int ll
#define fi first
#define se second
const ll inf = 1e18;
const int mod = 998244353, N = 100005;
vector<pair<int, int> > g[N];

vector<pair<int, long double> > e[N];
pair<int, int> seg[N];
long double dis[N];
pair<int, int> dis2[N];
int buf[N], _n, m;

pair<int, int> operator + (pair<int, int> A, pair<int, int> B){
	return make_pair(A.fi + B.fi, A.se + B.se);
}

pair<int, int> operator - (pair<int, int> A, pair<int, int> B){
	return make_pair(A.fi - B.fi, A.se - B.se);
}

inline int check(long double mid, int n){
	for(int i = 1; i <= n + 1; i++) g[i].clear(), e[i].clear();
	
	for(int i = 1; i <= m; i++){
		e[seg[i].fi].push_back(make_pair(seg[i].se + 1, mid));
		g[seg[i].se + 1].push_back(make_pair(seg[i].fi, - 1));
	}

	for(int i = 1; i <= n; i++) 
		g[i+1].push_back(make_pair(i, 0));

	for(int i = 2; i <= n + 1; i++) dis[i] = inf, dis2[i] = make_pair(0, 0);
	dis[1] = 0;
	int flag = 0;
	for(int i = 1; i <= n + 1; i++){
		flag = 0;
		for(int u = 1; u <= n + 1; u++){
			for(auto [v, w] : g[u])
				if(dis[u] + w < dis[v]){
					dis[v] = dis[u] + w, flag = 1;
					dis2[v] = dis2[u] + make_pair(w, 0);
				}
			for(auto [v, w] : e[u])
				if(dis[u] + w < dis[v]){
					dis[v] = dis[u] + w, flag = 1;
					dis2[v] = dis2[u] + make_pair(0, 1);
				}
		}


		if(!flag) return 1;
	}

	if(flag) return 0;
	
	return 1;
}

inline int Pow(int a, int b){
	int ans = 1;
	for(; b; b >>= 1, a = 1ll * a * a % mod)
		if(b & 1) ans = 1ll * ans * a % mod;
	return ans;
}

inline void solve(){
	read(_n), read(m); int t = 0;
	
	int mx = 0, mn = _n;
	for(int i = 1; i <= m; i++){
		read(seg[i].fi), buf[++t] = seg[i].fi;
		read(seg[i].se), buf[++t] = seg[i].se;
		mx = max(mx, seg[i].se - seg[i].fi + 1);
		mn = min(mx, seg[i].se - seg[i].fi + 1);
	}

	sort(buf + 1, buf + t + 1);
	t = unique(buf + 1, buf + t + 1) - buf - 1;
	int ct = t;
	for(int i = 1; i < t; i++) 
		if(buf[i] + 1 < buf[i+1]) buf[++ct] = buf[i] + 1;
	
	t = ct;
	sort(buf + 1, buf + t + 1);
	t = unique(buf + 1, buf + t + 1) - buf - 1;


	for(int i = 1; i <= m; i++){
		seg[i].fi = lower_bound(buf + 1, buf + t + 1, seg[i].fi) - buf;
		seg[i].se = lower_bound(buf + 1, buf + t + 1, seg[i].se) - buf;
	}

	long double l = 1, r = 1.0 * mx / mn + 1, res = 1;
	for(int tim = 60; ~tim; tim--){
		long double mid = (l + r) * 0.5;
		if(check(mid, t)) res = r = mid;
		else l = mid;
	}

	check(res, t);
	//cout << res << endl;
	
	//for(int i = 1; i <= t + 1; i++) cout << dis2[i].fi << " " << dis2[i].se << " " << dis[i] << endl;

	int nx = 1, ny = 1;
	for(int i = 1; i <= m; i++){
		auto [x, y] = dis2[seg[i].se+1] - dis2[seg[i].fi];
		if(y && 1ll * (1 - x) * ny > 1ll * y * nx) nx = 1 - x, ny = y;
	}
	for(int i = 1; i <= t; i++){
		auto [x, y] = dis2[i+1] - dis2[i];
		if(y && 1ll * (-x) * ny > 1ll * y * nx) nx = -x, ny = y;
	}
	assert((1.0 * nx / ny - res) < 1e-6);
	printf("%lld\n", 1ll * nx * Pow(ny, mod - 2) % mod);

}
signed main(){
	int T; read(T);
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7860kb

input:

3
3 3
1 3
2 3
1 2
12 6
2 3
5 7
1 9
4 8
1 2
7 11
4 5
3 4
2 3
1 2
4 4
1 1

output:

1
2
499122178

result:

ok 3 number(s): "1 2 499122178"

Test #2:

score: 0
Accepted
time: 11ms
memory: 7908kb

input:

2000
1000000000 1
259923446 367011266
1000000000 1
882434225 971573327
1000000000 1
41585677 470369580
1000000000 1
371902212 947250194
1000000000 1
787209148 924205796
1000000000 1
259074809 960876164
1000000000 1
148079314 188254573
1000000000 1
940091047 948318624
1000000000 1
40636497 743979446
...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 2000 numbers

Test #3:

score: -100
Runtime Error

input:

1000
1000000000 5
575330909 661595447
708422488 913945134
658050911 930246647
786571892 904549453
851755566 969150871
1000000000 2
198072104 844159589
8876188 644559580
1000000000 2
740802634 976972118
783909534 898449184
1000000000 2
871819537 941611957
465883854 640988372
1000000000 1
99458969 462...

output:


result: