QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643115#8548. China Convex Polygon Contestorz_zRE 1ms5624kbC++143.6kb2024-10-15 18:59:222024-10-15 18:59:24

Judging History

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

  • [2024-10-15 18:59:24]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5624kb
  • [2024-10-15 18:59:22]
  • 提交

answer

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("Ofast,fast-math")
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {
	cerr << "[" << s << "] = [" << x << "]\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {
	for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;
	else if (s[i] == ')' || s[i] == '}') b--;
	else if (s[i] == ',' && b == 0) {
		cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";
		debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);
		break;
	}
}
#ifdef ONLINE_JUDGE
#define Debug(...)
#else
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
	int x = 0;
	bool t = 0;
	char c = getchar();
	while (c < '0' || c > '9') t |= c == '-', c = getchar();
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	return t ? -x : x;
}
inline void wi(int x) {
	if (x < 0) {
		putchar('-'), x = -x;
	}
	if (x > 9) wi(x / 10);
	putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
	wi(x), putchar(s);
}
bool Mbe;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3f;
const int _ = 2e5 + 5;

int n, m, a[_], b[_];

bool vis[_];

map<pii, int> mp;

int val[_];

void solve() {
	n = ri(), m = ri();
	F(i, 1, n) a[i] = ri();
	int n2 = n;
	F(i, 1, n2) b[i] = ri() + b[i - 1];
	if(a[n] < m) a[++n] = m;
	vector<pii> A;
	F(i, 1, n - 1) A.pb({a[i], a[i + 1]});
	F(i, 1, n2) {
		int p = lower_bound(a + 1, a + n + 1, b[i]) - a;
		if(p <= n) A.pb({b[i], a[p]}), mp[{b[i], a[p]}] = i;
	}
	F(i, 1, n) vis[i] = 0;
	sort(A.begin(), A.end(), [&](pii a, pii b) { return a.se - a.fi > b.se - b.fi; });
	int ans = 0;
	F(i, 1, m) val[i] = 0;
	for(pii v : A) {
		Debug(v.fi, v.se);
		if(val[v.se]) continue;
		if(mp.find(v) != mp.end()) {
			if(!vis[mp[v]]) {
				vis[mp[v]] = 1, ans += v.se - v.fi;//, Debug(mp[v]);
				F(j, v.fi + 1, v.se) val[j] = 1;
				continue;
			}
			Debug("jb");
//			continue;
		}
		dF(j, n2, 1) if(b[j] <= v.fi && !vis[j]) {
			vis[j] = 1;
			ans += v.se - v.fi;
			F(j, v.fi + 1, v.se) val[j] = 1;
			Debug(j);
			break;
		}
	}
	cout << ans << '\n';
}

bool Med;
signed main() {
	// Mry;
	int T = ri();
	while(T--) {
		solve();
	}
	// Try;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 10
1 5 9
1 2 3
3 10
1 5 9
1 1 4
3 10
1 5 9
1 5 10

output:

9
9
7

result:

ok 3 number(s): "9 9 7"

Test #2:

score: -100
Runtime Error

input:

10000
9 879847766
125098132 150509852 181700303 196375322 519766842 560891576 609151480 721527163 805167083
99031467 66330518 6283986 21388462 41109537 83628243 116141243 144052767 192448599
8 30
5 12 16 19 20 23 25 27
3 1 1 4 2 8 2 3
8 30
4 10 13 16 17 20 23 27
6 3 1 2 3 4 7 2
7 586479012
37693706 ...

output:


result: