QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249166#7569. LinesUSP_USP_USP#WA 1ms3540kbC++202.9kb2023-11-12 01:41:162023-11-12 01:41:16

Judging History

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

  • [2023-11-12 01:41:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3540kb
  • [2023-11-12 01:41:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()
#define int int64_t
#define pb push_back

void dbg_out() { cerr << endl; }
template <typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }

#define fi first
#define se second

using ll = long long;

using db = long double;

struct CHT {
	int it;
	vector<ll> a, b;
	CHT():it(0){}
	bool useless(){
		int sz = a.size();
		int r = sz-1, m = sz-2, l = sz-3;

		long double x1 = b[r]-b[m];
		x1 /= db(a[m]-a[r]);
		long double x2 = b[r]-b[l];
		x2 /= db(a[l]-a[r]);
		return x2 >= x1;
	}
	void add(ll A, ll B){
		a.push_back(A); b.push_back(B);
		while (!a.empty()){
			if ((a.size() < 3) || !useless()) break;
			a.erase(a.end() - 2);
			b.erase(b.end() - 2);
		}
	}
};

void solve() {
	int n;
	cin >> n;
	vector<int> a(n+1), b(n+1), c(n+1);
	vector<int> ok(3*n+1);
	for(int i = 0; i <= n; i++){
		cin >> a[i];
	}
	for(int i = 0; i <= n; i++){
		cin >> b[i];
	}
	for(int i = 0 ; i <=  n; i++){
		cin >> c[i];
	}

	auto calcmaq = [&](vector<int> v){
		vector<pair<int,int>> mq;
		for(int i = 0; i <= n; i++){
			while(!mq.empty() && mq.back().fi <= v[i]) mq.pop_back();
			mq.push_back({v[i],i});
		}
		return mq;
	};

	vector<array<int,2>> sad;

	for(int q = 0; q < 2; q++){
		auto ma = calcmaq(a);
		auto mb = calcmaq(b);
		auto mc = calcmaq(c);

		int sa = ma.size();
		int sb = mb.size();
		int sc = mc.size();
		int i = 0;
		int j = 0;
		int k = 0;
		while(i < sa-1 || j < sb-1 || k < sc-1){
			auto [va,ida] = ma[i];
			auto [vb,idb] = mb[j];
			auto [vc,idc] = mc[k];
			if(q){
				ida = n-ida;
				idb = n-idb;
				idc = n-idc;
			}
			int eu = ida+idb+idc;
			sad.pb({eu,va+vb+vc});
			vector<array<int,3>> op;
			if(i < sa-1){
				op.pb({ ma[i+1].fi-ma[i].fi ,ma[i+1].se-ma[i].se, 0});
			}
			if(j < sb-1){
				op.pb({ mb[j+1].fi-mb[j].fi, mb[j+1].se-mb[j].se,1});
			}
			if(k < sc-1){
				op.pb({ mc[k+1].fi-mc[k].fi, mc[k+1].se-mc[k].se,2});
			}
			sort(op.rbegin(),op.rend());
			if(op[0][2] == 0){
				i++;
			}else if(op[0][2] == 1){
				j++;
			}else{
				k++;
			}
		}
		reverse(a.begin(),a.end());
		reverse(b.begin(),b.end());
		reverse(c.begin(),c.end());
	}
	sad.pb({0,a[0]+b[0]+c[0]});
	sad.pb({3*n,a[n]+b[n]+c[n]});
	sort(sad.begin(),sad.end());
	CHT cht;
	for(auto [A,B] : sad){
		cht.add(A,B);
	}
	for(auto fe : cht.a){
		ok[fe] = 1;
	}
	vector<int> ans;
	for(int i = 0; i <= 3*n; i++){
		if(!ok[i]) ans.pb(i);
	}
	cout << ans.size() << '\n';
	for(auto x : ans ) cout << x << ' ';
	cout << '\n';

}

signed main(){
	ios::sync_with_stdio(false); cin.tie(0);
	solve();
}

/*
Makefile:
CXXFLAGS=-Wall -Wextra -Wshadow -g -pedantic -fsanitize=address,undefined -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUGPEDANTIC -std=gnu++17
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 1 8 7
9 1 3 1
5 1 1 6

output:

5
1 3 4 7 8 

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3488kb

input:

1
1 2
1 2
1 2

output:

2
1 2 

result:

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

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3528kb

input:

252
336470888 634074578 642802746 740396295 773386884 579721198 396628655 503722503 971207868 202647942 2087506 268792718 46761498 443917727 16843338 125908043 691952768 717268783 787375312 150414369 693319712 519096230 45277106 856168102 762263554 674936674 407246545 274667941 279198849 527268921 1...

output:

737
4 6 7 8 9 10 11 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 1...

result:

wrong answer 1st numbers differ - expected: '733', found: '737'