QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90926#6134. Soldier GamednialhAC ✓503ms11632kbC++144.0kb2023-03-26 07:49:192023-03-26 07:49:22

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-26 07:49:22]
  • 评测
  • 测评结果:AC
  • 用时:503ms
  • 内存:11632kb
  • [2023-03-26 07:49:19]
  • 提交

answer

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

#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define sq(a) ((a)*(a))

#define MOO(i,a,b) for (int i=a; i<b; i++)
#define M00(i,a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define per(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a,b) for (int i=a; i<b; i++)

#define FOR(i,a,b) for (int i=a; i<b; i++)
#define F0R(i,a) for (int i=0; i<a; i++)
#define ROF(i,a,b) for (int i = (b)-1; i >= a; i--)
#define R0F(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << endl, 0;
#define dbg(x) cout << ">>> " << #x << " = " << x << endl;
#define _<< " _ " <<

#define int long long

template<class T> bool ckmin(T&a, T&b) { bool B = a > b; a = min(a,b); return B; }
template<class T> bool ckmax(T&a, T&b) { bool B = a < b; a = max(a,b); return B; }

typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ld,ld> pld;
typedef complex<ld> cd;

typedef vector<int> vi;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;

const ld PI = acos(-1.0);
const ld EPS = 1e-7;
const int MOD = 1e9+7;

int POW(int b, int e) {
	int r = 1;
	while(e) {
		if(e % 2 == 1) {
			r *= b;
			r %= MOD;
		}
		e /= 2;
		b *= b;
		b %= MOD;
	}
	return r;
}
int gcd(int a, int b) {
	if(b > a) return gcd(b,a);
	if(b == 0) return a;
	return gcd(b, a % b);
}
int INV(int a) {
	return POW(a, MOD-2);
}
//Constants and Variables here
struct Tree {
	typedef int T;
	T unit = 9;
	
	T f(T &a, T &b) { 
	    //return a;
	    
		int res = 0;
		
		M00(i, 2) M00(j, 2) { 
			M00(k, 2) {
				res |= ((b >> (2 * i + k)) & (a >> (2 * k + j)) & 1) << (2 * i + j);
			}
		}
		
		//if (a == 4 && b == 4)
		//    dbg(a _ b _ res);
		
		return res;
	}
	vector<T> s; int n;
	Tree(int n, T def) : s(2*n, def), n(n) {
	    for(int i = n - 1; i >= 0; i --){
	        s[i] = f(s[2 * i], s[2 * i + 1]);
	    }
	}
	void update(int pos, int i, int j, int val) {
	    pos += n;
	    
	    int mask = 1 << (2 * i + j);
	    
	    if (val){
	        s[pos] |= mask;
	    } else {
	        //dbg(s[pos] _ pos _ i _ j);
	        s[pos] &= ~mask;
	        //dbg(s[pos]);
	    }
	    
	    
	    
		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;
		for (b += n, e += n; b < e; b /= 2, e /= 2) {
			if (b % 2) ra = f(ra, s[b++]);
			if (e % 2) rb = f(s[--e], rb);
		}
		return f(ra, rb);
	}

	T access(int u) {
		return s[u + n];
	}
};
Tree T(0, 0);
vector<pair<int, pi>> dom;

void add(int x) {
	pi p = dom[x].s;
	if(p.f == p.s) {
		T.update(p.f, 0, 0, 1);
	} else {
		T.update(p.s, 0, 1, 1);
	}
}

void rem(int x) {
	pi p = dom[x].s;
	if(p.f == p.s) {
		T.update(p.f, 0, 0, 0);
	} else {
		T.update(p.s, 0, 1, 0);
	}
}

void solve() {
	int n; cin >> n;
	vi arr(n);
	M00(i, n){
	    //arr[i] = rand();
	    cin >> arr[i];
	}

	dom.clear();	
	M00(i, n) dom.pb(mp(arr[i], mp(i,i)));
	M00(i, n-1) dom.pb(mp(arr[i]+arr[i+1], mp(i,i+1)));
	
	sort(all(dom));
	
	M00(i, 2 * n - 1){
	    //cout << dom[i].s.f _ dom[i].s.s << endl;
	}

	int base = 4;
	T = Tree(n, base);

	int ans = 1e10;
	int r = -1, l = 0; // closed
	while(l < dom.size()) {
		while( (!(T.query(0, n) & 1)) && r < (int) dom.size()) {
			r += 1;
			if (r == dom.size()) break;
			add(r);
		}

		if (r == dom.size()) break;


		//dbg(T.query(0, 1) _ l _ r);
		//dbg(T.query(0, 2) _ l _ r);
		//dbg(T.query(0, 3) _ l _ r);
		//dbg(T.query(0, 4) _ l _ r);

		ans = min(ans, dom[r].f - dom[l].f);
		
		if(l == dom.size() - 1) break;
		
        rem(l);
		l++;
	}
	cout << ans << endl;
}

int32_t main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int t; cin >> t;
	while(t--) solve();
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 478ms
memory: 11632kb

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
0
0
2000000000
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
33
0
83
1...

result:

ok 10010 numbers

Test #3:

score: 0
Accepted
time: 63ms
memory: 10264kb

input:

1
100000
-999999999 999999999 999999998 -999999998 -999999997 999999997 999999996 -999999996 999999995 -999999995 -999999994 999999994 -999999993 999999993 -999999992 999999992 -999999991 999999991 999999990 -999999990 999999989 -999999989 999999988 -999999988 999999987 -999999987 999999986 -9999999...

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 503ms
memory: 11608kb

input:

10011
1
1000000000
1
-1000000000
2
1000000000 -1000000000
4
1000000000 1000000000 -1000000000 -1000000000
12
48 54 98 -20 -45 56 -100 78 47 23 -100 -21
19
66 41 52 17 -9 -90 -36 90 -26 66 -86 -83 -39 -83 35 78 100 -68 -62
2
-100 -23
17
89 -26 -100 -38 -14 87 32 -100 16 -31 -35 100 73 -61 -100 43 -48...

output:

0
0
0
2000000000
155
168
0
173
137
167
127
25
91
109
176
0
0
173
115
56
66
67
0
1999775909
121
166
128
77
60
146
152
78
172
110
60
200
89
160
200
130
175
79
97
1999891177
122
154
136
164
123
0
175
77
167
76
40
82
79
159
99
141
165
147
158
1999730298
0
179
31
181
192
193
47
91
164
63
65
138
100
168
1...

result:

ok 10011 numbers

Test #5:

score: 0
Accepted
time: 80ms
memory: 10188kb

input:

1
100000
50000 50000 50001 50001 50002 50002 50003 50003 50004 50004 50005 50005 50006 50006 50007 50007 50008 50008 50009 50009 50010 50010 50011 50011 50012 50012 50013 50013 50014 50014 50015 50015 50016 50016 50017 50017 50018 50018 50019 50019 50020 50020 50021 50021 50022 50022 50023 50023 500...

output:

49999

result:

ok 1 number(s): "49999"