QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101290#6134. Soldier Gameb2ogeymanTL 0ms3380kbC++143.5kb2023-04-29 07:17:552023-04-29 07:17:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-29 07:17:59]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3380kb
  • [2023-04-29 07:17:55]
  • 提交

answer

#include <bits/stdc++.h>
//#include <bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
//#define int long long int
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repb(i, a, b) for(int i = (a); i >= (b); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pb push_back

#define ln '\n'
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.ff<<","<<v.ss<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    for(auto &x : c) out<<x<<" ";
    out<<"}"; return out;
}

const int MOD = 1e9+7, LIM = 3e5+5;
const int inf = 2e9+1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector <vi> f(vector<vi> a, vector<vi> b) {
	vector<vi> v(2, vi(2, -inf));
	rep(i, 0, 2)
		rep(j, 0, 2)
			rep(k, 0, 2)
				v[i][j] = max(v[i][j], min(a[i][k], b[k][j]));
	return v;
}
vector<vi> unit = {{-inf, -inf}, {-inf, -inf}};


struct Tree {
	typedef vector<vi> T;
	vector<T> s; int n;
	Tree(int n = 0, T def = unit) : s(2*n, def), n(n) {}
	void modify1(int pos, int nval) {
		s[pos += n][0][0] = nval;
		for (; pos /= 2;)
			s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
	}
	void modify2(int pos, int nval) {
		s[pos += n][0][1] = nval;
		for (; pos /= 2;)
			s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
	}
	void update(int pos, T nval) {
		s[pos += n] = nval;
		for (; pos /= 2;)
			s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
	}
	T query(int b, int e) { // query [b, e)
		T ra = unit, rb = unit;
        bool rau = true, rbu = true;
		for (b += n, e += n; b < e; b /= 2, e /= 2) {
			if (b % 2) {
                if(rau) {
                    rau = false;
                    ra = s[b++];
                } else
                    ra = f(ra, s[b++]);
            }
			if (e % 2) {
                if(rbu) {
                    rbu = false;
                    rb = s[--e];
                } else
                    rb = f(s[--e], rb);
            }
		}
        if(rau)
            return rb;
        if(rbu)
            return ra;
		return f(ra, rb);
	}
};

int32_t main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
    #ifdef LOCAL
	freopen("stuff.in", "r", stdin);
	#endif

	int tests = 1;
	cin >> tests;

	while(tests--){
		int n;
		cin >> n;
		vi a(n);
		rep(i,0, n)
			cin >> a[i];
		Tree tr(n);
		rep(i,0, n)
			tr.update(i, {{a[i], (i < n-1 ? a[i] + a[i+1] : -inf)}, {inf, -inf}});
		int p = 0;

		vector<array<int, 3>> ind;
		rep(i, 0, n) {
			ind.push_back({a[i],i,0});
			if(i < n-1)
				ind.push_back({a[i] + a[i+1], i, 1});
		}
		sort(all(ind), [&](array<int, 3> a, array<int, 3> b){return a[0] > b[0];});

		vector<array<int, 3>> mxs;
		rep(i, 0, n) {
			mxs.push_back({a[i],i,0});
			if(i < n-1)
				mxs.push_back({a[i] + a[i+1], i, 1});
		}
		sort(all(mxs));
		int ans = inf;
        //cout << "Debug " << tr.query(0, n)[0][0] << ln;
		repb(i, sz(mxs)-1, 0) {
			while(p < sz(ind) && ind[p][0] > mxs[i][0]) {
				if(ind[p][2] == 0)
					tr.modify1(ind[p][1], -inf);
				else 
					tr.modify2(ind[p][1], -inf);
				p++;
			}
			int q = tr.query(0, n)[0][0];
			if(q > -inf/2)
				ans = min(ans, mxs[i][0] - q);
		}
		cout << ans << ln;
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5
-1 4 2 1 1
4
1 3 2 4
1
7

output:

1
2
0

result:

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

Test #2:

score: -100
Time Limit Exceeded

input:

10010
1
1000000000
1
-1000000000
2
1000000000 -1000000000
4
1000000000 1000000000 -1000000000 -1000000000
3
100 -100 100
16
-17 91 -19 66 100 -70 -71 76 -58 99 52 19 25 -67 -63 -32
7
-95 -26 63 -55 -19 77 -100
17
-100 72 -53 -32 8 -100 53 44 -100 -65 -81 -59 100 100 57 -47 1
11
99 10 -100 3 32 2 -26...

output:

0
2000000001
0
2000000001
100
135
103
181
189
84
63
164
176
0
147
135
152
36
200
131
134
0
136
0
72
171
146
0
183
77
176
89
200
135
38
109
119
126
158
189
70
0
38
999804364
188
161
0
116
116
200
0
101
200
39
0
183
139
0
183
107
139
0
178
85993
126
153
168
163
96
53
96
52
126
47
130
79
0
123
188
173
...

result: